Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Attributes and XML Documentation for method/property

Tags:

syntax

c#

wpf

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#.

like image 656
XAMeLi Avatar asked Sep 23 '12 17:09

XAMeLi


People also ask

What is XML documentation in C#?

The C# compiler combines the structure of the C# code with the text of the comments into a single XML document. The C# compiler verifies that the comments match the API signatures for relevant tags. Tools that process the XML documentation files can define XML elements and attributes specific to those tools.

What is the proper commenting method for XML?

To insert XML comments for a code element Type /// in C#, or ''' in Visual Basic.

What is an attribute C#?

Advertisements. An attribute is a declarative tag that is used to convey information to runtime about the behaviors of various elements like classes, methods, structures, enumerators, assemblies etc. in your program. You can add declarative information to a program by using an attribute.


1 Answers

Use the first case,

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

Resharper likes it and it should give you Something here in Intellisense. When it doesn't then there is another problem to solve.

like image 142
Henk Holterman Avatar answered Oct 16 '22 09:10

Henk Holterman