5 // Miguel de Icaza (miguel@ximian.com)
7 // (C) Ximian, Inc. http://www.ximian.com
11 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
13 // Permission is hereby granted, free of charge, to any person obtaining
14 // a copy of this software and associated documentation files (the
15 // "Software"), to deal in the Software without restriction, including
16 // without limitation the rights to use, copy, modify, merge, publish,
17 // distribute, sublicense, and/or sell copies of the Software, and to
18 // permit persons to whom the Software is furnished to do so, subject to
19 // the following conditions:
21 // The above copyright notice and this permission notice shall be
22 // included in all copies or substantial portions of the Software.
24 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
28 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
29 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
30 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
33 using System.Diagnostics;
34 using System.Reflection;
35 using System.Reflection.Emit;
36 using System.Collections;
37 using System.Runtime.InteropServices;
38 using System.Runtime.CompilerServices;
39 using System.Globalization;
44 [ClassInterface (ClassInterfaceType.None)]
47 [ComDefaultInterface (typeof (_Type))]
49 public abstract class Type : MemberInfo, IReflect, _Type, _MemberInfo {
51 internal RuntimeTypeHandle _impl;
53 public static readonly char Delimiter = '.';
54 public static readonly Type[] EmptyTypes = {};
55 public static readonly MemberFilter FilterAttribute = new MemberFilter (FilterAttribute_impl);
56 public static readonly MemberFilter FilterName = new MemberFilter (FilterName_impl);
57 public static readonly MemberFilter FilterNameIgnoreCase = new MemberFilter (FilterNameIgnoreCase_impl);
58 public static readonly object Missing;
60 internal const BindingFlags DefaultBindingFlags =
61 BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance;
63 /* implementation of the delegates for MemberFilter */
64 static bool FilterName_impl (MemberInfo m, object filterCriteria)
66 string name = (string) filterCriteria;
67 if (name == null || name.Length == 0 )
68 return false; // because m.Name cannot be null or empty
70 if (name [name.Length-1] == '*')
71 return string.Compare (name, 0, m.Name, 0, name.Length-1, false, CultureInfo.InvariantCulture) == 0;
73 return name.Equals (m.Name);
76 static bool FilterNameIgnoreCase_impl (MemberInfo m, object filterCriteria)
78 string name = (string) filterCriteria;
79 if (name == null || name.Length == 0 )
80 return false; // because m.Name cannot be null or empty
82 if (name [name.Length-1] == '*')
83 return string.Compare (name, 0, m.Name, 0, name.Length-1, true, CultureInfo.InvariantCulture) == 0;
85 return String.Compare (name, m.Name, true, CultureInfo.InvariantCulture) == 0;
88 static bool FilterAttribute_impl (MemberInfo m, object filterCriteria)
90 int flags = ((IConvertible)filterCriteria).ToInt32 (null);
92 return ((int)((MethodInfo)m).Attributes & flags) != 0;
94 return ((int)((FieldInfo)m).Attributes & flags) != 0;
95 if (m is PropertyInfo)
96 return ((int)((PropertyInfo)m).Attributes & flags) != 0;
98 return ((int)((EventInfo)m).Attributes & flags) != 0;
107 /// The assembly where the type is defined.
109 public abstract Assembly Assembly {
114 /// Gets the fully qualified name for the type including the
115 /// assembly name where the type is defined.
117 public abstract string AssemblyQualifiedName {
122 /// Returns the Attributes associated with the type.
124 public TypeAttributes Attributes {
126 return GetAttributeFlagsImpl ();
131 /// Returns the basetype for this type
133 public abstract Type BaseType {
138 /// Returns the class that declares the member.
140 public override Type DeclaringType {
149 public static Binder DefaultBinder {
151 return Binder.DefaultBinder;
156 /// The full name of the type including its namespace
158 public abstract string FullName {
162 public abstract Guid GUID {
166 public bool HasElementType {
168 return HasElementTypeImpl ();
172 public bool IsAbstract {
174 return (Attributes & TypeAttributes.Abstract) != 0;
178 public bool IsAnsiClass {
180 return (Attributes & TypeAttributes.StringFormatMask)
181 == TypeAttributes.AnsiClass;
185 public bool IsArray {
187 return IsArrayImpl ();
191 public bool IsAutoClass {
193 return (Attributes & TypeAttributes.StringFormatMask) == TypeAttributes.AutoClass;
197 public bool IsAutoLayout {
199 return (Attributes & TypeAttributes.LayoutMask) == TypeAttributes.AutoLayout;
203 public bool IsByRef {
205 return IsByRefImpl ();
209 public bool IsClass {
214 return !IsSubclassOf (typeof (ValueType));
218 public bool IsCOMObject {
220 return IsCOMObjectImpl ();
224 public bool IsContextful {
226 return IsContextfulImpl ();
232 return IsSubclassOf (typeof (Enum));
236 public bool IsExplicitLayout {
238 return (Attributes & TypeAttributes.LayoutMask) == TypeAttributes.ExplicitLayout;
242 public bool IsImport {
244 return (Attributes & TypeAttributes.Import) != 0;
248 public bool IsInterface {
250 return (Attributes & TypeAttributes.ClassSemanticsMask) == TypeAttributes.Interface;
254 public bool IsLayoutSequential {
256 return (Attributes & TypeAttributes.LayoutMask) == TypeAttributes.SequentialLayout;
260 public bool IsMarshalByRef {
262 return IsMarshalByRefImpl ();
266 public bool IsNestedAssembly {
268 return (Attributes & TypeAttributes.VisibilityMask) == TypeAttributes.NestedAssembly;
272 public bool IsNestedFamANDAssem {
274 return (Attributes & TypeAttributes.VisibilityMask) == TypeAttributes.NestedFamANDAssem;
278 public bool IsNestedFamily {
280 return (Attributes & TypeAttributes.VisibilityMask) == TypeAttributes.NestedFamily;
284 public bool IsNestedFamORAssem {
286 return (Attributes & TypeAttributes.VisibilityMask) == TypeAttributes.NestedFamORAssem;
290 public bool IsNestedPrivate {
292 return (Attributes & TypeAttributes.VisibilityMask) == TypeAttributes.NestedPrivate;
296 public bool IsNestedPublic {
298 return (Attributes & TypeAttributes.VisibilityMask) == TypeAttributes.NestedPublic;
302 public bool IsNotPublic {
304 return (Attributes & TypeAttributes.VisibilityMask) == TypeAttributes.NotPublic;
308 public bool IsPointer {
310 return IsPointerImpl ();
314 public bool IsPrimitive {
316 return IsPrimitiveImpl ();
320 public bool IsPublic {
322 return (Attributes & TypeAttributes.VisibilityMask) == TypeAttributes.Public;
326 public bool IsSealed {
328 return (Attributes & TypeAttributes.Sealed) != 0;
332 public bool IsSerializable {
334 if ((Attributes & TypeAttributes.Serializable) != 0)
337 // Enums and delegates are always serializable
339 Type type = UnderlyingSystemType;
343 // Fast check for system types
344 if (type.IsSystemType)
345 return type_is_subtype_of (type, typeof (Enum), false) || type_is_subtype_of (type, typeof (Delegate), false);
347 // User defined types depend on this behavior
349 if ((type == typeof (Enum)) || (type == typeof (Delegate)))
352 type = type.BaseType;
353 } while (type != null);
359 public bool IsSpecialName {
361 return (Attributes & TypeAttributes.SpecialName) != 0;
365 public bool IsUnicodeClass {
367 return (Attributes & TypeAttributes.StringFormatMask) == TypeAttributes.UnicodeClass;
371 public bool IsValueType {
373 return IsValueTypeImpl ();
377 public override MemberTypes MemberType {
378 get {return MemberTypes.TypeInfo;}
381 #if NET_2_0 || BOOTSTRAP_NET_2_0
384 public abstract Module Module {get;}
386 public abstract string Namespace {get;}
388 public override Type ReflectedType {
395 public virtual RuntimeTypeHandle TypeHandle {
396 get { return default (RuntimeTypeHandle); }
399 public abstract RuntimeTypeHandle TypeHandle {get;}
405 public ConstructorInfo TypeInitializer {
407 return GetConstructorImpl (
408 BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static,
410 CallingConventions.Any,
416 public abstract Type UnderlyingSystemType {get;}
418 public override bool Equals (object o)
423 Type cmp = o as Type;
429 public bool Equals (Type type) {
432 return UnderlyingSystemType.EqualsInternal (type.UnderlyingSystemType);
435 [MethodImplAttribute(MethodImplOptions.InternalCall)]
436 internal extern bool EqualsInternal (Type type);
438 [MethodImplAttribute(MethodImplOptions.InternalCall)]
439 private static extern Type internal_from_handle (IntPtr handle);
441 [MethodImplAttribute(MethodImplOptions.InternalCall)]
442 private static extern Type internal_from_name (string name, bool throwOnError, bool ignoreCase);
444 public static Type GetType(string typeName)
446 if (typeName == null)
447 throw new ArgumentNullException ("typeName");
449 return internal_from_name (typeName, false, false);
452 public static Type GetType(string typeName, bool throwOnError)
454 if (typeName == null)
455 throw new ArgumentNullException ("typeName");
457 Type type = internal_from_name (typeName, throwOnError, false);
458 if (throwOnError && type == null)
459 throw new TypeLoadException ("Error loading '" + typeName + "'");
464 public static Type GetType(string typeName, bool throwOnError, bool ignoreCase)
466 if (typeName == null)
467 throw new ArgumentNullException ("typeName");
469 Type t = internal_from_name (typeName, throwOnError, ignoreCase);
470 if (throwOnError && t == null)
471 throw new TypeLoadException ("Error loading '" + typeName + "'");
476 public static Type[] GetTypeArray (object[] args) {
478 throw new ArgumentNullException ("args");
481 ret = new Type [args.Length];
482 for (int i = 0; i < args.Length; ++i)
483 ret [i] = args[i].GetType ();
487 [MethodImplAttribute(MethodImplOptions.InternalCall)]
488 internal extern static TypeCode GetTypeCodeInternal (Type type);
490 public static TypeCode GetTypeCode (Type type) {
491 if (type is MonoType)
492 return GetTypeCodeInternal (type);
494 /* MS.NET returns this */
495 return TypeCode.Empty;
497 type = type.UnderlyingSystemType;
499 if (!type.IsSystemType)
500 return TypeCode.Object;
502 return GetTypeCodeInternal (type);
505 [MonoTODO("Mono does not support COM")]
506 public static Type GetTypeFromCLSID (Guid clsid)
508 throw new NotImplementedException ();
511 [MonoTODO("Mono does not support COM")]
512 public static Type GetTypeFromCLSID (Guid clsid, bool throwOnError)
514 throw new NotImplementedException ();
517 [MonoTODO("Mono does not support COM")]
518 public static Type GetTypeFromCLSID (Guid clsid, string server)
520 throw new NotImplementedException ();
523 [MonoTODO("Mono does not support COM")]
524 public static Type GetTypeFromCLSID (Guid clsid, string server, bool throwOnError)
526 throw new NotImplementedException ();
529 public static Type GetTypeFromHandle (RuntimeTypeHandle handle)
531 return internal_from_handle (handle.Value);
534 [MonoTODO("Mono does not support COM")]
535 public static Type GetTypeFromProgID (string progID)
537 throw new NotImplementedException ();
540 [MonoTODO("Mono does not support COM")]
541 public static Type GetTypeFromProgID (string progID, bool throwOnError)
543 throw new NotImplementedException ();
546 [MonoTODO("Mono does not support COM")]
547 public static Type GetTypeFromProgID (string progID, string server)
549 throw new NotImplementedException ();
552 [MonoTODO("Mono does not support COM")]
553 public static Type GetTypeFromProgID (string progID, string server, bool throwOnError)
555 throw new NotImplementedException ();
558 public static RuntimeTypeHandle GetTypeHandle (object o)
560 return o.GetType().TypeHandle;
563 [MethodImplAttribute(MethodImplOptions.InternalCall)]
564 internal static extern bool type_is_subtype_of (Type a, Type b, bool check_interfaces);
566 [MethodImplAttribute(MethodImplOptions.InternalCall)]
567 internal static extern bool type_is_assignable_from (Type a, Type b);
569 public new Type GetType ()
571 return base.GetType ();
577 public virtual bool IsSubclassOf (Type c)
579 if (c == null || c == this)
582 // Fast check for system types
584 return c.IsSystemType && type_is_subtype_of (this, c, false);
586 // User defined types depend on this behavior
587 for (Type type = BaseType; type != null; type = type.BaseType)
594 public virtual Type[] FindInterfaces (TypeFilter filter, object filterCriteria)
597 throw new ArgumentNullException ("filter");
599 ArrayList ifaces = new ArrayList ();
600 foreach (Type iface in GetInterfaces ()) {
601 if (filter (iface, filterCriteria))
605 return (Type []) ifaces.ToArray (typeof (Type));
608 public Type GetInterface (string name) {
609 return GetInterface (name, false);
612 public abstract Type GetInterface (string name, bool ignoreCase);
614 [MethodImplAttribute(MethodImplOptions.InternalCall)]
615 internal static extern void GetInterfaceMapData (Type t, Type iface, out MethodInfo[] targets, out MethodInfo[] methods);
620 public virtual InterfaceMapping GetInterfaceMap (Type interfaceType) {
621 InterfaceMapping res;
622 if (interfaceType == null)
623 throw new ArgumentNullException ("interfaceType");
624 if (!interfaceType.IsInterface)
625 throw new ArgumentException (Locale.GetText ("Argument must be an interface."), "interfaceType");
626 res.TargetType = this;
627 res.InterfaceType = interfaceType;
628 GetInterfaceMapData (this, interfaceType, out res.TargetMethods, out res.InterfaceMethods);
629 if (res.TargetMethods == null)
630 throw new ArgumentException (Locale.GetText ("Interface not found"), "interfaceType");
635 public abstract Type[] GetInterfaces ();
637 public virtual bool IsAssignableFrom (Type c)
645 if (c is TypeBuilder)
646 return ((TypeBuilder)c).IsAssignableTo (this);
648 /* Handle user defined type classes */
650 Type systemType = UnderlyingSystemType;
651 if (!systemType.IsSystemType)
653 return systemType.IsAssignableFrom (c);
656 if (!c.IsSystemType) {
657 Type underlyingType = c.UnderlyingSystemType;
658 if (!underlyingType.IsSystemType)
660 return IsAssignableFrom (underlyingType);
663 return type_is_assignable_from (this, c);
666 [MethodImplAttribute(MethodImplOptions.InternalCall)]
667 public extern virtual bool IsInstanceOfType (object o);
669 public virtual int GetArrayRank ()
671 throw new NotSupportedException (); // according to MSDN
674 public abstract Type GetElementType ();
676 public EventInfo GetEvent (string name)
678 return GetEvent (name, DefaultBindingFlags);
681 public abstract EventInfo GetEvent (string name, BindingFlags bindingAttr);
683 public virtual EventInfo[] GetEvents ()
685 return GetEvents (DefaultBindingFlags);
688 public abstract EventInfo[] GetEvents (BindingFlags bindingAttr);
690 public FieldInfo GetField( string name)
692 return GetField (name, DefaultBindingFlags);
695 public abstract FieldInfo GetField( string name, BindingFlags bindingAttr);
697 public FieldInfo[] GetFields ()
699 return GetFields (DefaultBindingFlags);
702 public abstract FieldInfo[] GetFields (BindingFlags bindingAttr);
704 public override int GetHashCode()
706 return (int)_impl.Value;
709 public MemberInfo[] GetMember (string name)
711 return GetMember (name, DefaultBindingFlags);
714 public virtual MemberInfo[] GetMember (string name, BindingFlags bindingAttr)
716 return GetMember (name, MemberTypes.All, bindingAttr);
719 public virtual MemberInfo[] GetMember (string name, MemberTypes type, BindingFlags bindingAttr)
721 if ((bindingAttr & BindingFlags.IgnoreCase) != 0)
722 return FindMembers (type, bindingAttr, FilterNameIgnoreCase, name);
724 return FindMembers (type, bindingAttr, FilterName, name);
727 public MemberInfo[] GetMembers ()
729 return GetMembers (DefaultBindingFlags);
732 public abstract MemberInfo[] GetMembers (BindingFlags bindingAttr);
734 public MethodInfo GetMethod (string name)
737 throw new ArgumentNullException ("name");
738 return GetMethodImpl (name, DefaultBindingFlags, null, CallingConventions.Any, null, null);
741 public MethodInfo GetMethod (string name, BindingFlags bindingAttr)
744 throw new ArgumentNullException ("name");
746 return GetMethodImpl (name, bindingAttr, null, CallingConventions.Any, null, null);
749 public MethodInfo GetMethod (string name, Type[] types)
751 return GetMethod (name, DefaultBindingFlags, null, CallingConventions.Any, types, null);
754 public MethodInfo GetMethod (string name, Type[] types, ParameterModifier[] modifiers)
756 return GetMethod (name, DefaultBindingFlags, null, CallingConventions.Any, types, modifiers);
759 public MethodInfo GetMethod (string name, BindingFlags bindingAttr, Binder binder,
760 Type[] types, ParameterModifier[] modifiers)
763 return GetMethod (name, bindingAttr, binder, CallingConventions.Any, types, modifiers);
766 public MethodInfo GetMethod (string name, BindingFlags bindingAttr, Binder binder,
767 CallingConventions callConvention, Type[] types, ParameterModifier[] modifiers)
770 throw new ArgumentNullException ("name");
772 throw new ArgumentNullException ("types");
774 for (int i = 0; i < types.Length; i++)
775 if (types[i] == null)
776 throw new ArgumentNullException ("types");
778 return GetMethodImpl (name, bindingAttr, binder, callConvention, types, modifiers);
781 protected abstract MethodInfo GetMethodImpl (string name, BindingFlags bindingAttr, Binder binder,
782 CallingConventions callConvention, Type[] types,
783 ParameterModifier[] modifiers);
785 internal MethodInfo GetMethodImplInternal (string name, BindingFlags bindingAttr, Binder binder,
786 CallingConventions callConvention, Type[] types,
787 ParameterModifier[] modifiers)
789 return GetMethodImpl (name, bindingAttr, binder, callConvention, types, modifiers);
792 internal virtual MethodInfo GetMethod (MethodInfo fromNoninstanciated)
794 throw new System.InvalidOperationException ("can only be called in generic type");
797 internal virtual ConstructorInfo GetConstructor (ConstructorInfo fromNoninstanciated)
799 throw new System.InvalidOperationException ("can only be called in generic type");
802 internal virtual FieldInfo GetField (FieldInfo fromNoninstanciated)
804 throw new System.InvalidOperationException ("can only be called in generic type");
808 public MethodInfo[] GetMethods ()
810 return GetMethods (DefaultBindingFlags);
813 public abstract MethodInfo[] GetMethods (BindingFlags bindingAttr);
815 public Type GetNestedType (string name)
817 return GetNestedType (name, DefaultBindingFlags);
820 public abstract Type GetNestedType (string name, BindingFlags bindingAttr);
822 public Type[] GetNestedTypes ()
824 return GetNestedTypes (DefaultBindingFlags);
827 public abstract Type[] GetNestedTypes (BindingFlags bindingAttr);
830 public PropertyInfo[] GetProperties ()
832 return GetProperties (DefaultBindingFlags);
835 public abstract PropertyInfo[] GetProperties (BindingFlags bindingAttr);
838 public PropertyInfo GetProperty (string name)
841 throw new ArgumentNullException ("name");
843 return GetPropertyImpl (name, DefaultBindingFlags, null, null, null, null);
846 public PropertyInfo GetProperty (string name, BindingFlags bindingAttr)
849 throw new ArgumentNullException ("name");
850 return GetPropertyImpl (name, bindingAttr, null, null, null, null);
853 public PropertyInfo GetProperty (string name, Type returnType)
856 throw new ArgumentNullException ("name");
857 return GetPropertyImpl (name, DefaultBindingFlags, null, returnType, null, null);
860 public PropertyInfo GetProperty (string name, Type[] types)
862 return GetProperty (name, DefaultBindingFlags, null, null, types, null);
865 public PropertyInfo GetProperty (string name, Type returnType, Type[] types)
867 return GetProperty (name, DefaultBindingFlags, null, returnType, types, null);
870 public PropertyInfo GetProperty( string name, Type returnType, Type[] types, ParameterModifier[] modifiers)
872 return GetProperty (name, DefaultBindingFlags, null, returnType, types, modifiers);
875 public PropertyInfo GetProperty (string name, BindingFlags bindingAttr, Binder binder, Type returnType,
876 Type[] types, ParameterModifier[] modifiers)
879 throw new ArgumentNullException ("name");
881 throw new ArgumentNullException ("types");
883 foreach (Type t in types) {
885 throw new ArgumentNullException ("types");
888 return GetPropertyImpl (name, bindingAttr, binder, returnType, types, modifiers);
891 protected abstract PropertyInfo GetPropertyImpl (string name, BindingFlags bindingAttr, Binder binder,
892 Type returnType, Type[] types, ParameterModifier[] modifiers);
894 internal PropertyInfo GetPropertyImplInternal (string name, BindingFlags bindingAttr, Binder binder,
895 Type returnType, Type[] types, ParameterModifier[] modifiers)
897 return GetPropertyImpl (name, bindingAttr, binder, returnType, types, modifiers);
900 protected abstract ConstructorInfo GetConstructorImpl (BindingFlags bindingAttr,
902 CallingConventions callConvention,
904 ParameterModifier[] modifiers);
906 protected abstract TypeAttributes GetAttributeFlagsImpl ();
907 protected abstract bool HasElementTypeImpl ();
908 protected abstract bool IsArrayImpl ();
909 protected abstract bool IsByRefImpl ();
910 protected abstract bool IsCOMObjectImpl ();
911 protected abstract bool IsPointerImpl ();
912 protected abstract bool IsPrimitiveImpl ();
914 [MethodImplAttribute(MethodImplOptions.InternalCall)]
915 internal static extern bool IsArrayImpl (Type type);
917 protected virtual bool IsValueTypeImpl ()
919 if (this == typeof (ValueType) || this == typeof (Enum))
922 return IsSubclassOf (typeof (ValueType));
925 protected virtual bool IsContextfulImpl ()
927 return typeof (ContextBoundObject).IsAssignableFrom (this);
930 protected virtual bool IsMarshalByRefImpl ()
932 return typeof (MarshalByRefObject).IsAssignableFrom (this);
938 public ConstructorInfo GetConstructor (Type[] types)
940 return GetConstructor (BindingFlags.Public|BindingFlags.Instance, null, CallingConventions.Any, types, null);
946 public ConstructorInfo GetConstructor (BindingFlags bindingAttr, Binder binder,
947 Type[] types, ParameterModifier[] modifiers)
949 return GetConstructor (bindingAttr, binder, CallingConventions.Any, types, modifiers);
955 public ConstructorInfo GetConstructor (BindingFlags bindingAttr, Binder binder,
956 CallingConventions callConvention,
957 Type[] types, ParameterModifier[] modifiers)
960 throw new ArgumentNullException ("types");
962 foreach (Type t in types) {
964 throw new ArgumentNullException ("types");
967 return GetConstructorImpl (bindingAttr, binder, callConvention, types, modifiers);
973 public ConstructorInfo[] GetConstructors ()
975 return GetConstructors (BindingFlags.Public | BindingFlags.Instance);
981 public abstract ConstructorInfo[] GetConstructors (BindingFlags bindingAttr);
983 public virtual MemberInfo[] GetDefaultMembers ()
985 object [] att = GetCustomAttributes (typeof (DefaultMemberAttribute), true);
987 return new MemberInfo [0];
989 MemberInfo [] member = GetMember (((DefaultMemberAttribute) att [0]).MemberName);
990 return (member != null) ? member : new MemberInfo [0];
993 public virtual MemberInfo[] FindMembers (MemberTypes memberType, BindingFlags bindingAttr,
994 MemberFilter filter, object filterCriteria)
997 ArrayList l = new ArrayList ();
999 // Console.WriteLine ("FindMembers for {0} (Type: {1}): {2}",
1000 // this.FullName, this.GetType().FullName, this.obj_address());
1002 if ((memberType & MemberTypes.Constructor) != 0) {
1003 ConstructorInfo[] c = GetConstructors (bindingAttr);
1004 if (filter != null) {
1005 foreach (MemberInfo m in c) {
1006 if (filter (m, filterCriteria))
1013 if ((memberType & MemberTypes.Event) != 0) {
1014 EventInfo[] c = GetEvents (bindingAttr);
1015 if (filter != null) {
1016 foreach (MemberInfo m in c) {
1017 if (filter (m, filterCriteria))
1024 if ((memberType & MemberTypes.Field) != 0) {
1025 FieldInfo[] c = GetFields (bindingAttr);
1026 if (filter != null) {
1027 foreach (MemberInfo m in c) {
1028 if (filter (m, filterCriteria))
1035 if ((memberType & MemberTypes.Method) != 0) {
1036 MethodInfo[] c = GetMethods (bindingAttr);
1037 if (filter != null) {
1038 foreach (MemberInfo m in c) {
1039 if (filter (m, filterCriteria))
1046 if ((memberType & MemberTypes.Property) != 0) {
1048 int count = l.Count;
1050 if (filter != null) {
1052 while ((l.Count == count) && (ptype != null)) {
1053 c = ptype.GetProperties (bindingAttr);
1054 foreach (MemberInfo m in c) {
1055 if (filter (m, filterCriteria))
1058 ptype = ptype.BaseType;
1061 c = GetProperties (bindingAttr);
1065 if ((memberType & MemberTypes.NestedType) != 0) {
1066 Type[] c = GetNestedTypes (bindingAttr);
1067 if (filter != null) {
1068 foreach (MemberInfo m in c) {
1069 if (filter (m, filterCriteria)) {
1077 result = new MemberInfo [l.Count];
1083 [DebuggerStepThrough]
1084 public object InvokeMember (string name, BindingFlags invokeAttr, Binder binder, object target, object[] args)
1086 return InvokeMember (name, invokeAttr, binder, target, args, null, null, null);
1090 [DebuggerStepThrough]
1091 public object InvokeMember (string name, BindingFlags invokeAttr, Binder binder,
1092 object target, object[] args, CultureInfo culture)
1094 return InvokeMember (name, invokeAttr, binder, target, args, null, culture, null);
1097 public abstract object InvokeMember (string name, BindingFlags invokeAttr,
1098 Binder binder, object target, object[] args,
1099 ParameterModifier[] modifiers,
1100 CultureInfo culture, string[] namedParameters);
1102 public override string ToString()
1107 internal bool IsSystemType {
1109 return _impl.Value != IntPtr.Zero;
1113 #if NET_2_0 || BOOTSTRAP_NET_2_0
1114 public virtual Type[] GetGenericArguments ()
1116 throw new NotSupportedException ();
1119 public virtual bool ContainsGenericParameters {
1120 get { return false; }
1123 public virtual extern bool IsGenericTypeDefinition {
1124 [MethodImplAttribute(MethodImplOptions.InternalCall)]
1128 [MethodImplAttribute(MethodImplOptions.InternalCall)]
1129 extern Type GetGenericTypeDefinition_impl ();
1131 public virtual Type GetGenericTypeDefinition ()
1133 Type res = GetGenericTypeDefinition_impl ();
1135 throw new InvalidOperationException ();
1140 public virtual extern bool IsGenericType {
1141 [MethodImplAttribute(MethodImplOptions.InternalCall)]
1145 [MethodImplAttribute(MethodImplOptions.InternalCall)]
1146 static extern Type MakeGenericType (Type gt, Type [] types);
1148 public virtual Type MakeGenericType (params Type[] types)
1150 if (!IsGenericTypeDefinition)
1151 throw new InvalidOperationException ("not a generic type definition");
1153 throw new ArgumentNullException ("types");
1154 if (GetGenericArguments().Length != types.Length)
1155 throw new ArgumentException (String.Format ("The type or method has {0} generic parameter(s) but {1} generic argument(s) where provided. A generic argument must be provided for each generic parameter.", GetGenericArguments ().Length, types.Length), "types");
1157 Type[] systemTypes = new Type[types.Length];
1158 for (int i = 0; i < types.Length; ++i) {
1161 throw new ArgumentNullException ("types");
1163 t = t.UnderlyingSystemType;
1164 if (t == null || !t.IsSystemType)
1165 throw new ArgumentNullException ("types");
1166 systemTypes [i] = types [i].UnderlyingSystemType;
1169 Type res = MakeGenericType (this, systemTypes);
1171 throw new TypeLoadException ();
1175 public virtual bool IsGenericParameter {
1181 public bool IsNested {
1183 return DeclaringType != null;
1187 public bool IsVisible {
1190 return DeclaringType.IsVisible;
1196 [MethodImplAttribute(MethodImplOptions.InternalCall)]
1197 extern int GetGenericParameterPosition ();
1199 public virtual int GenericParameterPosition {
1201 int res = GetGenericParameterPosition ();
1203 throw new InvalidOperationException ();
1208 [MethodImplAttribute(MethodImplOptions.InternalCall)]
1209 extern GenericParameterAttributes GetGenericParameterAttributes ();
1211 public virtual GenericParameterAttributes GenericParameterAttributes {
1213 if (!IsGenericParameter)
1214 throw new InvalidOperationException ();
1216 return GetGenericParameterAttributes ();
1220 [MethodImplAttribute(MethodImplOptions.InternalCall)]
1221 extern Type[] GetGenericParameterConstraints_impl ();
1223 public virtual Type[] GetGenericParameterConstraints ()
1225 if (!IsGenericParameter)
1226 throw new InvalidOperationException ();
1228 return GetGenericParameterConstraints_impl ();
1231 public virtual MethodBase DeclaringMethod {
1237 [MethodImplAttribute(MethodImplOptions.InternalCall)]
1238 extern Type make_array_type (int rank);
1240 public virtual Type MakeArrayType ()
1242 return MakeArrayType (1);
1245 public virtual Type MakeArrayType (int rank)
1248 throw new IndexOutOfRangeException ();
1249 return make_array_type (rank);
1252 [MethodImplAttribute(MethodImplOptions.InternalCall)]
1253 extern Type make_byref_type ();
1255 public virtual Type MakeByRefType ()
1257 return make_byref_type ();
1260 [MethodImplAttribute(MethodImplOptions.InternalCall)]
1261 public extern virtual Type MakePointerType ();
1263 public static Type ReflectionOnlyGetType (string typeName,
1264 bool throwIfNotFound,
1267 if (typeName == null)
1268 throw new ArgumentNullException ("typeName");
1269 int idx = typeName.IndexOf (',');
1270 if (idx < 0 || idx == 0 || idx == typeName.Length - 1)
1271 throw new ArgumentException ("Assembly qualifed type name is required", "typeName");
1272 string an = typeName.Substring (idx + 1);
1275 a = Assembly.ReflectionOnlyLoad (an);
1277 if (throwIfNotFound)
1281 return a.GetType (typeName.Substring (0, idx), throwIfNotFound, ignoreCase);
1284 [MethodImplAttribute(MethodImplOptions.InternalCall)]
1285 extern void GetPacking (out int packing, out int size);
1287 public virtual StructLayoutAttribute StructLayoutAttribute {
1291 if (IsLayoutSequential)
1292 kind = LayoutKind.Sequential;
1293 else if (IsExplicitLayout)
1294 kind = LayoutKind.Explicit;
1296 kind = LayoutKind.Auto;
1298 StructLayoutAttribute attr = new StructLayoutAttribute (kind);
1301 attr.CharSet = CharSet.Unicode;
1302 else if (IsAnsiClass)
1303 attr.CharSet = CharSet.Ansi;
1305 attr.CharSet = CharSet.Auto;
1307 if (kind != LayoutKind.Auto)
1308 GetPacking (out attr.Pack, out attr.Size);
1314 internal object[] GetPseudoCustomAttributes ()
1318 /* IsSerializable returns true for delegates/enums as well */
1319 if ((Attributes & TypeAttributes.Serializable) != 0)
1321 if ((Attributes & TypeAttributes.Import) != 0)
1326 object[] attrs = new object [count];
1329 if ((Attributes & TypeAttributes.Serializable) != 0)
1330 attrs [count ++] = new SerializableAttribute ();
1331 if ((Attributes & TypeAttributes.Import) != 0)
1332 attrs [count ++] = new ComImportAttribute ();
1339 void _Type.GetIDsOfNames ([In] ref Guid riid, IntPtr rgszNames, uint cNames, uint lcid, IntPtr rgDispId)
1341 throw new NotImplementedException ();
1344 void _Type.GetTypeInfo (uint iTInfo, uint lcid, IntPtr ppTInfo)
1346 throw new NotImplementedException ();
1349 void _Type.GetTypeInfoCount (out uint pcTInfo)
1351 throw new NotImplementedException ();
1354 void _Type.Invoke (uint dispIdMember, [In] ref Guid riid, uint lcid, short wFlags, IntPtr pDispParams, IntPtr pVarResult, IntPtr pExcepInfo, IntPtr puArgErr)
1356 throw new NotImplementedException ();