Trying to make Feature
generic and then suddenly compiler said
Operator '?' cannot be applied to operand of type 'T'
Here is the code
public abstract class Feature<T>
{
public T Value
{
get { return GetValue?.Invoke(); } // here is error
set { SetValue?.Invoke(value); }
}
public Func<T> GetValue { get; set; }
public Action<T> SetValue { get; set; }
}
It is possible to use this code instead
get
{
if (GetValue != null)
return GetValue();
return default(T);
}
But I am wondering how to fix that nice C# 6.0 one-liner.