我需要在C#setter中进行一次小检查 - 检查属性是否为空字符串.现在我最终得到了这样的结构:
private string property;
public string Property
{
get
{
return property;
}
set
{
if (value.IsNotEmpty())
{
property = value;
}
}
}
Run Code Online (Sandbox Code Playgroud)
代替
public string Property { get; set; }
Run Code Online (Sandbox Code Playgroud)
6行代替1.有没有办法插入逻辑,但保持它浓缩和优雅?