LookUpWhatsNew.cs
上传用户:lxycoco
上传日期:2022-07-21
资源大小:38457k
文件大小:3k
源码类别:

C#编程

开发平台:

Others

  1. using System;
  2. using System.Reflection;
  3. using System.Windows.Forms;
  4. using System.Text;
  5. using Wrox.ProCSharp.VectorClass;
  6. using Wrox.ProCSharp.WhatsNewAttributes;
  7. namespace Wrox.ProCSharp.LookUpWhatsNew
  8. {
  9.    class WhatsNewChecker
  10.    {
  11.       static StringBuilder outputText = new StringBuilder(1000);
  12.       static DateTime backDateTo = new DateTime(2002, 2, 1);
  13.       
  14.       static void Main()
  15.       {
  16.          Assembly theAssembly = Assembly.Load("VectorClass");
  17.          Attribute supportsAttribute = 
  18.             Attribute.GetCustomAttribute(
  19.                theAssembly, typeof(SupportsWhatsNewAttribute));
  20.          string Name = theAssembly.FullName;
  21.          AddToMessage("Assembly: " + Name);
  22.          if (supportsAttribute == null)
  23.          {
  24.             AddToMessage(
  25.                "This assembly does not support WhatsNew attributes");
  26.             return;
  27.          }
  28.          else 
  29.             AddToMessage("Defined Types:");
  30.          Type[] types = theAssembly.GetTypes();
  31.          foreach(Type definedType in types)
  32.             DisplayTypeInfo(theAssembly, definedType);
  33.          MessageBox.Show(outputText.ToString(), 
  34.             "What's New since " + backDateTo.ToLongDateString());
  35.          Console.ReadLine();
  36.       }
  37.       static void DisplayTypeInfo(Assembly theAssembly, Type type)
  38.       {
  39.          // make sure we only pick out classes
  40.          if (!(type.IsClass))
  41.             return;
  42.          AddToMessage("nclass " + type.Name);
  43.          Attribute [] attribs = Attribute.GetCustomAttributes(type);
  44.          if (attribs.Length == 0)
  45.             AddToMessage("No changes to this class");
  46.          else
  47.             foreach (Attribute attrib in attribs)
  48.                WriteAttributeInfo(attrib);
  49.       
  50.          MethodInfo [] methods = type.GetMethods();
  51.          AddToMessage("CHANGES TO METHODS OF THIS CLASS:");
  52.          foreach (MethodInfo nextMethod in methods)
  53.          {
  54.             object [] attribs2 = 
  55.                nextMethod.GetCustomAttributes(
  56.                   typeof(LastModifiedAttribute), false);
  57.             if (attribs != null)
  58.             {
  59.                AddToMessage(
  60.                   nextMethod.ReturnType + " " + nextMethod.Name + "()");
  61.                foreach (Attribute nextAttrib in attribs2)
  62.                   WriteAttributeInfo(nextAttrib);
  63.             }
  64.          }
  65.       }
  66.       static void WriteAttributeInfo(Attribute attrib)
  67.       {
  68.          LastModifiedAttribute lastModifiedAttrib =
  69.             attrib as LastModifiedAttribute;
  70.          if (lastModifiedAttrib == null)
  71.             return;
  72.          // check that date is in range
  73.          DateTime modifiedDate = lastModifiedAttrib.DateModified;
  74.          if (modifiedDate < backDateTo)
  75.             return;
  76.          AddToMessage("  MODIFIED: " +
  77.             modifiedDate.ToLongDateString() + ":");
  78.          AddToMessage("    " + lastModifiedAttrib.Changes);
  79.          if (lastModifiedAttrib.Issues != null)
  80.             AddToMessage("    Outstanding issues:" +
  81.                lastModifiedAttrib.Issues);
  82.       }
  83.       static void AddToMessage(string message)
  84.       {
  85.          outputText.Append("n" + message);
  86.       }
  87.    }
  88. }