Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ionic-framework/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# fxcop自定义规则-检查源代码以查找新关键字_C#_Fxcop_Fxcop Customrules - Fatal编程技术网

C# fxcop自定义规则-检查源代码以查找新关键字

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); }

我希望避免将某些类实例化为new,并强制使用factory类

但我不明白怎么做

有人能给我看一点样品吗

提前感谢您的帮助,
致以最诚挚的问候

这里有一些东西可以让你开始。您需要添加自己的逻辑,以确定是否允许通过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来查找工厂的接口