[英]How to use a setter to set a value of complex property
I have two base classes. 我有两个基类。
public class IValue
{
public dynamic Value { get; set; }
public dynamic Type { get; set; }
}
public class IParameter
{
public string Name { get; set; }
public bool Required { get; set; }
public IValue ValueObject
{
get { return _value.Value; }
set { _value.Value = value; }
}
private IValue _value { get; set; }
}
public class MyParm : IParameter
{
}
Now in order to set the ValuesObject of the MyParam Class, I should be able to use this line. 现在,为了设置MyParam类的ValuesObject,我应该能够使用此行。
MyParam.ValueObject = "";
but instead I have to use this line 但是我必须使用这条线
MyParam.ValueObject.Value = "";
Nobody ever needs to get the Type, the value is all that matters, the Type is there for the system. 没人需要获取Type,值才是最重要的,Type是系统可用的。 Is there a way to accomplish setting the ValueObject.Value and getting it, without explicitly saying .Value?
有没有一种方法可以完成设置ValueObject.Value并获取它,而无需显式说明.Value?
try this 尝试这个
public class IParameter
{
public IParameter()
{
_value = new IValue();
}
public string Name { get; set; }
public bool Required { get; set; }
public dynamic Value
{
get { return _value.Value; }
set
{
_value.Value = value;
}
}
private IValue _value { get; set; }
}
Now in order to set the Values of the MyParam Class, you will be able to use this line. 现在,为了设置MyParam类的值,您将能够使用此行。
MyParam.Value = "";
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.