One of the least discussed topics about compiler and Generic Methods is its ability to infer the Type Arguments. For example, consider the following code. A typical invocation of the code might look like following. However, in some scenarios as above, the compiler is smart enough to allow you to skip the type argument from … Continue reading Type Argument Inference during Type Initialization
Tag: Generics
Revisting Anonymous Type
While classes and structs are extremely powerful, there are times when you want to escape the cermonies they require even for simplest of design. This is where anonymous types comes handy and has been so frequent used by the developers. So what are Anonymous types really ? Let's consider an example first. Anonymous Types are … Continue reading Revisting Anonymous Type
Evil Code #007: Overloads
Time to do a bit of Evil Code again. Let's look into following set of classes first. The client code looks like following. What could be output of the above ? There might be tendency that the one might be inclined to think about an output that resembles following. But interestingly that is not quite … Continue reading Evil Code #007: Overloads
Design Pattern : Memento Pattern
Memento Design Pattern allows to capture internal state of an object in an external object and restore it to the desired checkpoint when required, all the while being in compliance with encapsulation. The Memento Design Pattern comprises of 3 actor classes. Originator : The class which needs to have the ability to store its internal … Continue reading Design Pattern : Memento Pattern
Pass Property as Expression
I recently needed to pass a property of a class as an expression to a method and read value from it. I found the code that I finally ended up interesting and thought it might be useful to share it here. It might look I could have passed the value directly instead of as an … Continue reading Pass Property as Expression
Design Patterns : Adapter Pattern
There is already a large amount of literature on the Internet which discusses Adapter Pattern. However, the purpose of article is to showcase the implementations of the Adapter Pattern, rather than discussing the application of the pattern. In this post, adapter class is implemented using 1. Inheritance 2. Dependency Injection 3. Generics Consider your old … Continue reading Design Patterns : Adapter Pattern