// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
-using System;
using System.Collections;
using System.Reflection;
using System.Globalization;
using System.ComponentModel.Design;
+using System.Security.Permissions;
namespace System.ComponentModel
{
return null;
}
+ [ReflectionPermission (SecurityAction.LinkDemand, TypeInformation = true, MemberAccess = true)]
public static EventDescriptor CreateEvent (Type componentType,
string name,
Type type,
return new ReflectionEventDescriptor (componentType, name, type, attributes);
}
+ [ReflectionPermission (SecurityAction.LinkDemand, TypeInformation = true, MemberAccess = true)]
public static EventDescriptor CreateEvent (Type componentType,
EventDescriptor oldEventDescriptor,
Attribute [] attributes)
return new ReflectionEventDescriptor (componentType, oldEventDescriptor, attributes);
}
+ [ReflectionPermission (SecurityAction.LinkDemand, TypeInformation = true, MemberAccess = true)]
public static PropertyDescriptor CreateProperty (Type componentType,
string name,
Type type,
return new ReflectionPropertyDescriptor (componentType, name, type, attributes);
}
+ [ReflectionPermission (SecurityAction.LinkDemand, TypeInformation = true, MemberAccess = true)]
public static PropertyDescriptor CreateProperty (Type componentType,
PropertyDescriptor oldPropertyDescriptor,
Attribute [] attributes)
return ((ICustomTypeDescriptor) component).GetAttributes ();
} else {
IComponent com = component as IComponent;
- if (com != null)
+ if (com != null && com.Site != null)
return GetComponentInfo (com).GetAttributes ();
else
return GetTypeInfo (component.GetType()).GetAttributes ();
throw new ArgumentNullException ("component", "component cannot be null");
if (noCustomTypeDesc == false && component is ICustomTypeDescriptor) {
- return ((ICustomTypeDescriptor) component).GetClassName ();
+ String res = ((ICustomTypeDescriptor) component).GetClassName ();
+ if (res == null)
+ res = ((ICustomTypeDescriptor) component).GetComponentName ();
+ if (res == null)
+ res = component.GetType ().FullName;
+ return res;
} else {
return component.GetType ().FullName;
}
#if NET_2_0
return null;
#else
-
-#endif
return component.GetType().Name;
+#endif
}
}
public static TypeConverter GetConverter (object component)
{
- return GetConverter (component.GetType ());
+ return GetConverter (component, false);
}
public static TypeConverter GetConverter (object component, bool noCustomTypeDesc)
return ((ICustomTypeDescriptor) component).GetDefaultEvent ();
else {
IComponent com = component as IComponent;
- if (com != null)
+ if (com != null && com.Site != null)
return GetComponentInfo (com).GetDefaultEvent ();
else
return GetTypeInfo (component.GetType()).GetDefaultEvent ();
return ((ICustomTypeDescriptor) component).GetDefaultProperty ();
else {
IComponent com = component as IComponent;
- if (com != null)
+ if (com != null && com.Site != null)
return GetComponentInfo (com).GetDefaultProperty ();
else
return GetTypeInfo (component.GetType()).GetDefaultProperty ();
return GetEditor (component, editorBaseType, false);
}
- [MonoTODO]
public static object GetEditor (object component, Type editorBaseType, bool noCustomTypeDesc)
{
- throw new NotImplementedException ();
+ if (component == null)
+ throw new ArgumentNullException ("component");
+ if (editorBaseType == null)
+ throw new ArgumentNullException ("editorBaseType");
+
+ if (!noCustomTypeDesc && (component is ICustomTypeDescriptor))
+ return ((ICustomTypeDescriptor) component).GetEditor (editorBaseType);
+
+ object [] atts = component.GetType ().GetCustomAttributes (typeof (EditorAttribute), true);
+ if (atts.Length == 0)
+ return null;
+ string target = editorBaseType.AssemblyQualifiedName;
+
+ foreach (EditorAttribute ea in atts){
+ if (ea.EditorBaseTypeName == target){
+ Type t = Type.GetType (ea.EditorTypeName, true);
+
+ return Activator.CreateInstance (t);
+ }
+ }
+ return null;
}
public static EventDescriptorCollection GetEvents (object component)
public static EventDescriptorCollection GetEvents (object component, bool noCustomTypeDesc)
{
- return GetEvents (component, null, noCustomTypeDesc);
+ if (!noCustomTypeDesc && (component is ICustomTypeDescriptor))
+ return ((ICustomTypeDescriptor) component).GetEvents ();
+ else {
+ IComponent com = component as IComponent;
+ if (com != null && com.Site != null)
+ return GetComponentInfo (com).GetEvents ();
+ else
+ return GetTypeInfo (component.GetType()).GetEvents ();
+ }
}
public static EventDescriptorCollection GetEvents (Type componentType, Attribute [] attributes)
return ((ICustomTypeDescriptor) component).GetEvents (attributes);
else {
IComponent com = component as IComponent;
- if (com != null)
+ if (com != null && com.Site != null)
return GetComponentInfo (com).GetEvents (attributes);
else
return GetTypeInfo (component.GetType()).GetEvents (attributes);
public static PropertyDescriptorCollection GetProperties (object component, Attribute [] attributes, bool noCustomTypeDesc)
{
if (component == null)
- throw new ArgumentNullException ("component");
+ return PropertyDescriptorCollection.Empty;
if (!noCustomTypeDesc && (component is ICustomTypeDescriptor))
return ((ICustomTypeDescriptor) component).GetProperties (attributes);
else {
IComponent com = component as IComponent;
- if (com != null)
+ if (com != null && com.Site != null)
return GetComponentInfo (com).GetProperties (attributes);
else
return GetTypeInfo (component.GetType()).GetProperties (attributes);
public static PropertyDescriptorCollection GetProperties (object component, bool noCustomTypeDesc)
{
- return GetProperties (component, null, noCustomTypeDesc);
+ if (component == null)
+ return PropertyDescriptorCollection.Empty;
+
+ if (!noCustomTypeDesc && (component is ICustomTypeDescriptor))
+ return ((ICustomTypeDescriptor) component).GetProperties ();
+ else {
+ IComponent com = component as IComponent;
+ if (com != null && com.Site != null)
+ return GetComponentInfo (com).GetProperties ();
+ else
+ return GetTypeInfo (component.GetType()).GetProperties ();
+ }
}
public static PropertyDescriptorCollection GetProperties (Type componentType, Attribute [] attributes)
}
public static IComNativeDescriptorHandler ComNativeDescriptorHandler {
+ [PermissionSet (SecurityAction.LinkDemand, Unrestricted = true)]
get { return descriptorHandler; }
+ [PermissionSet (SecurityAction.LinkDemand, Unrestricted = true)]
set { descriptorHandler = value; }
}
{
if (component != null && component.Site != null) {
ITypeResolutionService resver = (ITypeResolutionService) component.Site.GetService (typeof(ITypeResolutionService));
- if (resver != null) return resver.GetType (typeName, true, false);
+ if (resver != null)
+ return resver.GetType (typeName, true, false);
}
Type t = Type.GetType (typeName);
public EventDescriptorCollection GetEvents (Attribute[] attributes)
{
EventDescriptorCollection evs = GetEvents ();
- if (attributes == null) return evs;
- else return evs.Filter (attributes);
+ if (attributes == null)
+ return evs;
+ else
+ return evs.Filter (attributes);
}
public PropertyDescriptorCollection GetProperties (Attribute[] attributes)
{
PropertyDescriptorCollection props = GetProperties ();
- if (attributes == null) return props;
- else return props.Filter (attributes);
+ if (attributes == null)
+ return props;
+ else
+ return props.Filter (attributes);
}
public EventDescriptor GetDefaultEvent ()
{
- if (_gotDefaultEvent) return _defaultEvent;
+ if (_gotDefaultEvent)
+ return _defaultEvent;
DefaultEventAttribute attr = (DefaultEventAttribute) GetAttributes()[typeof(DefaultEventAttribute)];
if (attr == null || attr.Name == null)
public PropertyDescriptor GetDefaultProperty ()
{
- if (_gotDefaultProperty) return _defaultProperty;
+ if (_gotDefaultProperty)
+ return _defaultProperty;
DefaultPropertyAttribute attr = (DefaultPropertyAttribute) GetAttributes()[typeof(DefaultPropertyAttribute)];
if (attr == null || attr.Name == null)
protected AttributeCollection GetAttributes (IComponent comp)
{
- if (_attributes != null) return _attributes;
+ if (_attributes != null)
+ return _attributes;
bool cache = true;
object[] ats = _infoType.GetCustomAttributes (true);
Hashtable t = new Hashtable ();
- foreach (Attribute at in ats)
- t [at.TypeId] = at;
+
+ // Filter the custom attributes, so that only the top
+ // level of the same type are left.
+ //
+ for (int i = ats.Length -1; i >= 0; i--) {
+ t [((Attribute) ats[i]).TypeId] = ats[i];
+ }
if (comp != null && comp.Site != null)
{
ArrayList atts = new ArrayList ();
atts.AddRange (t.Values);
AttributeCollection attCol = new AttributeCollection (atts);
- if (cache) _attributes = attCol;
+ if (cache)
+ _attributes = attCol;
return attCol;
}
}
public override EventDescriptorCollection GetEvents ()
{
- if (_events != null) return _events;
+ if (_events != null)
+ return _events;
bool cache = true;
EventInfo[] events = _component.GetType().GetEvents ();
public override PropertyDescriptorCollection GetProperties ()
{
- if (_properties != null) return _properties;
+ if (_properties != null)
+ return _properties;
bool cache = true;
- PropertyInfo[] props = _component.GetType().GetProperties ();
+ PropertyInfo[] props = _component.GetType().GetProperties (BindingFlags.Instance | BindingFlags.Public);
Hashtable t = new Hashtable ();
foreach (PropertyInfo pr in props)
t [pr.Name] = new ReflectionPropertyDescriptor (pr);
ITypeDescriptorFilterService filter = (ITypeDescriptorFilterService) _component.Site.GetService (typeof(ITypeDescriptorFilterService));
cache = filter.FilterProperties (_component, t);
}
-
- ArrayList atts = new ArrayList ();
- atts.AddRange (t.Values);
- PropertyDescriptorCollection attCol = new PropertyDescriptorCollection (atts);
- if (cache) _properties = attCol;
+
+ PropertyDescriptor[] descriptors = new PropertyDescriptor[t.Values.Count];
+ t.Values.CopyTo (descriptors, 0);
+ PropertyDescriptorCollection attCol = new PropertyDescriptorCollection (descriptors, true);
+ if (cache)
+ _properties = attCol;
return attCol;
}
}
public override EventDescriptorCollection GetEvents ()
{
- if (_events != null) return _events;
+ if (_events != null)
+ return _events;
EventInfo[] events = InfoType.GetEvents ();
EventDescriptor[] descs = new EventDescriptor [events.Length];
public override PropertyDescriptorCollection GetProperties ()
{
- if (_properties != null) return _properties;
+ if (_properties != null)
+ return _properties;
- PropertyInfo[] props = InfoType.GetProperties ();
- PropertyDescriptor[] descs = new PropertyDescriptor [props.Length];
+ PropertyInfo[] props = InfoType.GetProperties (BindingFlags.Instance | BindingFlags.Public);
+ ArrayList descs = new ArrayList (props.Length);
for (int n=0; n<props.Length; n++)
- descs [n] = new ReflectionPropertyDescriptor (props[n]);
+ if (props [n].GetIndexParameters ().Length == 0)
+ descs.Add (new ReflectionPropertyDescriptor (props[n]));
- _properties = new PropertyDescriptorCollection (descs);
+ _properties = new PropertyDescriptorCollection ((PropertyDescriptor[]) descs.ToArray (typeof (PropertyDescriptor)), true);
return _properties;
}
}