namespace LookUpWhatsNew
{
internal class WhatsNewChecker
{
private static readonly StringBuilder outPutText = new StringBuilder();
private static DateTime backDateTo = new DateTime(2010,2,1);
static void Main(string[] args)
{
Assembly theAssembly = Assembly.Load("VectorClass");
Attribute supportsAttibute = Attribute.GetCustomAttribute(theAssembly, typeof(LastModifiedAttribute));// supportsAttibute 為空!
Conso.Read();
namespace WhatNewAttributes
{
[AttributeUsage(AttributeTargets .Class |AttributeTargets.Method ,AllowMultiple =true ,Inherited =false )]
public class LastModifiedAttribute:Attribute
{
private readonly DateTime dateModified;
private readonly string changes;
public LastModifiedAttribute(string dateModified, string changes)
{
this.dateModified = DateTime.Parse(dateModified);
this.changes = changes;
}
public DateTime DateModified
{
get
{
return this.dateModified;
}
}
public string Changes
{
get
{
return this.changes;
}
}
public string Issues { get; set; }
}
[AttributeUsage(AttributeTargets.Assembly)]
public class SupportWhatsNewAttribute : Attribute
{
}
}
namespace VectorClass
{
[LastModifiedAttribute("14,Feb,2010", "IEnumerable interface implemented so vector can now be treated as a Collection")]
[LastModifiedAttribute("10,Feb,2010", "IFormattable interface implemented so vector now responds to format specifiers N and VE")]
public class Vector:IEnumerable ,IFormattable
{
public double x, y, z;
public Vector(double x,double y,double z)
{
this.x = x;
this.y = y;
this.z = z;
}
[LastModifiedAttribute("10,Feb,2010", "Method added in order to formating support")]
public string ToString(string format, IFormatProvider formatProvider)
{
if (format == null)
{
return ToString();
}
switch (format)
{
case "N":
return string.Format("({0},{1},{2})", x, y, z);
case "VE":
return string.Format("{0}i+{1}j+{2}k", x, y, z);
default:
throw new ArgumentException("No {0} format !", format);
}
}
public string ToString(string format)
{
return ToString(format, null);
}
public IEnumerator GetEnumerator()
{
yield return x;
yield return y;
yield return z;
}
[LastModifiedAttribute("14,Feb,2010", "Class create as part of collection support for Vector")]
private class VectorIEnumerator : IEnumerator
{
public object Current
{
get { throw new NotImplementedException(); }
}
public bool MoveNext()
{
throw new NotImplementedException();
}
public void Reset()
{
throw new NotImplementedException();
}
}
}
}
foreach (Type type in theAssembly.GetTypes())
{
LastModifiedAttribute supportsAttibute = type.GetCustomAttributes(false)
.Cast()
.SingleOrDefault();
if (supportsAttibute != null)
{
Console.WriteLine((supportsAttibute.DateModified);
}
}