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

S Umadevi sumadevi at novell.com
Mon Feb 23 05:03:53 EST 2004


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 ?


>> 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





More information about the Mono-devel-list mailing list