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 {
212 // This code used to probe for "this == typeof (System.Enum)", but in
213 // The .NET Framework 1.0, the above test return false
215 if (this == typeof (System.ValueType))
219 return !is_subtype_of (this, typeof (System.ValueType), false);
223 public bool IsCOMObject {
225 return IsCOMObjectImpl ();
229 public bool IsContextful {
231 return IsContextfulImpl ();
237 // This hack is needed because EnumBuilder's UnderlyingSystemType returns the enum's basetype
238 if (this is EnumBuilder)
241 return is_subtype_of (this, typeof (System.Enum), false) &&
242 this != typeof (System.Enum);
246 public bool IsExplicitLayout {
248 return (Attributes & TypeAttributes.LayoutMask) == TypeAttributes.ExplicitLayout;
252 public bool IsImport {
254 return (Attributes & TypeAttributes.Import) != 0;
258 public bool IsInterface {
260 return (Attributes & TypeAttributes.ClassSemanticsMask) == TypeAttributes.Interface;
264 public bool IsLayoutSequential {
266 return (Attributes & TypeAttributes.LayoutMask) == TypeAttributes.SequentialLayout;
270 public bool IsMarshalByRef {
272 return IsMarshalByRefImpl ();
276 public bool IsNestedAssembly {
278 return (Attributes & TypeAttributes.VisibilityMask) == TypeAttributes.NestedAssembly;
282 public bool IsNestedFamANDAssem {
284 return (Attributes & TypeAttributes.VisibilityMask) == TypeAttributes.NestedFamANDAssem;
288 public bool IsNestedFamily {
290 return (Attributes & TypeAttributes.VisibilityMask) == TypeAttributes.NestedFamily;
294 public bool IsNestedFamORAssem {
296 return (Attributes & TypeAttributes.VisibilityMask) == TypeAttributes.NestedFamORAssem;
300 public bool IsNestedPrivate {
302 return (Attributes & TypeAttributes.VisibilityMask) == TypeAttributes.NestedPrivate;
306 public bool IsNestedPublic {
308 return (Attributes & TypeAttributes.VisibilityMask) == TypeAttributes.NestedPublic;
312 public bool IsNotPublic {
314 return (Attributes & TypeAttributes.VisibilityMask) == TypeAttributes.NotPublic;
318 public bool IsPointer {
320 return IsPointerImpl ();
324 public bool IsPrimitive {
326 return IsPrimitiveImpl ();
330 public bool IsPublic {
332 return (Attributes & TypeAttributes.VisibilityMask) == TypeAttributes.Public;
336 public bool IsSealed {
338 return (Attributes & TypeAttributes.Sealed) != 0;
342 public bool IsSerializable {
344 // Enums and delegates are always serializable
345 return (Attributes & TypeAttributes.Serializable) != 0 || IsEnum ||
346 is_subtype_of (this, typeof (System.Delegate), false);
350 public bool IsSpecialName {
352 return (Attributes & TypeAttributes.SpecialName) != 0;
356 public bool IsUnicodeClass {
358 return (Attributes & TypeAttributes.StringFormatMask) == TypeAttributes.UnicodeClass;
362 public bool IsValueType {
364 return IsValueTypeImpl ();
368 public override MemberTypes MemberType {
369 get {return MemberTypes.TypeInfo;}
372 #if NET_2_0 || BOOTSTRAP_NET_2_0
375 public abstract Module Module {get;}
377 public abstract string Namespace {get;}
379 public override Type ReflectedType {
385 public abstract RuntimeTypeHandle TypeHandle {get;}
390 public ConstructorInfo TypeInitializer {
392 return GetConstructorImpl (
393 BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static,
395 CallingConventions.Any,
401 public abstract Type UnderlyingSystemType {get;}
403 public override bool Equals (object o)
408 // TODO: return UnderlyingSystemType == o.UnderlyingSystemType;
409 Type cmp = o as Type;
415 [MethodImplAttribute(MethodImplOptions.InternalCall)]
416 public extern bool Equals (Type type);
418 [MethodImplAttribute(MethodImplOptions.InternalCall)]
419 private static extern Type internal_from_handle (IntPtr handle);
421 [MethodImplAttribute(MethodImplOptions.InternalCall)]
422 private static extern Type internal_from_name (string name, bool throwOnError, bool ignoreCase);
424 public static Type GetType(string typeName)
426 if (typeName == null)
427 throw new ArgumentNullException ("typeName");
429 return internal_from_name (typeName, false, false);
432 public static Type GetType(string typeName, bool throwOnError)
434 if (typeName == null)
435 throw new ArgumentNullException ("typeName");
437 Type type = internal_from_name (typeName, throwOnError, false);
438 if (throwOnError && type == null)
439 throw new TypeLoadException ("Error loading '" + typeName + "'");
444 public static Type GetType(string typeName, bool throwOnError, bool ignoreCase)
446 if (typeName == null)
447 throw new ArgumentNullException ("typeName");
449 Type t = internal_from_name (typeName, throwOnError, ignoreCase);
450 if (throwOnError && t == null)
451 throw new TypeLoadException ("Error loading '" + typeName + "'");
456 public static Type[] GetTypeArray (object[] args) {
458 throw new ArgumentNullException ("args");
461 ret = new Type [args.Length];
462 for (int i = 0; i < args.Length; ++i)
463 ret [i] = args[i].GetType ();
467 [MethodImplAttribute(MethodImplOptions.InternalCall)]
468 internal extern static TypeCode GetTypeCodeInternal (Type type);
470 public static TypeCode GetTypeCode (Type type) {
471 type = type.UnderlyingSystemType;
473 if (!type.IsSystemType)
474 return Type.GetTypeCode (typeof (object));
476 return GetTypeCodeInternal (type);
480 public static Type GetTypeFromCLSID (Guid clsid)
482 throw new NotImplementedException ();
486 public static Type GetTypeFromCLSID (Guid clsid, bool throwOnError)
488 throw new NotImplementedException ();
492 public static Type GetTypeFromCLSID (Guid clsid, string server)
494 throw new NotImplementedException ();
498 public static Type GetTypeFromCLSID (Guid clsid, string server, bool throwOnError)
500 throw new NotImplementedException ();
503 public static Type GetTypeFromHandle (RuntimeTypeHandle handle)
505 return internal_from_handle (handle.Value);
509 public static Type GetTypeFromProgID (string progID)
511 throw new NotImplementedException ();
515 public static Type GetTypeFromProgID (string progID, bool throwOnError)
517 throw new NotImplementedException ();
521 public static Type GetTypeFromProgID (string progID, string server)
523 throw new NotImplementedException ();
527 public static Type GetTypeFromProgID (string progID, string server, bool throwOnError)
529 throw new NotImplementedException ();
532 public static RuntimeTypeHandle GetTypeHandle (object o)
534 return o.GetType().TypeHandle;
537 [MethodImplAttribute(MethodImplOptions.InternalCall)]
538 internal static extern bool type_is_subtype_of (Type a, Type b, bool check_interfaces);
540 [MethodImplAttribute(MethodImplOptions.InternalCall)]
541 internal static extern bool type_is_assignable_from (Type a, Type b);
543 internal static bool is_subtype_of (Type a, Type b, bool check_interfaces)
545 a = a.UnderlyingSystemType;
546 b = b.UnderlyingSystemType;
548 if (!a.IsSystemType || !b.IsSystemType)
551 return type_is_subtype_of (a, b, check_interfaces);
557 public virtual bool IsSubclassOf (Type c)
562 return (this != c) && is_subtype_of (this, c, false);
565 public virtual Type[] FindInterfaces (TypeFilter filter, object filterCriteria)
568 throw new ArgumentNullException ("filter");
570 ArrayList ifaces = new ArrayList ();
571 foreach (Type iface in GetInterfaces ()) {
572 if (filter (iface, filterCriteria))
576 return (Type []) ifaces.ToArray (typeof (Type));
579 public Type GetInterface (string name) {
580 return GetInterface (name, false);
583 public abstract Type GetInterface (string name, bool ignoreCase);
585 [MethodImplAttribute(MethodImplOptions.InternalCall)]
586 internal static extern void GetInterfaceMapData (Type t, Type iface, out MethodInfo[] targets, out MethodInfo[] methods);
591 public virtual InterfaceMapping GetInterfaceMap (Type interfaceType) {
592 InterfaceMapping res;
593 if (interfaceType == null)
594 throw new ArgumentNullException ("interfaceType");
595 if (!interfaceType.IsInterface)
596 throw new ArgumentException (Locale.GetText ("Argument must be an interface."), "interfaceType");
597 res.TargetType = this;
598 res.InterfaceType = interfaceType;
599 GetInterfaceMapData (this, interfaceType, out res.TargetMethods, out res.InterfaceMethods);
600 if (res.TargetMethods == null)
601 throw new ArgumentException (Locale.GetText ("Interface not found"), "interfaceType");
606 public abstract Type[] GetInterfaces ();
608 public virtual bool IsAssignableFrom (Type c)
616 if (c is TypeBuilder)
617 return ((TypeBuilder)c).IsAssignableTo (this);
619 /* Handle user defined type classes */
621 Type systemType = UnderlyingSystemType;
622 if (!systemType.IsSystemType)
624 return systemType.IsAssignableFrom (c);
627 if (!c.IsSystemType) {
628 Type underlyingType = c.UnderlyingSystemType;
629 if (!underlyingType.IsSystemType)
631 return IsAssignableFrom (underlyingType);
634 return type_is_assignable_from (this, c);
637 [MethodImplAttribute(MethodImplOptions.InternalCall)]
638 public extern virtual bool IsInstanceOfType (object o);
640 public virtual int GetArrayRank ()
642 throw new NotSupportedException (); // according to MSDN
645 public abstract Type GetElementType ();
647 public EventInfo GetEvent (string name)
649 return GetEvent (name, DefaultBindingFlags);
652 public abstract EventInfo GetEvent (string name, BindingFlags bindingAttr);
654 public virtual EventInfo[] GetEvents ()
656 return GetEvents (DefaultBindingFlags);
659 public abstract EventInfo[] GetEvents (BindingFlags bindingAttr);
661 public FieldInfo GetField( string name)
663 return GetField (name, DefaultBindingFlags);
666 public abstract FieldInfo GetField( string name, BindingFlags bindingAttr);
668 public FieldInfo[] GetFields ()
670 return GetFields (DefaultBindingFlags);
673 public abstract FieldInfo[] GetFields (BindingFlags bindingAttr);
675 public override int GetHashCode()
677 return (int)_impl.Value;
680 public MemberInfo[] GetMember (string name)
682 return GetMember (name, DefaultBindingFlags);
685 public virtual MemberInfo[] GetMember (string name, BindingFlags bindingAttr)
687 return GetMember (name, MemberTypes.All, bindingAttr);
690 public virtual MemberInfo[] GetMember (string name, MemberTypes type, BindingFlags bindingAttr)
692 if ((bindingAttr & BindingFlags.IgnoreCase) != 0)
693 return FindMembers (type, bindingAttr, FilterNameIgnoreCase, name);
695 return FindMembers (type, bindingAttr, FilterName, name);
698 public MemberInfo[] GetMembers ()
700 return GetMembers (DefaultBindingFlags);
703 public abstract MemberInfo[] GetMembers (BindingFlags bindingAttr);
705 public MethodInfo GetMethod (string name)
708 throw new ArgumentNullException ("name");
709 return GetMethodImpl (name, DefaultBindingFlags, null, CallingConventions.Any, null, null);
712 public MethodInfo GetMethod (string name, BindingFlags bindingAttr)
715 throw new ArgumentNullException ("name");
717 return GetMethodImpl (name, bindingAttr, null, CallingConventions.Any, null, null);
720 public MethodInfo GetMethod (string name, Type[] types)
722 return GetMethod (name, DefaultBindingFlags, null, CallingConventions.Any, types, null);
725 public MethodInfo GetMethod (string name, Type[] types, ParameterModifier[] modifiers)
727 return GetMethod (name, DefaultBindingFlags, null, CallingConventions.Any, types, modifiers);
730 public MethodInfo GetMethod (string name, BindingFlags bindingAttr, Binder binder,
731 Type[] types, ParameterModifier[] modifiers)
734 return GetMethod (name, bindingAttr, binder, CallingConventions.Any, types, modifiers);
737 public MethodInfo GetMethod (string name, BindingFlags bindingAttr, Binder binder,
738 CallingConventions callConvention, Type[] types, ParameterModifier[] modifiers)
741 throw new ArgumentNullException ("name");
743 throw new ArgumentNullException ("types");
745 for (int i = 0; i < types.Length; i++)
746 if (types[i] == null)
747 throw new ArgumentNullException ("types");
749 return GetMethodImpl (name, bindingAttr, binder, callConvention, types, modifiers);
752 protected abstract MethodInfo GetMethodImpl (string name, BindingFlags bindingAttr, Binder binder,
753 CallingConventions callConvention, Type[] types,
754 ParameterModifier[] modifiers);
756 internal MethodInfo GetMethodImplInternal (string name, BindingFlags bindingAttr, Binder binder,
757 CallingConventions callConvention, Type[] types,
758 ParameterModifier[] modifiers)
760 return GetMethodImpl (name, bindingAttr, binder, callConvention, types, modifiers);
763 public MethodInfo[] GetMethods ()
765 return GetMethods (DefaultBindingFlags);
768 public abstract MethodInfo[] GetMethods (BindingFlags bindingAttr);
770 public Type GetNestedType (string name)
772 return GetNestedType (name, DefaultBindingFlags);
775 public abstract Type GetNestedType (string name, BindingFlags bindingAttr);
777 public Type[] GetNestedTypes ()
779 return GetNestedTypes (DefaultBindingFlags);
782 public abstract Type[] GetNestedTypes (BindingFlags bindingAttr);
785 public PropertyInfo[] GetProperties ()
787 return GetProperties (DefaultBindingFlags);
790 public abstract PropertyInfo[] GetProperties (BindingFlags bindingAttr);
793 public PropertyInfo GetProperty (string name)
796 throw new ArgumentNullException ("name");
798 return GetPropertyImpl (name, DefaultBindingFlags, null, null, null, null);
801 public PropertyInfo GetProperty (string name, BindingFlags bindingAttr)
804 throw new ArgumentNullException ("name");
805 return GetPropertyImpl (name, bindingAttr, null, null, null, null);
808 public PropertyInfo GetProperty (string name, Type returnType)
811 throw new ArgumentNullException ("name");
812 return GetPropertyImpl (name, DefaultBindingFlags, null, returnType, null, null);
815 public PropertyInfo GetProperty (string name, Type[] types)
817 return GetProperty (name, DefaultBindingFlags, null, null, types, null);
820 public PropertyInfo GetProperty (string name, Type returnType, Type[] types)
822 return GetProperty (name, DefaultBindingFlags, null, returnType, types, null);
825 public PropertyInfo GetProperty( string name, Type returnType, Type[] types, ParameterModifier[] modifiers)
827 return GetProperty (name, DefaultBindingFlags, null, returnType, types, modifiers);
830 public PropertyInfo GetProperty (string name, BindingFlags bindingAttr, Binder binder, Type returnType,
831 Type[] types, ParameterModifier[] modifiers)
834 throw new ArgumentNullException ("name");
836 throw new ArgumentNullException ("types");
838 return GetPropertyImpl (name, bindingAttr, binder, returnType, types, modifiers);
841 protected abstract PropertyInfo GetPropertyImpl (string name, BindingFlags bindingAttr, Binder binder,
842 Type returnType, Type[] types, ParameterModifier[] modifiers);
844 internal PropertyInfo GetPropertyImplInternal (string name, BindingFlags bindingAttr, Binder binder,
845 Type returnType, Type[] types, ParameterModifier[] modifiers)
847 return GetPropertyImpl (name, bindingAttr, binder, returnType, types, modifiers);
850 protected abstract ConstructorInfo GetConstructorImpl (BindingFlags bindingAttr,
852 CallingConventions callConvention,
854 ParameterModifier[] modifiers);
856 protected abstract TypeAttributes GetAttributeFlagsImpl ();
857 protected abstract bool HasElementTypeImpl ();
858 protected abstract bool IsArrayImpl ();
859 protected abstract bool IsByRefImpl ();
860 protected abstract bool IsCOMObjectImpl ();
861 protected abstract bool IsPointerImpl ();
862 protected abstract bool IsPrimitiveImpl ();
864 [MethodImplAttribute(MethodImplOptions.InternalCall)]
865 internal static extern bool IsArrayImpl (Type type);
867 protected virtual bool IsValueTypeImpl ()
869 if (this == typeof (Enum) || this == typeof (ValueType))
872 return IsSubclassOf (typeof (ValueType));
875 protected virtual bool IsContextfulImpl ()
877 return typeof (ContextBoundObject).IsAssignableFrom (this);
880 protected virtual bool IsMarshalByRefImpl ()
882 return typeof (MarshalByRefObject).IsAssignableFrom (this);
888 public ConstructorInfo GetConstructor (Type[] types)
890 return GetConstructorImpl (
891 DefaultBindingFlags, null, CallingConventions.Any, types, null);
897 public ConstructorInfo GetConstructor (BindingFlags bindingAttr, Binder binder,
898 Type[] types, ParameterModifier[] modifiers)
900 return GetConstructorImpl (
901 bindingAttr, binder, CallingConventions.Any, types, modifiers);
907 public ConstructorInfo GetConstructor (BindingFlags bindingAttr, Binder binder,
908 CallingConventions callConvention,
909 Type[] types, ParameterModifier[] modifiers)
912 throw new ArgumentNullException ("types");
914 return GetConstructorImpl (bindingAttr, binder, callConvention, types, modifiers);
920 public ConstructorInfo[] GetConstructors ()
922 return GetConstructors (BindingFlags.Public | BindingFlags.Instance);
928 public abstract ConstructorInfo[] GetConstructors (BindingFlags bindingAttr);
930 public virtual MemberInfo[] GetDefaultMembers ()
932 object [] att = GetCustomAttributes (typeof (DefaultMemberAttribute), true);
934 return new MemberInfo [0];
936 MemberInfo [] member = GetMember (((DefaultMemberAttribute) att [0]).MemberName);
937 return (member != null) ? member : new MemberInfo [0];
940 public virtual MemberInfo[] FindMembers (MemberTypes memberType, BindingFlags bindingAttr,
941 MemberFilter filter, object filterCriteria)
944 ArrayList l = new ArrayList ();
946 // Console.WriteLine ("FindMembers for {0} (Type: {1}): {2}",
947 // this.FullName, this.GetType().FullName, this.obj_address());
949 if ((memberType & MemberTypes.Constructor) != 0) {
950 ConstructorInfo[] c = GetConstructors (bindingAttr);
951 if (filter != null) {
952 foreach (MemberInfo m in c) {
953 if (filter (m, filterCriteria))
960 if ((memberType & MemberTypes.Event) != 0) {
961 EventInfo[] c = GetEvents (bindingAttr);
962 if (filter != null) {
963 foreach (MemberInfo m in c) {
964 if (filter (m, filterCriteria))
971 if ((memberType & MemberTypes.Field) != 0) {
972 FieldInfo[] c = GetFields (bindingAttr);
973 if (filter != null) {
974 foreach (MemberInfo m in c) {
975 if (filter (m, filterCriteria))
982 if ((memberType & MemberTypes.Method) != 0) {
983 MethodInfo[] c = GetMethods (bindingAttr);
984 if (filter != null) {
985 foreach (MemberInfo m in c) {
986 if (filter (m, filterCriteria))
993 if ((memberType & MemberTypes.Property) != 0) {
997 if (filter != null) {
999 while ((l.Count == count) && (ptype != null)) {
1000 c = ptype.GetProperties (bindingAttr);
1001 foreach (MemberInfo m in c) {
1002 if (filter (m, filterCriteria))
1005 ptype = ptype.BaseType;
1008 c = GetProperties (bindingAttr);
1012 if ((memberType & MemberTypes.NestedType) != 0) {
1013 Type[] c = GetNestedTypes (bindingAttr);
1014 if (filter != null) {
1015 foreach (MemberInfo m in c) {
1016 if (filter (m, filterCriteria)) {
1024 result = new MemberInfo [l.Count];
1030 [DebuggerStepThrough]
1031 public object InvokeMember (string name, BindingFlags invokeAttr, Binder binder, object target, object[] args)
1033 return InvokeMember (name, invokeAttr, binder, target, args, null, null, null);
1037 [DebuggerStepThrough]
1038 public object InvokeMember (string name, BindingFlags invokeAttr, Binder binder,
1039 object target, object[] args, CultureInfo culture)
1041 return InvokeMember (name, invokeAttr, binder, target, args, null, culture, null);
1044 public abstract object InvokeMember (string name, BindingFlags invokeAttr,
1045 Binder binder, object target, object[] args,
1046 ParameterModifier[] modifiers,
1047 CultureInfo culture, string[] namedParameters);
1049 public override string ToString()
1054 internal bool IsSystemType {
1056 return _impl.Value != IntPtr.Zero;
1060 #if NET_2_0 || BOOTSTRAP_NET_2_0
1061 public abstract Type[] GetGenericArguments ();
1063 public abstract bool HasGenericArguments {
1067 public abstract bool ContainsGenericParameters {
1071 public extern bool IsGenericTypeDefinition {
1072 [MethodImplAttribute(MethodImplOptions.InternalCall)]
1076 [MethodImplAttribute(MethodImplOptions.InternalCall)]
1077 extern Type GetGenericTypeDefinition_impl ();
1079 public virtual Type GetGenericTypeDefinition ()
1081 Type res = GetGenericTypeDefinition_impl ();
1083 throw new InvalidOperationException ();
1088 public extern bool IsGenericInstance {
1089 [MethodImplAttribute(MethodImplOptions.InternalCall)]
1093 [MethodImplAttribute(MethodImplOptions.InternalCall)]
1094 static extern Type BindGenericParameters (Type gt, Type [] types);
1099 public Type BindGenericParameters (Type [] types)
1102 throw new ArgumentNullException ("types");
1103 foreach (Type t in types) {
1105 throw new ArgumentNullException ("types");
1107 Type res = BindGenericParameters (this, types);
1109 throw new TypeLoadException ();
1113 public abstract bool IsGenericParameter {
1117 [MethodImplAttribute(MethodImplOptions.InternalCall)]
1118 extern int GetGenericParameterPosition ();
1120 public virtual int GenericParameterPosition {
1122 int res = GetGenericParameterPosition ();
1124 throw new InvalidOperationException ();
1129 [MethodImplAttribute(MethodImplOptions.InternalCall)]
1130 extern GenericParameterAttributes GetGenericParameterAttributes ();
1132 public virtual GenericParameterAttributes GenericParameterAttributes {
1134 if (!IsGenericParameter)
1135 throw new InvalidOperationException ();
1137 return GetGenericParameterAttributes ();
1141 [MethodImplAttribute(MethodImplOptions.InternalCall)]
1142 extern Type[] GetGenericParameterConstraints_impl ();
1144 public virtual Type[] GetGenericParameterConstraints ()
1146 if (!IsGenericParameter)
1147 throw new InvalidOperationException ();
1149 return GetGenericParameterConstraints_impl ();
1152 public abstract MethodInfo DeclaringMethod {
1156 [MethodImplAttribute(MethodImplOptions.InternalCall)]
1157 extern Type make_array_type (int rank);
1159 public virtual Type MakeArrayType ()
1161 return MakeArrayType (1);
1164 public virtual Type MakeArrayType (int rank)
1167 throw new IndexOutOfRangeException ();
1168 return make_array_type (rank);
1171 [MethodImplAttribute(MethodImplOptions.InternalCall)]
1172 extern Type make_byref_type ();
1174 public virtual Type MakeByRefType ()
1176 return make_byref_type ();
1179 [MethodImplAttribute(MethodImplOptions.InternalCall)]
1180 public extern virtual Type MakePointerType ();
1183 public static Type ReflectionOnlyGetType (string typeName,
1184 bool throwIfNotFound,
1187 throw new NotImplementedException ();
1190 [MethodImplAttribute(MethodImplOptions.InternalCall)]
1191 extern void GetPacking (out int packing, out int size);
1193 public virtual StructLayoutAttribute StructLayoutAttribute {
1197 if (IsLayoutSequential)
1198 kind = LayoutKind.Sequential;
1199 else if (IsExplicitLayout)
1200 kind = LayoutKind.Explicit;
1202 kind = LayoutKind.Auto;
1204 StructLayoutAttribute attr = new StructLayoutAttribute (kind);
1207 attr.CharSet = CharSet.Unicode;
1208 else if (IsAnsiClass)
1209 attr.CharSet = CharSet.Ansi;
1211 attr.CharSet = CharSet.Auto;
1213 if (kind != LayoutKind.Auto)
1214 GetPacking (out attr.Pack, out attr.Size);
1220 internal object[] GetPseudoCustomAttributes () {
1228 object[] attrs = new object [count];
1232 attrs [count ++] = new SerializableAttribute ();