[Mono-devel-list] Finding Values for all Attributes for classes.

Lluis Sanchez lluis at ximian.com
Mon Feb 23 06:19:20 EST 2004


On dl, 2004-02-23 at 11:03, S Umadevi wrote:
> Hi,
>    I am trying to complete the implementation of classes in
> system.data. In most of the classes some  attributes are not implemented
> for the class /properties/methods. Since there is no documentation of
> the values for the  attributes with the .NET,
> 
>  I need to run the following code on .NET and get the values to be
> used.
> 
> The problem with the following code is that
> 1. I need to find all the attributes that need to be implemented by the
> class.
> 2. I need to know the properties of the attributes so that I can call
> it to print the values.
> 3. Do it for each of the classes..
> 
> Since I am doing it for lots of classes, I need to keep modifying this
> code to get the values.
> Any ideas/ pointers on any generic mechansim to do this ?

Use Assembly.GetTypes() to get all types defined in an assembly. You can
then iterate through the list and execute your code. To display the
value of the properties for each attribute, just add:

foreach (PropertyInfo attrProp in attr.GetType().GetProperties())
	Console.WriteLine ("{0}={1}",attrProp.Name, attrProp.GetValue
(attrProp,null));

> 
> 
> >> code start
> 
>                              Type type =
> typeof(System.Data.SqlClient.SqlClientPermission);
> 		ObsoleteAttribute a;
> 		foreach (PropertyInfo prop in type.GetProperties())
> 		{
> 			foreach (Attribute attr in
> prop.GetCustomAttributes(true))
> 			{
> 				a = attr as ObsoleteAttribute;
> 				if ( null!= a)
> 				{
> 					Console.WriteLine("proprerties 
> {0}, {1}",a.Message,a.IsError);
> 				}
> 			}
> 			}
> 		
> 		// method info
> 		foreach (MethodInfo method in type.GetMethods())
> 		{
> 			foreach (Attribute attr in
> method.GetCustomAttributes(true))
> 			{
> 				a = attr as System.ObsoleteAttribute;
> 
> 				if ( null!= a)
> 				{
> 					Console.WriteLine("methods  {0},
> {1}",a.Message,a.IsError);
> 				
> 			}
> 			}
> 		}
> 
> // constructors
> 		foreach (ConstructorInfo method in
> type.GetConstructors())
> 		{
> 			foreach (Attribute attr in
> method.GetCustomAttributes(true))
> 			{
> 				a = attr as System.ObsoleteAttribute;
> 				if ( null!= a)
> 				{
> 			                         
> Console.WriteLine("constructores  {0}, {1}",a.Message,a.IsError);
> 						
> 			}
> 			}
> 		}
> 
> 		//for the class
> 			foreach (Attribute attr in
> type.GetCustomAttributes(true))
> 			{
> 				a = attr as System.ObsoleteAttribute;
> 				if ( null!= a)
> 				{
> 					Console.WriteLine(" class {0},
> {1}",a.Message,a.IsError);
> 				}
> 			}
> 
> 
> 		}
> 	}
> 
> 
> >> code end..
> 
> regards
> uma
> 
> 
> _______________________________________________
> Mono-devel-list mailing list
> Mono-devel-list at lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/mono-devel-list




More information about the Mono-devel-list mailing list