Browse Source

2007-08-25 Ivan N. Zlatev <[email protected]>

	* TypeDescriptionProvider.cs: implemented.
	* TypeDescriptionProviderAttribute.cs: implemented.
	* CustomTypeDescriptor.cs: implemented.
	* TypeDescriptor.cs: Implement CreateInstance.


svn path=/trunk/mcs/; revision=84843
Ivan Zlatev 18 years ago
parent
commit
f36cc45ae4

+ 7 - 0
mcs/class/System/System.ComponentModel/ChangeLog

@@ -1,3 +1,10 @@
+2007-08-25  Ivan N. Zlatev  <[email protected]>
+
+	* TypeDescriptionProvider.cs: implemented.
+	* TypeDescriptionProviderAttribute.cs: implemented.
+	* CustomTypeDescriptor.cs: implemented.
+	* TypeDescriptor.cs: Implement CreateInstance.
+
 2007-08-20  Gert Driesen  <[email protected]>
 
 	* EnumConverter.cs: Conversion to and from Enum [] is 2.0 only. 

+ 78 - 37
mcs/class/System/System.ComponentModel/CustomTypeDescriptor.cs

@@ -1,11 +1,10 @@
 //
-// CustomTypeDescriptor.cs
+// System.ComponentModel.CustomTypeDescriptor
 //
-// Author:
-//	Atsushi Enomoto  <[email protected]>
-//
-// Copyright (C) 2007 Novell, Inc. http://www.novell.com
+// Authors:		
+//		Ivan N. Zlatev (contact i-nZ.net)
 //
+// (C) 2007 Ivan N. Zlatev
 
 //
 // Permission is hereby granted, free of charge, to any person obtaining
@@ -34,90 +33,132 @@ using System;
 
 namespace System.ComponentModel
 {
+
 	public abstract class CustomTypeDescriptor : ICustomTypeDescriptor
 	{
+
+		private ICustomTypeDescriptor _parent;
+		
 		protected CustomTypeDescriptor ()
 		{
 		}
 
-		[MonoTODO]
-		protected CustomTypeDescriptor (ICustomTypeDescriptor other)
+		
+		protected CustomTypeDescriptor (ICustomTypeDescriptor parent)
 		{
-			throw new NotImplementedException ();
+			_parent = parent;
 		}
 
-		[MonoTODO]
+
 		public virtual AttributeCollection GetAttributes ()
 		{
-			throw new NotImplementedException ();
+			if (_parent != null)
+				return _parent.GetAttributes ();
+
+			return AttributeCollection.Empty;
 		}
 
-		[MonoTODO]
+
 		public virtual string GetClassName ()
 		{
-			throw new NotImplementedException ();
+			if (_parent != null)
+				return _parent.GetClassName ();
+
+			return null;
 		}
 
-		[MonoTODO]
+
 		public virtual string GetComponentName ()
 		{
-			throw new NotImplementedException ();
+			if (_parent != null)
+				return _parent.GetComponentName ();
+
+			return null;
 		}
 
-		[MonoTODO]
+
 		public virtual TypeConverter GetConverter ()
 		{
-			throw new NotImplementedException ();
+			if (_parent != null)
+				return _parent.GetConverter ();
+
+			return new TypeConverter();
 		}
 
-		[MonoTODO]
-		public virtual EventDescriptor GetDefaultEvent ()
+
+		public virtual EventDescriptor GetDefaultEvent()
 		{
-			throw new NotImplementedException ();
+			if (_parent != null)
+				return _parent.GetDefaultEvent ();
+			
+			return null;
 		}
 
-		[MonoTODO]
+
 		public virtual PropertyDescriptor GetDefaultProperty ()
 		{
-			throw new NotImplementedException ();
+			if (_parent != null)
+				return _parent.GetDefaultProperty ();
+			
+			return null;
 		}
 
-		[MonoTODO]
-		public virtual Object GetEditor (Type editorBaseType)
+		
+		public virtual object GetEditor (Type editorBaseType)
 		{
-			throw new NotImplementedException ();
+			if (_parent != null)
+				return _parent.GetEditor (editorBaseType);
+
+			return null;
 		}
 
-		[MonoTODO]
+
 		public virtual EventDescriptorCollection GetEvents ()
 		{
-			throw new NotImplementedException ();
+			if (_parent != null)
+				return _parent.GetEvents ();
+			
+			return EventDescriptorCollection.Empty;
 		}
 
-		[MonoTODO]
-		public virtual EventDescriptorCollection GetEvents (Attribute [] attributes)
+ 
+		public virtual EventDescriptorCollection GetEvents (Attribute[] attributes)
 		{
-			throw new NotImplementedException ();
+			if (_parent != null)
+				return _parent.GetEvents(attributes);
+			
+			return EventDescriptorCollection.Empty;
 		}
 
-		[MonoTODO]
+ 
 		public virtual PropertyDescriptorCollection GetProperties ()
 		{
-			throw new NotImplementedException ();
+			if (_parent != null)
+				return _parent.GetProperties ();
+			
+			return PropertyDescriptorCollection.Empty;
 		}
 
-		[MonoTODO]
-		public virtual PropertyDescriptorCollection GetProperties (Attribute [] attributes)
+		
+		public virtual PropertyDescriptorCollection GetProperties (Attribute[] attributes)
 		{
-			throw new NotImplementedException ();
+			if (_parent != null)
+				return _parent.GetProperties (attributes);
+			
+			return PropertyDescriptorCollection.Empty;
 		}
 
-		[MonoTODO]
-		public virtual Object GetPropertyOwner (PropertyDescriptor pd)
+
+		public virtual object GetPropertyOwner (PropertyDescriptor pd)
 		{
-			throw new NotImplementedException ();
+			if (_parent != null)
+				return _parent.GetPropertyOwner (pd);
+			
+			return null;
 		}
+		
 	}
+	
 }
 
 #endif

+ 72 - 34
mcs/class/System/System.ComponentModel/TypeDescriptionProvider.cs

@@ -1,11 +1,10 @@
 //
-// TypeDescriptionProvider.cs
+// System.ComponentModel.TypeDescriptionProvider
 //
-// Author:
-//	Atsushi Enomoto  <[email protected]>
-//
-// Copyright (C) 2007 Novell, Inc. http://www.novell.com
+// Authors:		
+//		Ivan N. Zlatev (contact i-nZ.net)
 //
+// (C) 2007 Ivan N. Zlatev
 
 //
 // Permission is hereby granted, free of charge, to any person obtaining
@@ -35,78 +34,117 @@ using System.Collections;
 
 namespace System.ComponentModel
 {
+
 	public abstract class TypeDescriptionProvider
 	{
-		protected TypeDescriptionProvider ()
+
+		private sealed class EmptyCustomTypeDescriptor : CustomTypeDescriptor 
 		{
 		}
 
-		[MonoTODO]
-		protected TypeDescriptionProvider (TypeDescriptionProvider other)
+		private EmptyCustomTypeDescriptor _emptyCustomTypeDescriptor;
+		private TypeDescriptionProvider _parent;
+		
+		protected TypeDescriptionProvider ()
+		{
+		}
+		
+		protected TypeDescriptionProvider (TypeDescriptionProvider parent)
 		{
-			throw new NotImplementedException ();
+			_parent = parent;
 		}
 
-		[MonoTODO]
-		public virtual Object CreateInstance (IServiceProvider provider, Type objectType, Type [] argTypes, object [] args)
+		public virtual object CreateInstance (IServiceProvider provider, Type objectType, Type[] argTypes, object[] args)
 		{
-			throw new NotImplementedException ();
+			if (_parent != null)
+				return _parent.CreateInstance (provider, objectType, argTypes, args);
+			
+			return System.Activator.CreateInstance (objectType, args);
 		}
 
-		[MonoTODO]
+
 		public virtual IDictionary GetCache (object instance)
 		{
-			throw new NotImplementedException ();
+			if (_parent != null)
+				return _parent.GetCache (instance);
+
+			return null;
 		}
 
-		[MonoTODO]
+		
 		public virtual ICustomTypeDescriptor GetExtendedTypeDescriptor (object instance)
 		{
-			throw new NotImplementedException ();
+			if (_parent != null)
+				return _parent.GetExtendedTypeDescriptor (instance);
+
+			if (_emptyCustomTypeDescriptor == null)
+				_emptyCustomTypeDescriptor = new EmptyCustomTypeDescriptor ();
+						
+			return _emptyCustomTypeDescriptor;
 		}
 
-		[MonoTODO]
+		
 		public virtual string GetFullComponentName (object component)
 		{
-			throw new NotImplementedException ();
+			if (_parent != null)
+				return _parent.GetFullComponentName (component);
+
+			return GetTypeDescriptor (component).GetComponentName ();
 		}
 
-		[MonoTODO]
-		public Type GetReflectionType (Type objectType)
+		
+		public Type GetReflectionType (object instance)
 		{
-			throw new NotImplementedException ();
+			if (instance == null)
+				throw new ArgumentNullException ("instance");
+
+			return GetReflectionType (instance.GetType (), instance);
 		}
 
-		[MonoTODO]
-		public Type GetReflectionType (object instance)
+		
+		public Type GetReflectionType (Type objectType)
 		{
-			throw new NotImplementedException ();
+			return GetReflectionType (objectType, null);
 		}
 
-		[MonoTODO]
+
 		public virtual Type GetReflectionType (Type objectType, object instance)
 		{
-			throw new NotImplementedException ();
+			if (_parent != null)
+				return _parent.GetReflectionType (objectType, instance);
+
+			return objectType;
 		}
 
-		[MonoTODO]
-		public ICustomTypeDescriptor GetTypeDescriptor (Type objectType)
+		
+		public ICustomTypeDescriptor GetTypeDescriptor (object instance)
 		{
-			throw new NotImplementedException ();
+			if (instance == null)
+				throw new ArgumentNullException ("instance");
+
+			return GetTypeDescriptor (instance.GetType (), instance);
 		}
 
-		[MonoTODO]
-		public ICustomTypeDescriptor GetTypeDescriptor (object instance)
+		
+		public ICustomTypeDescriptor GetTypeDescriptor (Type objectType)
 		{
-			throw new NotImplementedException ();
+			return GetTypeDescriptor (objectType, null);
 		}
 
-		[MonoTODO]
+		
 		public virtual ICustomTypeDescriptor GetTypeDescriptor (Type objectType, object instance)
 		{
-			throw new NotImplementedException ();
+			if (_parent != null)
+				_parent.GetTypeDescriptor (objectType, instance);
+
+			if (_emptyCustomTypeDescriptor == null)
+				_emptyCustomTypeDescriptor = new EmptyCustomTypeDescriptor ();
+			
+			return _emptyCustomTypeDescriptor;
 		}
+
 	}
+
 }
 
 #endif

+ 19 - 21
mcs/class/System/System.ComponentModel/TypeDescriptionProviderAttribute.cs

@@ -1,11 +1,10 @@
 //
-// TypeDescriptionProviderAttribute.cs
+// System.ComponentModel.TypeDescriptionProviderAttribute
 //
-// Author:
-//	Atsushi Enomoto  <[email protected]>
-//
-// Copyright (C) 2007 Novell, Inc. http://www.novell.com
+// Authors:		
+//		Ivan N. Zlatev (contact i-nZ.net)
 //
+// (C) 2007 Ivan N. Zlatev
 
 //
 // Permission is hereby granted, free of charge, to any person obtaining
@@ -30,35 +29,34 @@
 
 #if NET_2_0
 
-using System;
-
 namespace System.ComponentModel
 {
-	[AttributeUsage (AttributeTargets.Class)]
+	[AttributeUsage(AttributeTargets.Class, Inherited=true)]
 	public sealed class TypeDescriptionProviderAttribute : Attribute
 	{
-		string type;
+		private string typeName;
+
+		public string TypeName { 
+			get { return this.typeName; }
+		}
 
-		[MonoTODO]
 		public TypeDescriptionProviderAttribute (string typeName)
 		{
 			if (typeName == null)
-				throw new ArgumentNullException ("typeName");
-			type = typeName;
-		}
+				throw new System.ArgumentNullException ("typeName");
 
-		[MonoTODO]
+			this.typeName = typeName;
+		}
+		
 		public TypeDescriptionProviderAttribute (Type type)
 		{
-			if (type== null)
-				throw new ArgumentNullException ("type");
-			this.type = type.AssemblyQualifiedName;
-		}
+			if (type == null)
+				throw new System.ArgumentNullException ("type");
 
-		public string TypeName {
-			get { return type; }
+			this.typeName = type.AssemblyQualifiedName;
 		}
+		
 	}
-}
 
+}
 #endif

+ 18 - 2
mcs/class/System/System.ComponentModel/TypeDescriptor.cs

@@ -87,10 +87,26 @@ public sealed class TypeDescriptor
 		throw new NotImplementedException ();
 	}
 
-	[MonoNotSupported("")]
+	[MonoTODO]
 	public static object CreateInstance (IServiceProvider provider, Type objectType, Type [] argTypes, object [] args)
 	{
-		throw new NotImplementedException ();
+		if (objectType == null)
+			throw new ArgumentNullException ("objectType");
+
+		object instance = null;
+
+		if (provider != null) {
+			TypeDescriptionProvider typeDescrProvider = provider.GetService (typeof (TypeDescriptionProvider)) as TypeDescriptionProvider;
+			if (typeDescrProvider != null)
+				instance = typeDescrProvider.CreateInstance (provider, objectType, argTypes, args);
+		}
+
+		// TODO: also search and use the internal providers table once Add/RemoveProvider have been implemented
+
+		if (instance == null)
+			instance = Activator.CreateInstance (objectType, args);
+
+		return instance;
 	}
 #endif