我在构造函数中调用一个方法,如below.Is,这是根据某些validations.Please建议设置属性的正确方法。
public class Asset
{
public Asset(string id)
{
SetStorageId(id);
}
public string AssetId { get; set; }
public string UtilId { get; set; }
public string MappingId { get; set; }
public bool IsActive { get; set; }
private void SetStorageId(string id)
{
if (Regex.Match(id, "^[A-Z][a-zA-Z]*$").Success)
{
AssetId = id;
}
else
{
UtilId = id;
}
}
}发布于 2017-12-20 06:37:31
这没什么错。它可能会变得有点混乱。也许您可以通过将SetStorageId的bod移动到构造函数来使其更加清晰。相对于项目中的其他代码,也许没有必要将子类复杂化。
https://stackoverflow.com/questions/47899022
复制相似问题