获取最后修改的方法

getting method last modified

我有一个问题。我需要检查上次修改方法的时间。我知道如何检查这个文件,但没有找到任何东西我怎么能只检查一个方法。我必须做的作业如下:

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.

如果有人可以帮助完成关于程序员和枚举值的最后一部分任务,我也会应用它,但我主要对上次修改日期的方法感兴趣。感谢期待

听起来您需要 custom attribute

您可以使用

使其单独处理方法
[AttributeUsage(AttributeTargets.Method)]
public class MyAttribute : Attribute
{
    ...
    public MyAttribute(string name, DateTime lastChanged, CustomEnum reason)
    {
        ... 

这不会自动找出上次修改方法的时间和原因。该信息不存在于文件中,您的作业也没有说明。您需要一个单独的程序来从您使用的任何版本控制系统生成适当的属性标签,或者您可以依靠程序员来创建适当的标签。