C# fxcop自定义规则-检查源代码以查找新关键字
我希望避免将某些类实例化为new,并强制使用factory类 但我不明白怎么做 有人能给我看一点样品吗 提前感谢您的帮助,C# fxcop自定义规则-检查源代码以查找新关键字,c#,fxcop,fxcop-customrules,C#,Fxcop,Fxcop Customrules,我希望避免将某些类实例化为new,并强制使用factory类 但我不明白怎么做 有人能给我看一点样品吗 提前感谢您的帮助, 致以最诚挚的问候这里有一些东西可以让你开始。您需要添加自己的逻辑,以确定是否允许通过newing实例化任何给定类型的实例 public override ProblemCollection Check(Member member) { if (member is Method) { this.Visit(member); }
致以最诚挚的问候这里有一些东西可以让你开始。您需要添加自己的逻辑,以确定是否允许通过newing实例化任何给定类型的实例
public override ProblemCollection Check(Member member)
{
if (member is Method)
{
this.Visit(member);
}
return this.Problems;
}
public override void VisitConstruct(Construct construct)
{
base.VisitConstruct(construct);
if (!this.AllowTypeToBeNewed(construct.Type))
{
this.Problems.Add(new Problem(this.GetResolution(), construct));
}
}
private bool AllowTypeToBeNewed(TypeNode type)
{
throw new NotImplementedException();
}
这家伙解释得很好
正在寻找如何创建自定义FxCop规则的示例或如何检查类实例化的示例?@TrueWill>非常乐意,但我该怎么做呢@dtb>我知道如何创建简单的规则,但我正在寻找分析如何为特定类型执行实例化的方法感谢您的帮助。我可以使用Type.Interfaces来查找工厂的接口