• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# DiagnosticResult类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中DiagnosticResult的典型用法代码示例。如果您正苦于以下问题:C# DiagnosticResult类的具体用法?C# DiagnosticResult怎么用?C# DiagnosticResult使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



DiagnosticResult类属于命名空间,在下文中一共展示了DiagnosticResult类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: TestUnspecifiedSetPropertyHasCorrectComment

        public void TestUnspecifiedSetPropertyHasCorrectComment()
        {
            var test = @"
namespace ConsoleApplication1
{
    class TypeName
    {
        public string VogonConstructorFleet { get; }
    }
}";
            var expected = new DiagnosticResult
            {
                Id = "SA1623D",
                Message = $"property documentation: no documentation.",
                Severity = DiagnosticSeverity.Warning,
                Locations =
                    new[] { new DiagnosticResultLocation("Test0.cs", 6, 23) }
            };

            new DocumentationPropertyCodeFixVerifier().VerifyCSharpDiagnostic(test, expected);

            var fixtest = @"
namespace ConsoleApplication1
{
    class TypeName
    {
        /// <summary>
        /// Gets the vogon constructor fleet.
        /// </summary>
        public string VogonConstructorFleet { get; }
    }
}";
            new DocumentationPropertyCodeFixVerifier().VerifyCSharpFix(test, fixtest);
        }
开发者ID:jimmymain,项目名称:Documentation.Analyzers,代码行数:34,代码来源:PrivateSetDocumentationTests.cs


示例2: NestedExpressionContains2Dots_DiagnosticIsReported

        public void NestedExpressionContains2Dots_DiagnosticIsReported()
        {
            const string code = @"
               class Board {
                public String boardRepresentation() {
                    StringBuilder buf = new StringBuilder();

                    for (Location loc : squares()) {
                        buf.append(loc.current.substring(0, 1));
                    }

                    return buf.toString();
                }
             }";

            var expected = new DiagnosticResult
            {
                Id = "DaVinciOC5",
                Message = "\'loc.current.substring(0, 1)\' contains more than 1 dot per line.",
                Severity = DiagnosticSeverity.Info,
                Locations = new[] { new DiagnosticResultLocation("Test0.cs", 7, 36) }
            };

            VerifyCSharpDiagnostic(code, expected);
        }
开发者ID:johannes-schmitt,项目名称:DaVinci,代码行数:25,代码来源:Oc5UseOneDotPerLineTest.cs


示例3: MethodTakesMultiplePrimitiveAsParameter_MultipleDiagnosticReported

        public void MethodTakesMultiplePrimitiveAsParameter_MultipleDiagnosticReported()
        {
            const string Code = @"
                class SomeClass
                {
                    public void DoSomething(int parameter1, uint parameter2)
                    {
                    }
                }";

            var expected1 = new DiagnosticResult
            {
                Id = "DaVinciOC3",
                Message = "'parameter1' should be wrapped as it's a primitive.",
                Severity = DiagnosticSeverity.Info,
                Locations = new[] { new DiagnosticResultLocation("Test0.cs", 4, 49) }
            };

            var expected2 = new DiagnosticResult
            {
                Id = "DaVinciOC3",
                Message = "'parameter2' should be wrapped as it's a primitive.",
                Severity = DiagnosticSeverity.Info,
                Locations = new[] { new DiagnosticResultLocation("Test0.cs", 4, 66) }
            };

            VerifyCSharpDiagnostic(Code, expected1, expected2);
        }
开发者ID:johannes-schmitt,项目名称:DaVinci,代码行数:28,代码来源:Oc3WrapAllPrimitivesAndStringsTest.cs


示例4: DiagnosticForMethod

        public void DiagnosticForMethod()
        {
            var source = @"
using System.Threading;
class T
{
    void M(CancellationToken t, int i)
    {
    }
}";
            var expected = new DiagnosticResult
            {
                Id = RoslynDiagnosticIds.CancellationTokenMustBeLastRuleId,
                Message = string.Format(RoslynDiagnosticsResources.CancellationTokenMustBeLastMessage, "T.M(System.Threading.CancellationToken, int)"),
                Severity = DiagnosticSeverity.Warning,
                Locations = new[]
                {
                    new DiagnosticResultLocation("Test0.cs", 5, 10)
                }
            };

            VerifyCSharp(source, expected);

            var fixedSource = @"
using System.Threading;
class T
{
    void M(int i, CancellationToken t)
    {
    }
}";
            VerifyCSharpFix(source, fixedSource);
        }
开发者ID:GloryChou,项目名称:roslyn,代码行数:33,代码来源:CancellationTokenMustBeLastTests.cs


示例5: MethodContainsControlStructureInElseStatement_DiagnosticIsReported

        public void MethodContainsControlStructureInElseStatement_DiagnosticIsReported()
        {
            const string Code = @"
            class SomeClass
            {
                public void SomeMethod()
                {
                    if (new Random().Next(1) == 1)
                    {
                        System.Console.WriteLine(string.Empty);
                    }
                    else
                    {
                        for (int i = 0; i < 10; i++)
                        {
                            System.Console.WriteLine();
                        }
                    }
                }
            }";

            var expected = new DiagnosticResult
            {
                Id = "DaVinciOC1",
                Message = "\'SomeMethod\' contains more than 1 level of indentation.",
                Severity = DiagnosticSeverity.Info,
                Locations = new[] { new DiagnosticResultLocation("Test0.cs", 4, 29) }
            };

            VerifyCSharpDiagnostic(Code, expected);
        }
开发者ID:johannes-schmitt,项目名称:DaVinci,代码行数:31,代码来源:Oc1UseOneLevelOfIndentationPerMethodTest.cs


示例6: TestThatFirstPropertyHasCorrectSpacingBefore

        public void TestThatFirstPropertyHasCorrectSpacingBefore()
        {
            var test = @"
namespace Test
{
    public class TestClass
    {
        private readonly int _someVariable;
    }
}";
            var expected = new DiagnosticResult
            {
                Id = "SA1600D",
                Message = $"members must be correctly documented.",
                Severity = DiagnosticSeverity.Warning,
                Locations =
                    new[] { new DiagnosticResultLocation("Test0.cs", 6, 30) }
            };

            new DocumentationMemberCodeFixVerifier().VerifyCSharpDiagnostic(test, expected);

            var fixtest = @"
namespace Test
{
    public class TestClass
    {
        /// <summary>
        /// the some variable.
        /// </summary>
        private readonly int _someVariable;
    }
}";
            new DocumentationMemberCodeFixVerifier().VerifyCSharpFix(test, fixtest);
        }
开发者ID:jimmymain,项目名称:Documentation.Analyzers,代码行数:34,代码来源:TestSpacingOnFirstVariables.cs


示例7: TestExpressionBodiedProperties

        public void TestExpressionBodiedProperties()
        {
            var test = @"
namespace ConsoleApplication1
{
    class TypeName
    {
        private IAuthenticationManager AuthenticationManager => this.HttpContext.GetOwinContext().Authentication;
    }
}";
            var expected = new DiagnosticResult
            {
                Id = "SA1623D",
                Message = $"property documentation: no documentation.",
                Severity = DiagnosticSeverity.Warning,
                Locations =
                    new[] { new DiagnosticResultLocation("Test0.cs", 6, 40) }
            };

            new DocumentationPropertyCodeFixVerifier().VerifyCSharpDiagnostic(test, expected);

            var fixtest = @"
namespace ConsoleApplication1
{
    class TypeName
    {
        /// <summary>
        /// Gets the authentication manager.
        /// </summary>
        private IAuthenticationManager AuthenticationManager => this.HttpContext.GetOwinContext().Authentication;
    }
}";
            new DocumentationPropertyCodeFixVerifier().VerifyCSharpFix(test, fixtest);
        }
开发者ID:jimmymain,项目名称:Documentation.Analyzers,代码行数:34,代码来源:PublicGetDocumentationTests.cs


示例8: TestThatMethodContainingParametersHaveParametersDetected

        public void TestThatMethodContainingParametersHaveParametersDetected()
        {
            var test = @"
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Diagnostics;

namespace ConsoleApplication1
{
    class TypeName
    {
        /// <summary>
        /// build the vogon constructor fleet.       
        /// </summary>
        /// <param name=""parameterOne"">parameter one</param>
        public void BuildVogonConstructorFleet(string parameterOne, int parameterItemTwo)
        {
        }
    }
}";
            var expected = new DiagnosticResult
            {
                Id = "SA1612D",
                Message = $"method documentation: missing 'parameterItemTwo'.",
                Severity = DiagnosticSeverity.Warning,
                Locations =
                    new[] { new DiagnosticResultLocation("Test0.cs", 17, 21) }
            };

            new DocumentationMethodCodeFixVerifier().VerifyCSharpDiagnostic(test, expected);
        }
开发者ID:jimmymain,项目名称:Documentation.Analyzers,代码行数:34,代码来源:MethodParameterDocumentationDetectionTests.cs


示例9: ClassContainsTwoListsAndAnotherField_ReportDiagnostic

        public void ClassContainsTwoListsAndAnotherField_ReportDiagnostic()
        {
            const string Code = @"
            class SomeClass
            {
                private System.Collections.Generic.List<int> firstList;
                private System.Collections.Generic.List<int> secondList;
                private int intField;

                public SomeClass(int val)
                {
                    this.firstList = new System.Collections.Generic.List<int>();
                    this.secondList = new System.Collections.Generic.List<int>();
                    this.intField = val;
                }
            }";

            var firstExpected = new DiagnosticResult
            {
                Id = "DaVinciOC4",
                Message = "Consider wrapping the collection into a separate class.",
                Severity = DiagnosticSeverity.Info,
                Locations = new[] { new DiagnosticResultLocation("Test0.cs", 4, 62)}
            };

            var secondExpected = new DiagnosticResult
            {
                Id = "DaVinciOC4",
                Message = "Consider wrapping the collection into a separate class.",
                Severity = DiagnosticSeverity.Info,
                Locations = new[] { new DiagnosticResultLocation("Test0.cs", 5, 62) }
            };

            VerifyCSharpDiagnostic(Code, firstExpected, secondExpected);
        }
开发者ID:johannes-schmitt,项目名称:DaVinci,代码行数:35,代码来源:Oc4FirstClassCollectionsTest.cs


示例10: ClassContainsListAndField_ReportDiagnostic

        public void ClassContainsListAndField_ReportDiagnostic()
        {
            const string Code = @"
            class SomeClass
            {
                private int someField;

                private System.Collections.Generic.List<int> list;

                public SomeClass()
                {
                    this.someField = 1;
                    this.list = new System.Collections.Generic.List<int>();
                }
            }";

            var expected = new DiagnosticResult
            {
                Id = "DaVinciOC4",
                Message = "Consider wrapping the collection into a separate class.",
                Severity = DiagnosticSeverity.Info,
                Locations = new[] { new DiagnosticResultLocation("Test0.cs", 6, 62) }
            };

            VerifyCSharpDiagnostic(Code, expected);
        }
开发者ID:johannes-schmitt,项目名称:DaVinci,代码行数:26,代码来源:Oc4FirstClassCollectionsTest.cs


示例11: MethodContainsIfWithElse_OneDiagnosticReported

        public void MethodContainsIfWithElse_OneDiagnosticReported()
        {
            const string Code = @"
            class SomeClass
            {
                private int firstField;

                private int secondField;

                public void Do()
                {
                    if (true)
                    {
                        System.Console.WriteLine();
                    }
                    else
                    {
                        System.Console.WriteLine();
                    }
                }
            }";

            var expected = new DiagnosticResult
            {
                Id = "DaVinciOC2",
                Message = "The else keyword should be avoided.",
                Severity = DiagnosticSeverity.Info,
                Locations = new[] { new DiagnosticResultLocation("Test0.cs", 14, 21) }
            };
            VerifyCSharpDiagnostic(Code, expected);
        }
开发者ID:johannes-schmitt,项目名称:DaVinci,代码行数:31,代码来源:Oc2DoNotUseTheElseKeywordTest.cs


示例12: ConstructorParameterDocumentationAddSingleParameterTest

        public void ConstructorParameterDocumentationAddSingleParameterTest()
        {
            var test = @"
using System;
namespace ConsoleApplication1
{
    public class TypeName
    {
        /// <summary>
        /// a description has been provided.
        /// line 2 of the description.
        /// </summary>
        /// <param name=""parameterOne"">there is some documentation</param>
        /// <param name=""parameterTwo""></param>
        public TypeName(
            string parameterOne,
            int parameterItemTwo,
            string parameterThree)
        {
        }
    }
}";
            var expected = new DiagnosticResult
            {
                Id = "SA1642D",
                Message = $"constructors must be correctly documented.",
                Severity = DiagnosticSeverity.Warning,
                Locations =
                    new[] { new DiagnosticResultLocation("Test0.cs", 13, 16) }
            };

            new DocumentationConstructorCodeFixVerifier().VerifyCSharpDiagnostic(test, expected);

            var fixtest = @"
using System;
namespace ConsoleApplication1
{
    public class TypeName
    {
        /// <summary>
        /// Initializes a new instance of the <see cref=""TypeName""/> class.
        /// a description has been provided.
        /// line 2 of the description.
        /// </summary>
        /// <param name=""parameterOne"">there is some documentation</param>
        /// <param name=""parameterItemTwo"">the parameter item two.</param>
        /// <param name=""parameterThree"">the parameter three.</param>
        public TypeName(
            string parameterOne,
            int parameterItemTwo,
            string parameterThree)
        {
        }
    }
}";
            new DocumentationConstructorCodeFixVerifier().VerifyCSharpFix(test, fixtest);
        }
开发者ID:jimmymain,项目名称:Documentation.Analyzers,代码行数:57,代码来源:ConstructorParameterDocumentationFixTests.cs


示例13: TestMethodBuildsCorrectMethodSummaryAfterFix

        public void TestMethodBuildsCorrectMethodSummaryAfterFix()
        {
            var test = @"
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Diagnostics;

namespace ConsoleApplication1
{
    class TypeName
    {
        public void BuildVogonConstructorFleet()
        {
        }
    }
}";
            var expected = new DiagnosticResult
            {
                Id = "SA1612D",
                Message = $"method documentation: no documentation.",
                Severity = DiagnosticSeverity.Warning,
                Locations =
                    new[] { new DiagnosticResultLocation("Test0.cs", 13, 21) }
            };

            new DocumentationMethodCodeFixVerifier().VerifyCSharpDiagnostic(test, expected);

            var fixtest = @"
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Diagnostics;

namespace ConsoleApplication1
{
    class TypeName
    {
        /// <summary>
        /// build the vogon constructor fleet.
        /// </summary>
        public void BuildVogonConstructorFleet()
        {
        }
    }
}";
            new DocumentationMethodCodeFixVerifier().VerifyCSharpFix(test, fixtest);
        }
开发者ID:jimmymain,项目名称:Documentation.Analyzers,代码行数:52,代码来源:EmptyDocumentationFixTests.cs


示例14: VerifyMissingQuickFixReplacesDocumentation

        public void VerifyMissingQuickFixReplacesDocumentation()
        {
            var test = @"
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Diagnostics;

namespace ConsoleApplication1
{
    class TypeName
    {
        public string TestProperty { get; set; }
    }
}";
            var expected = new DiagnosticResult
            {
                Id = "SA1623D",
                Message = $"property documentation: no documentation.",
                Severity = DiagnosticSeverity.Warning,
                Locations =
                    new[] { new DiagnosticResultLocation("Test0.cs", 13, 23) }
            };

            this.VerifyCSharpDiagnostic(test, expected);

            var fixtest = @"
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Diagnostics;

namespace ConsoleApplication1
{
    class TypeName
    {
        /// <summary>
        /// Gets or sets the test property.
        /// </summary>
        public string TestProperty { get; set; }
    }
}";
            this.VerifyCSharpFix(test, fixtest);
        }
开发者ID:jimmymain,项目名称:Documentation.Analyzers,代码行数:48,代码来源:MissingDocumentationTests.cs


示例15: TestMethod2

        public void TestMethod2()
        {
            var test = @"
            using System;
            using System.Collections.Generic;
            using System.Linq;
            using System.Text;
            using System.Threading.Tasks;
            using System.Diagnostics;

            namespace ConsoleApplication1
            {
            class TypeName
            {
            }
            }";
            var expected = new DiagnosticResult
            {
                Id = "ConfigureAwaitAnalyzer",
                Message = String.Format("Type name '{0}' contains lowercase letters", "TypeName"),
                Severity = DiagnosticSeverity.Warning,
                Locations =
                    new[] {
                            new DiagnosticResultLocation("Test0.cs", 11, 15)
                        }
            };

            this.VerifyCSharpDiagnostic(test, expected);

            var fixtest = @"
            using System;
            using System.Collections.Generic;
            using System.Linq;
            using System.Text;
            using System.Threading.Tasks;
            using System.Diagnostics;

            namespace ConsoleApplication1
            {
            class TYPENAME
            {
            }
            }";
            this.VerifyCSharpFix(test, fixtest);
        }
开发者ID:Rocketmakers,项目名称:hubble,代码行数:45,代码来源:ConfigureAwaitTests.cs


示例16: TestThatReturnValuesAreNotReplaced

        public void TestThatReturnValuesAreNotReplaced()
        {
            var test = @"
namespace ConsoleApplication1
{
    class TypeName
    {
        /// <summary>
        /// build the vogon constructor fleet.       
        /// </summary>
        /// <returns>the result of the application</returns>
        public static int Main<T>(string[] arguments)
        {
        }
    }
}";
            var expected = new DiagnosticResult
            {
                Id = "SA1612D",
                Message = $"method documentation: missing 'arguments'.",
                Severity = DiagnosticSeverity.Warning,
                Locations =
                    new[] { new DiagnosticResultLocation("Test0.cs", 10, 27) }
            };

            new DocumentationMethodCodeFixVerifier().VerifyCSharpDiagnostic(test, expected);

            var fixtest = @"
namespace ConsoleApplication1
{
    class TypeName
    {
        /// <summary>
        /// build the vogon constructor fleet.
        /// </summary>
        /// <param name=""arguments"">the arguments.</param>
        /// <returns>the result of the application</returns>
        /// <typeparam name=""T"">a type of {T}.</typeparam>
        public static int Main<T>(string[] arguments)
        {
        }
    }
}";
            new DocumentationMethodCodeFixVerifier().VerifyCSharpFix(test, fixtest);
        }
开发者ID:jimmymain,项目名称:Documentation.Analyzers,代码行数:45,代码来源:MethodReturnValueTests.cs


示例17: AllowMembersOrderingForMoreThanOneMemberShouldTiggerDiagnostic

        public async void AllowMembersOrderingForMoreThanOneMemberShouldTiggerDiagnostic(string typeDeclaration)
        {
            var test = @"
            " + typeDeclaration + @" Foo
            {
                int bar() { return 0; }
                void car() { }
            }";

            var expected = new DiagnosticResult
            {
                Id = DiagnosticId.AllowMembersOrdering.ToDiagnosticId(),
                Message = AllowMembersOrderingAnalyzer.MessageFormat,
                Severity = DiagnosticSeverity.Hidden,
                Locations = new[] { new DiagnosticResultLocation("Test0.cs", 2, 14 + typeDeclaration.Length) }
            };

            await VerifyCSharpDiagnosticAsync(test, expected);
        }
开发者ID:haroldhues,项目名称:code-cracker,代码行数:19,代码来源:AllowMembersOrderingAnalyzerTests.cs


示例18: TestStaticMainMethodWithASingleParameter

        public void TestStaticMainMethodWithASingleParameter()
        {
            var test = @"
namespace ConsoleApplication1
{
    class TypeName
    {
        /// <summary>
        /// build the vogon constructor fleet.       
        /// </summary>
        /// <param name=""args""></param>
        public static void Main(string[] args)
        {
        }
    }
}";
            var expected = new DiagnosticResult
            {
                Id = "SA1612D",
                Message = $"method documentation: missing 'args'.",
                Severity = DiagnosticSeverity.Warning,
                Locations =
                    new[] { new DiagnosticResultLocation("Test0.cs", 10, 28) }
            };

            new DocumentationMethodCodeFixVerifier().VerifyCSharpDiagnostic(test, expected);

            var fixtest = @"
namespace ConsoleApplication1
{
    class TypeName
    {
        /// <summary>
        /// build the vogon constructor fleet.
        /// </summary>
        /// <param name=""args"">the args.</param>
        public static void Main(string[] args)
        {
        }
    }
}";
            new DocumentationMethodCodeFixVerifier().VerifyCSharpFix(test, fixtest);
        }
开发者ID:jimmymain,项目名称:Documentation.Analyzers,代码行数:43,代码来源:MethodParameterDocumentationFixTests.cs


示例19: TestNamedMethodWithStringReturnValue

        public void TestNamedMethodWithStringReturnValue()
        {
            var test = @"
namespace ConsoleApplication1
{
    class TypeName
    {
        /// <summary>
        /// build the vogon constructor fleet.
        /// </summary>
        public int PerformAFunction()
        {
        }
    }
}";
            var expected = new DiagnosticResult
            {
                Id = "SA1612D",
                Message = $"method documentation: missing return value documentation.",
                Severity = DiagnosticSeverity.Warning,
                Locations =
                    new[] { new DiagnosticResultLocation("Test0.cs", 9, 20) }
            };

            new DocumentationMethodCodeFixVerifier().VerifyCSharpDiagnostic(test, expected);

            var fixtest = @"
namespace ConsoleApplication1
{
    class TypeName
    {
        /// <summary>
        /// build the vogon constructor fleet.
        /// </summary>
        /// <returns>an int containing the perform a function.</returns>
        public int PerformAFunction()
        {
        }
    }
}";
            new DocumentationMethodCodeFixVerifier().VerifyCSharpFix(test, fixtest);
        }
开发者ID:jimmymain,项目名称:Documentation.Analyzers,代码行数:42,代码来源:MethodReturnValueFixTests.cs


示例20: ClassHasThreeFields_OneDiagnosticReportedShowingThreeFields

        public void ClassHasThreeFields_OneDiagnosticReportedShowingThreeFields()
        {
            const string Code = @"
            class SomeClass
            {
                private int firstField;
                private int secondField;
                private int thirdField;
            }";

            var expected = new DiagnosticResult
            {
                Id = "DaVinciOC8",
                Message = "\'SomeClass\' contains more than 2 fields (3).",
                Severity = DiagnosticSeverity.Info,
                Locations = new[] { new DiagnosticResultLocation("Test0.cs", 2, 19) }
            };

            VerifyCSharpDiagnostic(Code, expected);
        }
开发者ID:johannes-schmitt,项目名称:DaVinci,代码行数:20,代码来源:Oc8NoClassesWithMoreThanTwoFieldsTest.cs



注:本文中的DiagnosticResult类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# DiagnosticSeverity类代码示例发布时间:2022-05-24
下一篇:
C# DiagnosticInfoCollection类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap