Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add XML documentation / comments to properties/fields in EF generated classes

i have the habbit to comment properties and classes with the standard XML documentation, what it means / what they do.

But in EF generated classes off course, these are all gone when i regenerate the model.

Is there another way to do this?

like image 762
Michel Avatar asked Oct 06 '11 09:10

Michel


People also ask

What is XML comments C#?

C# documentation comments use XML elements to define the structure of the output documentation. One consequence of this feature is that you can add any valid XML in your documentation comments. The C# compiler copies these elements into the output XML file.

How do I auto generate comments in Visual Studio?

The only way I know to do this is on the line right above your method just type "///" and it will generate a comment template based on the method.

How do you comment out a class in C#?

Single-line comments The most basic type of comment in C# is the single-line comment. As the name indicates, it turns a single line into a comment - let's see how it might look: // My comments about the class name could go here... // My comments about the class name could go here...

How do you comment a function in C#?

A comment is preceded by an double forward slash. The code of line after the double forward slash is simply ignored by the compiler. To code a comment, type an double forward slash followed by the comment. You can use this technique to add a comment on its own line or to add a comment after the code on a line.


1 Answers

As Ladislav stated in his answer, you need to modify the T4 template so the comments will be included in the generated code. This answer was taken from this article:

First of all you need to specify your comments in the properties boxes of the model designer. Under Documentation -> Long Description, and Summary.

Then in the template, you can for example add this above the property you want to document:

<#if (!ReferenceEquals(edmProperty.Documentation, null))
{
#>
/// <summary>
/// <#=edmProperty.Documentation.Summary#> – <#=edmProperty.Documentation.LongDescription#>
/// </summary>
<#}#>

This will create a summary block above your property in the generated code.

like image 145
Edwin de Koning Avatar answered Oct 04 '22 17:10

Edwin de Koning