重写的方法在构造函数 - 帮助修复
-
18-09-2019 - |
题
林试图使用的FxCop上的C#项目作为一种为C#编码标准基础的。
使用IM是称为S#ARP架构和项目是免费提供在这里:小号# ARP拱
现在,如果我跑的FxCop(大部分东西已经被固定)我需要修复的CA2214 FxCop的错误在contructors重写的方法。
目前一块违反代码看起来是这样的:
public class Region : Entity, IHasAssignedId<int>
{
public Region(string description)
{
Check.Require(!string.IsNullOrEmpty(description));
this.Description = description;
}
protected Region()
{
}
[DomainSignature]
> public virtual string Description { get; protected set; }
public virtual void SetAssignedIdTo(int assignedId)
{
Id = assignedId;
}
}
它的大部分被称为在这种方式中的其他光盘的文件:
public static RegionDto Create(Region region)
{
if (region == null)
{
return null;
}
return new RegionDto()
{
Id = region.Id,
> Description = region.Description
};
}
我试图改变方法的类型(私人/保护等),但往往存在冲突的通过的FxCop和需求单元测试,FxCop的说它不象与虚拟的方法,但该单元称该方法应该是公开contructors /受保护的虚拟或受保护的内部虚拟,抓22律位?
因此,任何帮助解决这一问题的FxCop规则,将不胜感激,谢谢。
(上标有线>,虚拟获取设置方法,当改变了其他>是它抱怨发生该错误)
解决方案
这是容易的: “不做该”。代替:
private string _description;
public Region(string description)
{
Check.Require(!string.IsNullOrEmpty(description));
_description = description;
}
protected Region()
{
}
[DomainSignature]
public virtual string Description {
get {return _description;}
set {_description = value;}
}
不隶属于 StackOverflow