35

When I want to have an attribute and XML documentation for a method/property - what is the correct order to write them above the method/property?

This sounds so trivial, but...

If I use:

/// <summary>
/// Something here
/// </summary>
[MyAttribute]
public void MyMethod() {}

Build is successful and ReSharper is "happy", but I don't see the documentation in IntelliSense for MyClass.MyMethod.

When I use:

[MyAttribute]
/// <summary>
/// Something here
/// </summary>
public void MyMethod() {}

Build is successful but ReSharper has a warning (XML comment is not placed on a valid language element), and I still don't see the documentation in IntelliSense for MyClass.MyMethod.

I've searched the internet and see only examples where attributes are used without documentation; or documentation without attributes.

Is there really no way to have attributes and XML documentation for the same method/property?

Info: WPF application, .NET 4.0, C#.

4

1 回答 1

33

使用第一种情况,

/// <summary>
/// Something here
/// </summary>
[MyAttribute]
public void MyMethod() {}

Resharper 喜欢它,它应该在 Intellisense 中为您提供一些东西。如果没有,那么还有另一个问题需要解决。

于 2012-09-23T18:04:49.810 回答