Code Generation - GeneratedCodeAttribute

All the analysis tools that come with Visual Studio 2008, allow you to suppress analysis on files that were automatically generated by tools and are supposed to be regenerated at some point in time.

The question is how do these tools know that a code as been generated by a tool?

Well, it's very simple. All the classes, members, methods, etc. marked with the GeneratedCodeAttribute are considered as generated by a tool. So, when, for example, creating text templates for the DSL Tools, you'll need to add this attribute to the generated classes. Like this:

   1: /// <summary>
   2: /// Operation request.
   3: /// </summary>
   4: [GeneratedCode("MyDsl.MyCodeGenerator", "2.0.0.0")]
   5: public class OperationRequest
   6: {
   7:     #region Properties
   8:     
   9:     /// <summary>
  10:     /// Id.
  11:     /// </summary>
  12:     public Guid Id { get; set; }
  13:  
  14:     #endregion
  15: }

The following post explains the different usage of this attribute in FxCop and Code Metrics. The interesting thing is that also explains the cases where this attribute should not be used.

Correct Usage of the CompilerGeneratedAttribute and the GeneratedCodeAttribute

Published 02 June 08 03:22 by hgr
Filed under: , , ,

Comments

No Comments
Anonymous comments are disabled