Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the utility of the attribute GeneratedCodeAttribute in C #?

I generated some of my C# code with an external tool. Each generated class has an attribute GeneratedCodeAttribute. Why is my generator creating this attribute?

like image 645
Bastien Vandamme Avatar asked Mar 05 '10 16:03

Bastien Vandamme


2 Answers

This attribute was set because this code is generated by tool, not by human :) what is use of it you might ask? MSDN tells us:

The GeneratedCodeAttribute class can be used by code analysis tools to identify computer-generated code, and to provide an analysis based on the tool and the version of the tool that generated the code.

like image 114
Andrey Avatar answered Nov 15 '22 14:11

Andrey


The first link is its documentation and the second link is a detailed description of what this is for, why code generators produce it, and how code analyzers consume it.

http://msdn.microsoft.com/en-us/library/system.codedom.compiler.generatedcodeattribute.aspx

and

https://blogs.msdn.microsoft.com/codeanalysis/2007/04/27/correct-usage-of-the-compilergeneratedattribute-and-the-generatedcodeattribute/

Does that answer your question?

like image 30
Eric Lippert Avatar answered Nov 15 '22 13:11

Eric Lippert