[Mono-list] Adding missing Attributes to System.Web

Duncan Mak duncan@ximian.com
10 Jun 2002 18:11:22 -0400


--=-3GEGAazyb5Dkb1R/4b3V
Content-Type: text/plain
Content-Transfer-Encoding: 7bit

Hey guys,

We're missing a bunch of Attributes in the classes for the System.Web
namespace. I played around with the reflection API (always fun!) and
came up with a tool that'll show what Attributes are missing in each
class.

If anyone's interested, you can use this tool to add the missing bits to
the classes. This is a great way to start contributing to the project.
Any help is really appreciated.

If you look into the ToString() method in the AttributeCollection class
in the file, you'll see that there's a 'filter' for finding out what
type of Attribute it is. All you need to do is add new filters, then
find out from the documentation what useful information can obtained
from each particular Attribute.

Gonzalo said that, when adding these Attributes, please start with
System.Web.UI.HtmlControls, then WebControls, then Validators.

If there is any other questions, please mail me.

Thanks,

-- 
Duncan Mak <duncan@ximian.com>

--=-3GEGAazyb5Dkb1R/4b3V
Content-Disposition: attachment; filename=attributes.cs
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain; name=attributes.cs; charset=ISO-8859-1

//=20
// Attributes.cs - Let's go look up some Attributes!
//=20
// Author: Duncan Mak (duncan@ximian.com)
//=20
// (C) Ximian, Inc.
//=20

using System;
using System.Collections;
using System.ComponentModel;
using System.Reflection;
using System.Text;
using System.Web.UI;

class X {
	static void Main ()
	{
		Page p =3D new Page ();
		Type type =3D p.GetType ();
		Assembly web =3D Assembly.GetAssembly (type);
		Type[] types =3D web.GetTypes ();
	=09
		Hashtable ht =3D new Hashtable ();

		foreach (Type t in types)
			ht.Add (t.FullName, new AttributeCollection (t.GetCustomAttributes (true=
)));
	=09
		foreach (object key in ht.Keys)
			Console.WriteLine (key + ":\n" + ht[key]);
	}
}

class AttributeCollection {
	object [] attributes;
=09
	public AttributeCollection (object [] att)
	{
		attributes =3D att;
	}
=09
	public override string ToString ()
	{
		StringBuilder s =3D new StringBuilder ();
	=09
		foreach (Attribute a in attributes) {
		=09
			s.Append ("\t[" + a + "]\n");
		=09
			if (a is ControlBuilderAttribute) {
				ControlBuilderAttribute c =3D a as ControlBuilderAttribute;
				s.Append ("\t\t" + c.BuilderType.FullName + "\n");
			}
		=09
			if (a is DefaultEventAttribute) {
				DefaultEventAttribute c =3D a as DefaultEventAttribute;
				s.Append ("\t\t" + c.Name + "\n");
			}
		=09
			if (a is DefaultPropertyAttribute) {
				DefaultPropertyAttribute c =3D a as DefaultPropertyAttribute;
				s.Append ("\t\t" + c.Name + "\n");
			}

			if (a is DefaultMemberAttribute) {
				DefaultMemberAttribute c =3D a as DefaultMemberAttribute;
				s.Append ("\t\t" + c.MemberName + "\n");
			}
		=09
			//
			// Add more here
			// if (a is SOME_ATTRIBUTE) {
			//  SOME_ATTRIBUTE x =3D a as SOME_ATTRIBUTE;
			// s.Append ("\t\t" + x.SOME_PROPERTY + "\n");
			//=20
		}		=09
		return s.ToString ();
	}
}

--=-3GEGAazyb5Dkb1R/4b3V--