using System ;
using System.Reflection ;
using MyAttributeClasses ;
public class TestMyAttribute
{
public static void Main( )
{
DisplayDefectTrack( "MyAttributes" ) ;
Console.ReadLine();
}
public static void DisplayDefectTrack(
string lcAssembly )
{
Assembly loAssembly =
Assembly.Load( lcAssembly ) ;
Type[ ] laTypes = loAssembly.GetTypes( ) ;
foreach( Type loType in laTypes )
{
Console.WriteLine("*======================*" ) ;
Console.WriteLine( "TYPE:\t" +
loType.ToString( ) ) ;
Console.WriteLine( "*=====================*" ) ;
object[ ] laAttributes =
loType.GetCustomAttributes(
typeof( DefectTrackAttribute ),
false ) ;
if( laAttributes.Length > 0 )
Console.WriteLine( "\nMod/Fix Log:" ) ;
foreach( Attribute loAtt in laAttributes )
{
DefectTrackAttribute loDefectTrack =
(DefectTrackAttribute)loAtt ;
Console.WriteLine( "----------------------" ) ;
Console.WriteLine( "Defect ID:\t" +
loDefectTrack.DefectID ) ;
Console.WriteLine( "Date:\t\t" +
loDefectTrack.ModificationDate ) ;
Console.WriteLine( "Developer ID:\t" +
loDefectTrack.DeveloperID ) ;
Console.WriteLine( "Origin:\t\t" +
loDefectTrack.Origin ) ;
Console.WriteLine( "Comment:\n" +
loDefectTrack.FixComment ) ;
}
MethodInfo[ ] laMethods =
loType.GetMethods(
BindingFlags.Public |
BindingFlags.Instance |
BindingFlags.DeclaredOnly ) ;
if( laMethods.Length > 0 )
{
Console.WriteLine( "\nMethods: " ) ;
Console.WriteLine( "----------------------" ) ;
}
foreach( MethodInfo loMethod in laMethods )
{
Console.WriteLine( "\n\t" +
loMethod.ToString( ) ) ;
object[ ] laMethodAttributes =
loMethod.GetCustomAttributes(
typeof( DefectTrackAttribute ),
false ) ;
if( laMethodAttributes.Length > 0 )
Console.WriteLine( "\n\t\tMod/Fix Log:" ) ;
foreach( Attribute loAtt in laMethodAttributes )
{
DefectTrackAttribute loDefectTrack =
(DefectTrackAttribute)loAtt ;
Console.WriteLine( "\t\t----------------" ) ;
Console.WriteLine( "\t\tDefect ID:\t" +
loDefectTrack.DefectID ) ;
Console.WriteLine( "\t\tDeveloper ID:\t" +
loDefectTrack.DeveloperID ) ;
Console.WriteLine( "\t\tOrigin:\t\t" +
loDefectTrack.Origin ) ;
Console.WriteLine( "\t\tComment:\n\t\t" +
loDefectTrack.FixComment ) ;
}
}
Console.WriteLine( "\n\n" ) ;
}
}
}