Ani*_*aul 3 .net c# validation dependencies properties
假设我有一个类有两个string类型的属性
并且有以下限制
定义其值彼此依赖的属性的最佳方法是什么,以及在一个属性中进行的更改应该触发另一个属性的setter属性?
您需要在属性设置器中添加验证.
string prop1;
string prop2;
string Prop1
{
get { return prop1;}
set
{
if (!( Prop2 == "Test2" && value == "Test1"))
{
Prop1 = value;
}
... Add other condition here
}
}
string Prop2
{
get { return prop1;}
set
{
// set Prop2 based on Prop1
}
}
Run Code Online (Sandbox Code Playgroud)