C# compiler:
error CS0738: Field<T>' does not implement interface memberField.Value.get' and the best implementing candidate Field<T>.Value.get' return typeT' does not match interface member return type `object'
public interface Field
{
object Value {get;}
}
public class MyField<T> : Field
{
T _value;
public T Value
{
get
{
return _value;
}
}
}
Why ? List < T > extends List in microsoft classes, but i as a user (copying same design pattern) am not allowed to do that? why?
Trying where T: object also gives a compiler error...
How do i fix this?
the other 1.000.000 threads on the same subject, Say :
blablabla, 'return type covariance', blablabla, 'you cant'.
They do not propose a solution or a workaround on how to compile this beast.
Requirements:
1) Field is an interface that cannot take generics. Evil framework called "unity" forbids generics.
2) Field < T > which "implements Field" has generic T.
You can implement interface explicitly. https://msdn.microsoft.com/en-us/library/ms173157.aspx
The same pattern is used on non generic version of
IEnumerableand genericIEnumerable<T>You can do the same and have generic interface too.
Now if you have
Field<T>on your hand you can useThappily. if you haveFieldyou get object form of valueT