Search code examples
c#methodsattributeslast-modified

getting method last modified


I have a question. I need to check when was a method last modified. I know how to check this for files but didn't find anything how can i check just a method. The assignment i have to do is the following:

Write a LastModifiedAttribute that can be applied to a method. The attribute should specify the date and programmer who last touched the method and possibly an enumerated value of why the method was changed (new feature, defect correction, etc.). Write a program that loads an assembly and lists the classes and methods, sorted by their lastmodified date.

If somebody can help with the last part of the assigment too about the programmer and the enumerated value i would appricate that too, but i'm mainly interested in the method last modified date. Thx anticipated


Solution

  • It sounds like you need a custom attribute.

    You can make it work on methods alone using

    [AttributeUsage(AttributeTargets.Method)]
    public class MyAttribute : Attribute
    {
        ...
        public MyAttribute(string name, DateTime lastChanged, CustomEnum reason)
        {
            ... 
    

    This does not automatically find out when the method was last modified and why. That information is not present in the files, and your assignment doesn't say it is. You need a separate program to generate appropriate attribute tags from whatever version control system you use, or you can rely on the programmers to create appropriate tags.