C# 如何让Stylecop在使用Sandcastle记录名称空间时停止抱怨?
我正试图按照StackOverflow的建议记录我的名称空间回答:C# 如何让Stylecop在使用Sandcastle记录名称空间时停止抱怨?,c#,stylecop,sandcastle,C#,Stylecop,Sandcastle,我正试图按照StackOverflow的建议记录我的名称空间回答: namespace Test { /// <summary> /// The documentation for my namespace goes here. /// </summary> [System.Runtime.CompilerServices.CompilerGenerated] internal class NamespaceDoc {
namespace Test
{
/// <summary>
/// The documentation for my namespace goes here.
/// </summary>
[System.Runtime.CompilerServices.CompilerGenerated]
internal class NamespaceDoc
{
}
// (other classes below...)
}
然而,我无法让它忽略第一个警告。我尝试应用另一个属性,但没有成功:
[System.Diagnostics.CodeAnalysis.SuppressMessage(
"StyleCop.CSharp.Maintainability",
"*",
Justification = "Hack for Sandcastle.")]
让Sandcastle和StyleCop玩得好的最好方法是什么
我知道我可以在Sandcastle help file builder中更改设置以记录名称空间,但除非我需要,否则我不希望更改,因为我希望所有文档都在源代码级别可用。我也不想完全禁用这些规则,因为它们在大多数情况下都很有用 我认为没有现成的解决办法。我认为在保持整洁的同时,最好的办法是实现自己的StyleCop规则。您可以考虑触发规则SA1402和SA120 2的规则,除非在“沙特堡上下文”下。然后在StyleCop配置中禁用规则SA1402和SA1202
您可以看看如何为StyleCop创建一个规则。只是为了参考,我想我应该记录我最后做了什么 基本上,我只是为我拥有的每个名称空间创建了一个新的
.cs
文件(例如,为Foo
名称空间创建了FooDoc.cs
),并将我的代码格式化如下:
// <copyright file="FooDoc.cs" company="Bar Company">
// Copyright (c) 2013 Bar Company. All rights reserved.
// </copyright>
namespace Foo
{
/// <summary>
/// Documentation here.
/// </summary>
[System.Runtime.CompilerServices.CompilerGenerated]
internal class FooDoc
{
}
}
//
//版权所有(c)2013酒吧公司。版权所有。
//
名称空间Foo
{
///
///这里有文档。
///
[System.Runtime.CompilerServices.CompilerGenerated]
内部类FooDoc
{
}
}
这有点像黑客,因为我基本上只是添加了一个额外的文件来记录我的名称空间,但它确实让我的文档在项目和Sandcastle中保持100%的兼容性,而不会打乱Stylecop或我一直在使用的其他代码分析工具
// <copyright file="FooDoc.cs" company="Bar Company">
// Copyright (c) 2013 Bar Company. All rights reserved.
// </copyright>
namespace Foo
{
/// <summary>
/// Documentation here.
/// </summary>
[System.Runtime.CompilerServices.CompilerGenerated]
internal class FooDoc
{
}
}