Merge pull request #347 from JamesB7/master
[mono.git] / mcs / class / System / System.ComponentModel / TypeDescriptor.cs
index 35df4f0410e2b3420fa350183039717c37bd10b0..9ebeeddd36de23a063a04ab0e67a145d132ad6b0 100644 (file)
@@ -39,9 +39,7 @@ using System.Globalization;
 using System.ComponentModel.Design;
 using System.Security.Permissions;
 
-#if NET_2_0
 using System.Collections.Generic;
-#endif
 
 namespace System.ComponentModel
 {
@@ -55,7 +53,6 @@ public sealed class TypeDescriptor
        private static Hashtable typeTable = new Hashtable ();
        private static Hashtable editors;
 
-#if NET_2_0
        static object typeDescriptionProvidersLock = new object ();
        static Dictionary <Type, LinkedList <TypeDescriptionProvider>> typeDescriptionProviders;
 
@@ -67,18 +64,26 @@ public sealed class TypeDescriptor
                typeDescriptionProviders = new Dictionary <Type, LinkedList <TypeDescriptionProvider>> ();
                componentDescriptionProviders = new Dictionary <WeakObjectWrapper, LinkedList <TypeDescriptionProvider>> (new WeakObjectWrapperComparer ());
        }
-#endif
+
        private TypeDescriptor ()
        {
        }
 
-#if NET_2_0
        [MonoNotSupported ("Mono does not support COM")]
        [EditorBrowsable (EditorBrowsableState.Advanced)]
        public static Type ComObjectType {
                get { throw new NotImplementedException (); }
        }
 
+#if NET_4_0
+       [EditorBrowsable (EditorBrowsableState.Advanced)]
+       public static Type InterfaceType {
+               get {
+                       return typeof (TypeDescriptorInterface);
+               }
+       }
+#endif
+
        [EditorBrowsable (EditorBrowsableState.Advanced)]
        public static TypeDescriptionProvider AddAttributes (object instance, params Attribute [] attributes)
        {
@@ -151,6 +156,22 @@ public sealed class TypeDescriptor
                }
        }
 
+#if NET_4_0
+       [MonoLimitation ("Security not applied.")]
+       [EditorBrowsable (EditorBrowsableState.Advanced)]
+       public static void AddProviderTransparent (TypeDescriptionProvider provider, object instance)
+       {
+               AddProvider (provider, instance);
+       }
+
+       [MonoLimitation ("Security not applied.")]
+       [EditorBrowsable (EditorBrowsableState.Advanced)]
+       public static void AddProviderTransparent (TypeDescriptionProvider provider, Type type)
+       {
+               AddProvider (provider, type);
+       }
+#endif
+
        [MonoTODO]
        public static object CreateInstance (IServiceProvider provider, Type objectType, Type [] argTypes, object [] args)
        {
@@ -172,11 +193,8 @@ public sealed class TypeDescriptor
 
                return instance;
        }
-#endif
 
-#if NET_2_0
        [EditorBrowsable (EditorBrowsableState.Advanced)]
-#endif
 #if !NET_2_1
        public
 #else
@@ -258,9 +276,7 @@ public sealed class TypeDescriptor
                return GetAttributes (component, false);
        }
 
-#if NET_2_0
        [EditorBrowsable (EditorBrowsableState.Advanced)]
-#endif
        public static AttributeCollection GetAttributes (object component, bool noCustomTypeDesc)
        {
                if (component == null)
@@ -282,9 +298,7 @@ public sealed class TypeDescriptor
                return GetClassName (component, false);
        }
 
-#if NET_2_0
        [EditorBrowsable (EditorBrowsableState.Advanced)]
-#endif
        public static string GetClassName (object component, bool noCustomTypeDesc)
        {
                if (component == null)
@@ -307,9 +321,7 @@ public sealed class TypeDescriptor
                return GetComponentName (component, false);
        }
 
-#if NET_2_0
        [EditorBrowsable (EditorBrowsableState.Advanced)]
-#endif
        public static string GetComponentName (object component, bool noCustomTypeDesc)
        {
                if (component == null)
@@ -321,15 +333,10 @@ public sealed class TypeDescriptor
                        IComponent c = component as IComponent;
                        if (c != null && c.Site != null)
                                return c.Site.Name;
-#if NET_2_0
                        return null;
-#else
-                       return component.GetType().Name;
-#endif
                }
        }
 
-#if NET_2_0
        [MonoNotSupported("")]
        public static string GetFullComponentName (object component)
        {
@@ -341,16 +348,13 @@ public sealed class TypeDescriptor
        {
                throw new NotImplementedException ();
        }
-#endif
 
        public static TypeConverter GetConverter (object component)
        {
                return GetConverter (component, false);
        }
 
-#if NET_2_0
        [EditorBrowsable (EditorBrowsableState.Advanced)]
-#endif
        public static TypeConverter GetConverter (object component, bool noCustomTypeDesc)
        {
                if (component == null)
@@ -442,10 +446,8 @@ public sealed class TypeDescriptor
        {
                Type converterType = null;
                if (type != null) {
-#if NET_2_0
                        if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>))
                                return typeof(NullableConverter);
-#endif
                        // Is there a default converter
                        foreach (DictionaryEntry entry in DefaultConverters) {
                                if ((Type)entry.Key == type)
@@ -486,9 +488,7 @@ public sealed class TypeDescriptor
                return GetDefaultEvent (component, false);
        }
 
-#if NET_2_0
        [EditorBrowsable (EditorBrowsableState.Advanced)]
-#endif
        public static EventDescriptor GetDefaultEvent (object component, bool noCustomTypeDesc)
        {
                if (!noCustomTypeDesc && (component is ICustomTypeDescriptor))
@@ -512,9 +512,7 @@ public sealed class TypeDescriptor
                return GetDefaultProperty (component, false);
        }
 
-#if NET_2_0
        [EditorBrowsable (EditorBrowsableState.Advanced)]
-#endif
        public static PropertyDescriptor GetDefaultProperty (object component, bool noCustomTypeDesc)
        {
                if (!noCustomTypeDesc && (component is ICustomTypeDescriptor))
@@ -620,9 +618,7 @@ public sealed class TypeDescriptor
                return GetEditor (component, editorBaseType, false);
        }
 
-#if NET_2_0
        [EditorBrowsable (EditorBrowsableState.Advanced)]
-#endif
        public static object GetEditor (object component, Type editorBaseType, bool noCustomTypeDesc)
        {
                if (component == null)
@@ -663,9 +659,7 @@ public sealed class TypeDescriptor
                return GetEvents (component, attributes, false);
        }
 
-#if NET_2_0
        [EditorBrowsable (EditorBrowsableState.Advanced)]
-#endif
        public static EventDescriptorCollection GetEvents (object component, bool noCustomTypeDesc)
        {
                if (!noCustomTypeDesc && (component is ICustomTypeDescriptor))
@@ -684,9 +678,7 @@ public sealed class TypeDescriptor
                return GetTypeInfo (componentType).GetEvents (attributes);
        }
 
-#if NET_2_0
        [EditorBrowsable (EditorBrowsableState.Advanced)]
-#endif
        public static EventDescriptorCollection GetEvents (object component, Attribute [] attributes, bool noCustomTypeDesc)
        {
                if (!noCustomTypeDesc && (component is ICustomTypeDescriptor))
@@ -731,9 +723,7 @@ public sealed class TypeDescriptor
                }
        }
 
-#if NET_2_0
        [EditorBrowsable (EditorBrowsableState.Advanced)]
-#endif
        public static PropertyDescriptorCollection GetProperties (object component, bool noCustomTypeDesc)
        {
                if (component == null)
@@ -755,7 +745,6 @@ public sealed class TypeDescriptor
                return GetTypeInfo (componentType).GetProperties (attributes);
        }
 
-#if NET_2_0
        [EditorBrowsable (EditorBrowsableState.Advanced)]
        public static TypeDescriptionProvider GetProvider (object instance)
        {
@@ -902,6 +891,22 @@ public sealed class TypeDescriptor
                        refreshed (new RefreshEventArgs (type));
        }
 
+#if NET_4_0
+       [MonoLimitation ("Security not applied.")]
+       [EditorBrowsable (EditorBrowsableState.Advanced)]
+       public static void RemoveProviderTransparent (TypeDescriptionProvider provider, object instance)
+       {
+               RemoveProvider (provider, instance);
+       }
+
+       [MonoLimitation ("Security not applied.")]
+       [EditorBrowsable (EditorBrowsableState.Advanced)]
+       public static void RemoveProviderTransparent (TypeDescriptionProvider provider, Type type)
+       {
+               RemoveProvider (provider, type);
+       }
+#endif
+
        static void RemoveProvider (TypeDescriptionProvider provider, LinkedList <TypeDescriptionProvider> plist)
        {
                LinkedListNode <TypeDescriptionProvider> node = plist.Last;
@@ -921,7 +926,6 @@ public sealed class TypeDescriptor
                                        
                } while (true);
        }
-#endif
 
        public static void SortDescriptorArray (IList infos)
        {
@@ -937,10 +941,8 @@ public sealed class TypeDescriptor
                        infos.Add (ob);
        }
 
-#if NET_2_0
        // well, ComObjectType is not implemented, but we don't support COM anyways ...
        [Obsolete ("Use ComObjectType")]
-#endif
        public static IComNativeDescriptorHandler ComNativeDescriptorHandler {
                [PermissionSet (SecurityAction.LinkDemand, Unrestricted = true)]
                get { return descriptorHandler; }
@@ -1032,7 +1034,6 @@ public sealed class TypeDescriptor
                return type;
        }
 
-#if NET_2_0
        sealed class AttributeProvider : TypeDescriptionProvider
        {
                Attribute[] attributes;
@@ -1226,7 +1227,6 @@ public sealed class TypeDescriptor
                        return new DefaultTypeDescriptor (this, objectType, instance);
                }
        }
-#endif
 }
 
        internal abstract class Info
@@ -1281,19 +1281,6 @@ public sealed class TypeDescriptor
                        else {
                                EventDescriptorCollection events = GetEvents ();
                                _defaultEvent = events [attr.Name];
-#if !NET_2_0
-                               // In our test case (TypeDescriptorTest.TestGetDefaultEvent), we have
-                               // a scenario where a custom filter adds the DefaultEventAttribute,
-                               // but its FilterEvents method removes the event the
-                               // DefaultEventAttribute applied to.  .NET 1.x accepts this and returns
-                               // the *other* event defined in the class.
-                               //
-                               // Consequently, we know we have a DefaultEvent, but we need to check
-                               // and ensure that the requested event is unfiltered.  If it is, just
-                               // grab the first element in the collection.
-                               if (_defaultEvent == null && events.Count > 0)
-                                       _defaultEvent = events [0];
-#endif
                        }
                        _gotDefaultEvent = true;
                        return _defaultEvent;
@@ -1491,4 +1478,13 @@ public sealed class TypeDescriptor
                        return _properties;
                }
        }
+
+#if NET_4_0
+       // In .net this class seems to be a dummy and empty class
+       // used to represent internally any extender provider associated with
+       // all the interfaces.
+       sealed class TypeDescriptorInterface
+       {
+       }
+#endif
 }