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)]
45 public abstract class Type : MemberInfo, IReflect {
47 internal RuntimeTypeHandle _impl;
49 public static readonly char Delimiter = '.';
50 public static readonly Type[] EmptyTypes = {};
51 public static readonly MemberFilter FilterAttribute = new MemberFilter (FilterAttribute_impl);
52 public static readonly MemberFilter FilterName = new MemberFilter (FilterName_impl);
53 public static readonly MemberFilter FilterNameIgnoreCase = new MemberFilter (FilterNameIgnoreCase_impl);
54 public static readonly object Missing;
56 protected const BindingFlags DefaultBindingFlags =
57 BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance;
59 /* implementation of the delegates for MemberFilter */
60 static bool FilterName_impl (MemberInfo m, object filterCriteria)
62 string name = (string) filterCriteria;
63 if (name == null || name.Length == 0 )
64 return false; // because m.Name cannot be null or empty
66 if (name [name.Length-1] == '*')
67 return string.Compare (name, 0, m.Name, 0, name.Length-1, false, CultureInfo.InvariantCulture) == 0;
69 return name.Equals (m.Name);
72 static bool FilterNameIgnoreCase_impl (MemberInfo m, object filterCriteria)
74 string name = (string) filterCriteria;
75 if (name == null || name.Length == 0 )
76 return false; // because m.Name cannot be null or empty
78 if (name [name.Length-1] == '*')
79 return string.Compare (name, 0, m.Name, 0, name.Length-1, true, CultureInfo.InvariantCulture) == 0;
81 return String.Compare (name, m.Name, true, CultureInfo.InvariantCulture) == 0;
84 static bool FilterAttribute_impl (MemberInfo m, object filterCriteria)
86 int flags = ((IConvertible)filterCriteria).ToInt32 (null);
88 return ((int)((MethodInfo)m).Attributes & flags) != 0;
90 return ((int)((FieldInfo)m).Attributes & flags) != 0;
91 if (m is PropertyInfo)
92 return ((int)((PropertyInfo)m).Attributes & flags) != 0;
94 return ((int)((EventInfo)m).Attributes & flags) != 0;
103 /// The assembly where the type is defined.
105 public abstract Assembly Assembly {
110 /// Gets the fully qualified name for the type including the
111 /// assembly name where the type is defined.
113 public abstract string AssemblyQualifiedName {
118 /// Returns the Attributes associated with the type.
120 public TypeAttributes Attributes {
122 return GetAttributeFlagsImpl ();
127 /// Returns the basetype for this type
129 public abstract Type BaseType {
134 /// Returns the class that declares the member.
136 public override Type DeclaringType {
145 public static Binder DefaultBinder {
147 return Binder.DefaultBinder;
152 /// The full name of the type including its namespace
154 public abstract string FullName {
158 public abstract Guid GUID {
162 public bool HasElementType {
164 return HasElementTypeImpl ();
168 public bool IsAbstract {
170 return (Attributes & TypeAttributes.Abstract) != 0;
174 public bool IsAnsiClass {
176 return (Attributes & TypeAttributes.StringFormatMask)
177 == TypeAttributes.AnsiClass;
181 public bool IsArray {
183 return IsArrayImpl ();
187 public bool IsAutoClass {
189 return (Attributes & TypeAttributes.StringFormatMask) == TypeAttributes.AutoClass;
193 public bool IsAutoLayout {
195 return (Attributes & TypeAttributes.LayoutMask) == TypeAttributes.AutoLayout;
199 public bool IsByRef {
201 return IsByRefImpl ();
205 public bool IsClass {
208 // This code used to probe for "this == typeof (System.Enum)", but in
209 // The .NET Framework 1.0, the above test return false
211 if (this == typeof (System.ValueType))
215 return !is_subtype_of (this, typeof (System.ValueType), false);
219 public bool IsCOMObject {
221 return IsCOMObjectImpl ();
225 public bool IsContextful {
227 return IsContextfulImpl ();
233 // This hack is needed because EnumBuilder's UnderlyingSystemType returns the enum's basetype
234 if (this is EnumBuilder)
237 return is_subtype_of (this, typeof (System.Enum), false) &&
238 this != typeof (System.Enum);
242 public bool IsExplicitLayout {
244 return (Attributes & TypeAttributes.LayoutMask) == TypeAttributes.ExplicitLayout;
248 public bool IsImport {
250 return (Attributes & TypeAttributes.Import) != 0;
254 public bool IsInterface {
256 return (Attributes & TypeAttributes.ClassSemanticsMask) == TypeAttributes.Interface;
260 public bool IsLayoutSequential {
262 return (Attributes & TypeAttributes.LayoutMask) == TypeAttributes.SequentialLayout;
266 public bool IsMarshalByRef {
268 return IsMarshalByRefImpl ();
272 public bool IsNestedAssembly {
274 return (Attributes & TypeAttributes.VisibilityMask) == TypeAttributes.NestedAssembly;
278 public bool IsNestedFamANDAssem {
280 return (Attributes & TypeAttributes.VisibilityMask) == TypeAttributes.NestedFamANDAssem;
284 public bool IsNestedFamily {
286 return (Attributes & TypeAttributes.VisibilityMask) == TypeAttributes.NestedFamily;
290 public bool IsNestedFamORAssem {
292 return (Attributes & TypeAttributes.VisibilityMask) == TypeAttributes.NestedFamORAssem;
296 public bool IsNestedPrivate {
298 return (Attributes & TypeAttributes.VisibilityMask) == TypeAttributes.NestedPrivate;
302 public bool IsNestedPublic {
304 return (Attributes & TypeAttributes.VisibilityMask) == TypeAttributes.NestedPublic;
308 public bool IsNotPublic {
310 return (Attributes & TypeAttributes.VisibilityMask) == TypeAttributes.NotPublic;
314 public bool IsPointer {
316 return IsPointerImpl ();
320 public bool IsPrimitive {
322 return IsPrimitiveImpl ();
326 public bool IsPublic {
328 return (Attributes & TypeAttributes.VisibilityMask) == TypeAttributes.Public;
332 public bool IsSealed {
334 return (Attributes & TypeAttributes.Sealed) != 0;
338 public bool IsSerializable {
340 // Enums and delegates are always serializable
341 return (Attributes & TypeAttributes.Serializable) != 0 || IsEnum ||
342 is_subtype_of (this, typeof (System.Delegate), false);
346 public bool IsSpecialName {
348 return (Attributes & TypeAttributes.SpecialName) != 0;
352 public bool IsUnicodeClass {
354 return (Attributes & TypeAttributes.StringFormatMask) == TypeAttributes.UnicodeClass;
358 public bool IsValueType {
360 return IsValueTypeImpl ();
364 public override MemberTypes MemberType {
365 get {return MemberTypes.TypeInfo;}
368 #if NET_2_0 || BOOTSTRAP_NET_2_0
371 public abstract Module Module {get;}
373 public abstract string Namespace {get;}
375 public override Type ReflectedType {
381 public abstract RuntimeTypeHandle TypeHandle {get;}
383 public ConstructorInfo TypeInitializer {
385 return GetConstructorImpl (
386 BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static,
388 CallingConventions.Any,
394 public abstract Type UnderlyingSystemType {get;}
396 public override bool Equals (object o)
401 // TODO: return UnderlyingSystemType == o.UnderlyingSystemType;
402 Type cmp = o as Type;
408 [MethodImplAttribute(MethodImplOptions.InternalCall)]
409 public extern bool Equals (Type type);
411 [MethodImplAttribute(MethodImplOptions.InternalCall)]
412 private static extern Type internal_from_handle (IntPtr handle);
414 [MethodImplAttribute(MethodImplOptions.InternalCall)]
415 private static extern Type internal_from_name (string name, bool throwOnError, bool ignoreCase);
417 public static Type GetType(string typeName)
419 if (typeName == null)
420 throw new ArgumentNullException ("typeName");
422 return internal_from_name (typeName, false, false);
425 public static Type GetType(string typeName, bool throwOnError)
427 if (typeName == null)
428 throw new ArgumentNullException ("typeName");
430 Type type = internal_from_name (typeName, throwOnError, false);
431 if (throwOnError && type == null)
432 throw new TypeLoadException ("Error loading '" + typeName + "'");
437 public static Type GetType(string typeName, bool throwOnError, bool ignoreCase)
439 if (typeName == null)
440 throw new ArgumentNullException ("typeName");
442 Type t = internal_from_name (typeName, throwOnError, ignoreCase);
443 if (throwOnError && t == null)
444 throw new TypeLoadException ("Error loading '" + typeName + "'");
449 public static Type[] GetTypeArray (object[] args) {
451 throw new ArgumentNullException ("args");
454 ret = new Type [args.Length];
455 for (int i = 0; i < args.Length; ++i)
456 ret [i] = args[i].GetType ();
460 [MethodImplAttribute(MethodImplOptions.InternalCall)]
461 public extern static TypeCode GetTypeCodeInternal (Type type);
463 public static TypeCode GetTypeCode (Type type) {
464 type = type.UnderlyingSystemType;
466 if (!type.IsSystemType)
467 return Type.GetTypeCode (typeof (object));
469 return GetTypeCodeInternal (type);
473 public static Type GetTypeFromCLSID (Guid clsid)
475 throw new NotImplementedException ();
479 public static Type GetTypeFromCLSID (Guid clsid, bool throwOnError)
481 throw new NotImplementedException ();
485 public static Type GetTypeFromCLSID (Guid clsid, string server)
487 throw new NotImplementedException ();
491 public static Type GetTypeFromCLSID (Guid clsid, string server, bool throwOnError)
493 throw new NotImplementedException ();
496 public static Type GetTypeFromHandle (RuntimeTypeHandle handle)
498 return internal_from_handle (handle.Value);
502 public static Type GetTypeFromProgID (string progID)
504 throw new NotImplementedException ();
508 public static Type GetTypeFromProgID (string progID, bool throwOnError)
510 throw new NotImplementedException ();
514 public static Type GetTypeFromProgID (string progID, string server)
516 throw new NotImplementedException ();
520 public static Type GetTypeFromProgID (string progID, string server, bool throwOnError)
522 throw new NotImplementedException ();
525 public static RuntimeTypeHandle GetTypeHandle (object o)
527 return o.GetType().TypeHandle;
530 [MethodImplAttribute(MethodImplOptions.InternalCall)]
531 internal static extern bool type_is_subtype_of (Type a, Type b, bool check_interfaces);
533 [MethodImplAttribute(MethodImplOptions.InternalCall)]
534 internal static extern bool type_is_assignable_from (Type a, Type b);
536 internal static bool is_subtype_of (Type a, Type b, bool check_interfaces)
538 a = a.UnderlyingSystemType;
539 b = b.UnderlyingSystemType;
541 if (!a.IsSystemType || !b.IsSystemType)
544 return type_is_subtype_of (a, b, check_interfaces);
547 public virtual bool IsSubclassOf (Type c)
552 return (this != c) && is_subtype_of (this, c, false);
555 public virtual Type[] FindInterfaces (TypeFilter filter, object filterCriteria)
558 throw new ArgumentNullException ("filter");
560 ArrayList ifaces = new ArrayList ();
561 foreach (Type iface in GetInterfaces ()) {
562 if (filter (iface, filterCriteria))
566 return (Type []) ifaces.ToArray (typeof (Type));
569 public Type GetInterface (string name) {
570 return GetInterface (name, false);
573 public abstract Type GetInterface (string name, bool ignoreCase);
575 [MethodImplAttribute(MethodImplOptions.InternalCall)]
576 internal static extern void GetInterfaceMapData (Type t, Type iface, out MethodInfo[] targets, out MethodInfo[] methods);
578 public virtual InterfaceMapping GetInterfaceMap (Type interfaceType) {
579 InterfaceMapping res;
580 if (interfaceType == null)
581 throw new ArgumentNullException ("interfaceType");
582 if (!interfaceType.IsInterface)
583 throw new ArgumentException (Locale.GetText ("Argument must be an interface."), "interfaceType");
584 res.TargetType = this;
585 res.InterfaceType = interfaceType;
586 GetInterfaceMapData (this, interfaceType, out res.TargetMethods, out res.InterfaceMethods);
587 if (res.TargetMethods == null)
588 throw new ArgumentException (Locale.GetText ("Interface not found"), "interfaceType");
593 public abstract Type[] GetInterfaces ();
595 public virtual bool IsAssignableFrom (Type c)
603 if (c is TypeBuilder)
604 return ((TypeBuilder)c).IsAssignableTo (this);
606 /* Handle user defined type classes */
608 Type systemType = UnderlyingSystemType;
609 if (!systemType.IsSystemType)
611 return systemType.IsAssignableFrom (c);
614 if (!c.IsSystemType) {
615 Type underlyingType = c.UnderlyingSystemType;
616 if (!underlyingType.IsSystemType)
618 return IsAssignableFrom (underlyingType);
621 return type_is_assignable_from (this, c);
624 [MethodImplAttribute(MethodImplOptions.InternalCall)]
625 public extern virtual bool IsInstanceOfType (object o);
627 public virtual int GetArrayRank ()
629 throw new NotSupportedException (); // according to MSDN
632 public abstract Type GetElementType ();
634 public EventInfo GetEvent (string name)
636 return GetEvent (name, DefaultBindingFlags);
639 public abstract EventInfo GetEvent (string name, BindingFlags bindingAttr);
641 public virtual EventInfo[] GetEvents ()
643 return GetEvents (DefaultBindingFlags);
646 public abstract EventInfo[] GetEvents (BindingFlags bindingAttr);
648 public FieldInfo GetField( string name)
650 return GetField (name, DefaultBindingFlags);
653 public abstract FieldInfo GetField( string name, BindingFlags bindingAttr);
655 public FieldInfo[] GetFields ()
657 return GetFields (DefaultBindingFlags);
660 public abstract FieldInfo[] GetFields (BindingFlags bindingAttr);
662 public override int GetHashCode()
664 return (int)_impl.Value;
667 public MemberInfo[] GetMember (string name)
669 return GetMember (name, DefaultBindingFlags);
672 public virtual MemberInfo[] GetMember (string name, BindingFlags bindingAttr)
674 return GetMember (name, MemberTypes.All, bindingAttr);
677 public virtual MemberInfo[] GetMember (string name, MemberTypes type, BindingFlags bindingAttr)
679 if ((bindingAttr & BindingFlags.IgnoreCase) != 0)
680 return FindMembers (type, bindingAttr, FilterNameIgnoreCase, name);
682 return FindMembers (type, bindingAttr, FilterName, name);
685 public MemberInfo[] GetMembers ()
687 return GetMembers (DefaultBindingFlags);
690 public abstract MemberInfo[] GetMembers (BindingFlags bindingAttr);
692 public MethodInfo GetMethod (string name)
695 throw new ArgumentNullException ("name");
696 return GetMethodImpl (name, DefaultBindingFlags, null, CallingConventions.Any, null, null);
699 public MethodInfo GetMethod (string name, BindingFlags bindingAttr)
702 throw new ArgumentNullException ("name");
704 return GetMethodImpl (name, bindingAttr, null, CallingConventions.Any, null, null);
707 public MethodInfo GetMethod (string name, Type[] types)
709 return GetMethod (name, DefaultBindingFlags, null, CallingConventions.Any, types, null);
712 public MethodInfo GetMethod (string name, Type[] types, ParameterModifier[] modifiers)
714 return GetMethod (name, DefaultBindingFlags, null, CallingConventions.Any, types, modifiers);
717 public MethodInfo GetMethod (string name, BindingFlags bindingAttr, Binder binder,
718 Type[] types, ParameterModifier[] modifiers)
721 return GetMethod (name, bindingAttr, binder, CallingConventions.Any, types, modifiers);
724 public MethodInfo GetMethod (string name, BindingFlags bindingAttr, Binder binder,
725 CallingConventions callConvention, Type[] types, ParameterModifier[] modifiers)
728 throw new ArgumentNullException ("name");
730 throw new ArgumentNullException ("types");
732 for (int i = 0; i < types.Length; i++)
733 if (types[i] == null)
734 throw new ArgumentNullException ("types");
736 return GetMethodImpl (name, bindingAttr, binder, callConvention, types, modifiers);
739 protected abstract MethodInfo GetMethodImpl (string name, BindingFlags bindingAttr, Binder binder,
740 CallingConventions callConvention, Type[] types,
741 ParameterModifier[] modifiers);
743 internal MethodInfo GetMethodImplInternal (string name, BindingFlags bindingAttr, Binder binder,
744 CallingConventions callConvention, Type[] types,
745 ParameterModifier[] modifiers)
747 return GetMethodImpl (name, bindingAttr, binder, callConvention, types, modifiers);
750 public MethodInfo[] GetMethods ()
752 return GetMethods (DefaultBindingFlags);
755 public abstract MethodInfo[] GetMethods (BindingFlags bindingAttr);
757 public Type GetNestedType (string name)
759 return GetNestedType (name, DefaultBindingFlags);
762 public abstract Type GetNestedType (string name, BindingFlags bindingAttr);
764 public Type[] GetNestedTypes ()
766 return GetNestedTypes (DefaultBindingFlags);
769 public abstract Type[] GetNestedTypes (BindingFlags bindingAttr);
772 public PropertyInfo[] GetProperties ()
774 return GetProperties (DefaultBindingFlags);
777 public abstract PropertyInfo[] GetProperties (BindingFlags bindingAttr);
780 public PropertyInfo GetProperty (string name)
783 throw new ArgumentNullException ("name");
785 return GetPropertyImpl (name, DefaultBindingFlags, null, null, null, null);
788 public PropertyInfo GetProperty (string name, BindingFlags bindingAttr)
791 throw new ArgumentNullException ("name");
792 return GetPropertyImpl (name, bindingAttr, null, null, null, null);
795 public PropertyInfo GetProperty (string name, Type returnType)
798 throw new ArgumentNullException ("name");
799 return GetPropertyImpl (name, DefaultBindingFlags, null, returnType, null, null);
802 public PropertyInfo GetProperty (string name, Type[] types)
804 return GetProperty (name, DefaultBindingFlags, null, null, types, null);
807 public PropertyInfo GetProperty (string name, Type returnType, Type[] types)
809 return GetProperty (name, DefaultBindingFlags, null, returnType, types, null);
812 public PropertyInfo GetProperty( string name, Type returnType, Type[] types, ParameterModifier[] modifiers)
814 return GetProperty (name, DefaultBindingFlags, null, returnType, types, modifiers);
817 public PropertyInfo GetProperty (string name, BindingFlags bindingAttr, Binder binder, Type returnType,
818 Type[] types, ParameterModifier[] modifiers)
821 throw new ArgumentNullException ("name");
823 throw new ArgumentNullException ("types");
825 return GetPropertyImpl (name, bindingAttr, binder, returnType, types, modifiers);
828 protected abstract PropertyInfo GetPropertyImpl (string name, BindingFlags bindingAttr, Binder binder,
829 Type returnType, Type[] types, ParameterModifier[] modifiers);
831 internal PropertyInfo GetPropertyImplInternal (string name, BindingFlags bindingAttr, Binder binder,
832 Type returnType, Type[] types, ParameterModifier[] modifiers)
834 return GetPropertyImpl (name, bindingAttr, binder, returnType, types, modifiers);
837 protected abstract ConstructorInfo GetConstructorImpl (BindingFlags bindingAttr,
839 CallingConventions callConvention,
841 ParameterModifier[] modifiers);
843 protected abstract TypeAttributes GetAttributeFlagsImpl ();
844 protected abstract bool HasElementTypeImpl ();
845 protected abstract bool IsArrayImpl ();
846 protected abstract bool IsByRefImpl ();
847 protected abstract bool IsCOMObjectImpl ();
848 protected abstract bool IsPointerImpl ();
849 protected abstract bool IsPrimitiveImpl ();
851 [MethodImplAttribute(MethodImplOptions.InternalCall)]
852 internal static extern bool IsArrayImpl (Type type);
854 protected virtual bool IsValueTypeImpl ()
856 if (this == typeof (Enum) || this == typeof (ValueType))
859 return IsSubclassOf (typeof (ValueType));
862 protected virtual bool IsContextfulImpl ()
864 return typeof (ContextBoundObject).IsAssignableFrom (this);
867 protected virtual bool IsMarshalByRefImpl ()
869 return typeof (MarshalByRefObject).IsAssignableFrom (this);
872 public ConstructorInfo GetConstructor (Type[] types)
874 return GetConstructorImpl (
875 DefaultBindingFlags, null, CallingConventions.Any, types, null);
878 public ConstructorInfo GetConstructor (BindingFlags bindingAttr, Binder binder,
879 Type[] types, ParameterModifier[] modifiers)
881 return GetConstructorImpl (
882 bindingAttr, binder, CallingConventions.Any, types, modifiers);
885 public ConstructorInfo GetConstructor (BindingFlags bindingAttr, Binder binder,
886 CallingConventions callConvention,
887 Type[] types, ParameterModifier[] modifiers)
890 throw new ArgumentNullException ("types");
892 return GetConstructorImpl (bindingAttr, binder, callConvention, types, modifiers);
895 public ConstructorInfo[] GetConstructors ()
897 return GetConstructors (BindingFlags.Public | BindingFlags.Instance);
900 public abstract ConstructorInfo[] GetConstructors (BindingFlags bindingAttr);
902 public virtual MemberInfo[] GetDefaultMembers ()
904 object [] att = GetCustomAttributes (typeof (DefaultMemberAttribute), true);
906 return new MemberInfo [0];
908 MemberInfo [] member = GetMember (((DefaultMemberAttribute) att [0]).MemberName);
909 return (member != null) ? member : new MemberInfo [0];
912 public virtual MemberInfo[] FindMembers (MemberTypes memberType, BindingFlags bindingAttr,
913 MemberFilter filter, object filterCriteria)
916 ArrayList l = new ArrayList ();
918 // Console.WriteLine ("FindMembers for {0} (Type: {1}): {2}",
919 // this.FullName, this.GetType().FullName, this.obj_address());
921 if ((memberType & MemberTypes.Constructor) != 0) {
922 ConstructorInfo[] c = GetConstructors (bindingAttr);
923 if (filter != null) {
924 foreach (MemberInfo m in c) {
925 if (filter (m, filterCriteria))
932 if ((memberType & MemberTypes.Event) != 0) {
933 EventInfo[] c = GetEvents (bindingAttr);
934 if (filter != null) {
935 foreach (MemberInfo m in c) {
936 if (filter (m, filterCriteria))
943 if ((memberType & MemberTypes.Field) != 0) {
944 FieldInfo[] c = GetFields (bindingAttr);
945 if (filter != null) {
946 foreach (MemberInfo m in c) {
947 if (filter (m, filterCriteria))
954 if ((memberType & MemberTypes.Method) != 0) {
955 MethodInfo[] c = GetMethods (bindingAttr);
956 if (filter != null) {
957 foreach (MemberInfo m in c) {
958 if (filter (m, filterCriteria))
965 if ((memberType & MemberTypes.Property) != 0) {
969 if (filter != null) {
971 while ((l.Count == count) && (ptype != null)) {
972 c = ptype.GetProperties (bindingAttr);
973 foreach (MemberInfo m in c) {
974 if (filter (m, filterCriteria))
977 ptype = ptype.BaseType;
980 c = GetProperties (bindingAttr);
984 if ((memberType & MemberTypes.NestedType) != 0) {
985 Type[] c = GetNestedTypes (bindingAttr);
986 if (filter != null) {
987 foreach (MemberInfo m in c) {
988 if (filter (m, filterCriteria)) {
996 result = new MemberInfo [l.Count];
1002 [DebuggerStepThrough]
1003 public object InvokeMember (string name, BindingFlags invokeAttr, Binder binder, object target, object[] args)
1005 return InvokeMember (name, invokeAttr, binder, target, args, null, null, null);
1009 [DebuggerStepThrough]
1010 public object InvokeMember (string name, BindingFlags invokeAttr, Binder binder,
1011 object target, object[] args, CultureInfo culture)
1013 return InvokeMember (name, invokeAttr, binder, target, args, null, culture, null);
1016 public abstract object InvokeMember (string name, BindingFlags invokeAttr,
1017 Binder binder, object target, object[] args,
1018 ParameterModifier[] modifiers,
1019 CultureInfo culture, string[] namedParameters);
1021 public override string ToString()
1026 internal bool IsSystemType {
1028 return _impl.Value != IntPtr.Zero;
1032 #if NET_2_0 || BOOTSTRAP_NET_2_0
1033 public abstract Type[] GetGenericArguments ();
1035 public abstract bool HasGenericArguments {
1039 public abstract bool ContainsGenericParameters {
1043 public extern bool IsGenericTypeDefinition {
1044 [MethodImplAttribute(MethodImplOptions.InternalCall)]
1048 [MethodImplAttribute(MethodImplOptions.InternalCall)]
1049 extern Type GetGenericTypeDefinition_impl ();
1051 public virtual Type GetGenericTypeDefinition ()
1053 Type res = GetGenericTypeDefinition_impl ();
1055 throw new InvalidOperationException ();
1060 public extern bool IsGenericInstance {
1061 [MethodImplAttribute(MethodImplOptions.InternalCall)]
1065 [MethodImplAttribute(MethodImplOptions.InternalCall)]
1066 static extern Type BindGenericParameters (Type gt, Type [] types);
1068 public Type BindGenericParameters (Type [] types)
1071 throw new ArgumentNullException ("types");
1072 foreach (Type t in types) {
1074 throw new ArgumentNullException ("types");
1076 Type res = BindGenericParameters (this, types);
1078 throw new TypeLoadException ();
1082 public abstract bool IsGenericParameter {
1086 [MethodImplAttribute(MethodImplOptions.InternalCall)]
1087 extern int GetGenericParameterPosition ();
1089 public virtual int GenericParameterPosition {
1091 int res = GetGenericParameterPosition ();
1093 throw new InvalidOperationException ();
1098 [MethodImplAttribute(MethodImplOptions.InternalCall)]
1099 extern GenericParameterAttributes GetGenericParameterAttributes ();
1101 public virtual GenericParameterAttributes GenericParameterAttributes {
1103 if (!IsGenericParameter)
1104 throw new InvalidOperationException ();
1106 return GetGenericParameterAttributes ();
1110 [MethodImplAttribute(MethodImplOptions.InternalCall)]
1111 extern Type[] GetGenericParameterConstraints_impl ();
1113 public virtual Type[] GetGenericParameterConstraints ()
1115 if (!IsGenericParameter)
1116 throw new InvalidOperationException ();
1118 return GetGenericParameterConstraints_impl ();
1121 public abstract MethodInfo DeclaringMethod {
1125 [MethodImplAttribute(MethodImplOptions.InternalCall)]
1126 extern Type make_array_type (int rank);
1128 public virtual Type MakeArrayType ()
1130 return MakeArrayType (1);
1133 public virtual Type MakeArrayType (int rank)
1136 throw new IndexOutOfRangeException ();
1137 return make_array_type (rank);
1140 [MethodImplAttribute(MethodImplOptions.InternalCall)]
1141 extern Type make_byref_type ();
1143 public virtual Type MakeByRefType ()
1145 return make_byref_type ();
1148 [MethodImplAttribute(MethodImplOptions.InternalCall)]
1149 public extern virtual Type MakePointerType ();
1152 public static Type ReflectionOnlyGetType (string typeName,
1153 bool throwIfNotFound,
1156 throw new NotImplementedException ();
1159 [MethodImplAttribute(MethodImplOptions.InternalCall)]
1160 extern void GetPacking (out int packing, out int size);
1162 public virtual StructLayoutAttribute StructLayoutAttribute {
1166 if (IsLayoutSequential)
1167 kind = LayoutKind.Sequential;
1168 else if (IsExplicitLayout)
1169 kind = LayoutKind.Explicit;
1171 kind = LayoutKind.Auto;
1173 StructLayoutAttribute attr = new StructLayoutAttribute (kind);
1176 attr.CharSet = CharSet.Unicode;
1177 else if (IsAnsiClass)
1178 attr.CharSet = CharSet.Ansi;
1180 attr.CharSet = CharSet.Auto;
1182 if (kind != LayoutKind.Auto)
1183 GetPacking (out attr.Pack, out attr.Size);