Another option (an alternative to Jon's answer) is to apply the adapter pattern, which can be useful when:
- you are unable to modify the type, and can thus not define a base-type for it.
- or, there is a need to expose 'type-specific bits' (as Jon put it).
When you want to expose type-specific bits, you effectively have to create a non-generic wrapper. A short example:
class NonGenericWrapper : IAdaptor
{
private readonly Adaptee _adaptee;
public NonGenericWrapper(Adaptee adaptee)
{
_adaptee = adaptee;
}
public object Value
{
get { return _adaptee.Value; }
set { _adaptee.Value = (T) value; }
}
}
Implementing this non-generic behavior in a base-type would effectively break the Liskov substitution principle, which is why I prefer the wrapper approach as I also argue in my blog post.