Attributes

I just wanted verification on this. If I use custom attributes to document bug fixes in my code, will that effect run-time performance
[BugFix("01/01/07", "Fixed problem with calculation...")]
[BugFix("01/04/07", "Added error-handling....")]
public void MyMethod()
{
................



Answer this question

Attributes

  • Gunston

    Hey that's pretty cool, I've never thought of doing that. But I have no idea if it will cause any performance hit. I would be interested in know if it does or not as that would be pretty handy to be able to do for the project I'm working on.


  • Fran&#231&#59;ois296449

    I could use the XML comments, but I could also use the attributes, since they will generate with the SandCastle documentation. Also it allows the possibility of building a utility to pull the code modifications out into a report all by itself via reflection.


  • lamont_23

    Why don't you use comments for that


  • CGuyArun

    You could  use the XML /// comments and pull them out of the generated XML also.  I kind of like the attribute better because it is easier to create because of the intellisense.

    ///<bugfix>Fixed bug</bugfix>

     

    I can send you the custom attribute I created for this later today.  I assume it just gets compiled into the Metadata and doesn't affect the performance much at run-time, except for a slighlty larger assembly.


  • Triangle1408

    I had also thought about using a custom BusinessRule attribute to document my classes business rules, but once again, if it will significanlty affect run-time performance, I don't want to do that.
  • spattewar

    Dont' worry about it I'll figure it out myself, there has to be a way to though to enter in custom attributes for comments so that intellisense will include it in it's list, and then you wouldn't even have the problem of a larger assembly.

    I just think the idea of getting bug fixes through reflection is kind of cool, you could build a class browser like the one smalltalk uses that displays the bug fixes and other related metadata, actually I think I'll do that myself.


  • Kinetic Media

    O'Reilly gives the Bug Fix as an example of using an Attribute, so i guess it is OK

    http://www.oreilly.com/catalog/progcsharp/chapter/ch18.html .

    Custom Attributes

    You are free to create your own custom attributes and use them at runtime as you see fit. Suppose, for example, that your development organization wants to keep track of bug fixes. You already keep a database of all your bugs, but you'd like to tie your bug reports to specific fixes in the code.

    You might add comments to your code along the lines of:

    // Bug 323 fixed by Jesse Liberty 1/1/2005.
    

    This would make it easy to see in your source code, but there is no enforced connection to Bug 323 in the database. A custom attribute might be just what you need. You would replace your comment with something like this:

    [BugFixAttribute(323,"Jesse Liberty","1/1/2005") 
    Comment="Off by one error"]
    

    You could then write a program to read through the metadata to find these bug-fix notations and update the database. The attribute would serve the purposes of a comment, but would also allow you to retrieve the information programmatically through tools you'd create.


  • Attributes