I have the following method, which returns a generic object of type INamedProperty<TReturn> based on the return type of a defined expression. I need to store a reference to the object that is returned by this method for future processing. What type should I store it as? Would Object be OK? How would I cast it back to the appropriate INamedProperty<TReturn> later on? Do I also need to store the type of TReturn?
public class PropertyBuilder<T> : IPropertyBuilder<T> where T : class {
public INamedProperty<TReturn> Named<TReturn>(Expression<Func<T, TReturn>> property) {
o = new NamedProperty<TReturn>();
// how do I store o as an instance of the encapsulating class?
}
}
Thanks in advance!
I would try to implement a generic, uhh, non-generic
INamedPropertythat could implement the operations you need:Then implement them in the generic NamedProperty: