We have following classes
public class MyPropertyBase
{
public int StartOffset { get; set; }
public int EndOffset { get; set; }
}
public class MyProperty<T> : MyPropertyBase
{
public MyProperty(T propertyValue)
{
PropertyValue = propertyValue;
}
public T PropertyValue { get; set; }
}
class BE
{
public MyProperty<string> FUND_CITY { get; set; }
public MyProperty<int> SomeOtherProperty { get; set; }
public List<MyPropertyBase> MyDataPoints { get; set; }
}
When I create instance of BE as objBE and assign objBE.FUND_CITY="Some Value" it gives the error:
“Can’t convert “string” to MyProperty.
That’s correct.
FUND_CITYis not astring, but is aMyProperty<string>type. You’ll need to do:Or, if you have a parameterless constructor, you can do: