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 {
394 public abstract RuntimeTypeHandle TypeHandle {get;}
399 public ConstructorInfo TypeInitializer {
401 return GetConstructorImpl (
402 BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static,
404 CallingConventions.Any,
410 public abstract Type UnderlyingSystemType {get;}
412 public override bool Equals (object o)
417 // TODO: return UnderlyingSystemType == o.UnderlyingSystemType;
418 Type cmp = o as Type;
424 [MethodImplAttribute(MethodImplOptions.InternalCall)]
425 public extern bool Equals (Type type);
427 [MethodImplAttribute(MethodImplOptions.InternalCall)]
428 private static extern Type internal_from_handle (IntPtr handle);
430 [MethodImplAttribute(MethodImplOptions.InternalCall)]
431 private static extern Type internal_from_name (string name, bool throwOnError, bool ignoreCase);
433 public static Type GetType(string typeName)
435 if (typeName == null)
436 throw new ArgumentNullException ("typeName");
438 return internal_from_name (typeName, false, false);
441 public static Type GetType(string typeName, bool throwOnError)
443 if (typeName == null)
444 throw new ArgumentNullException ("typeName");
446 Type type = internal_from_name (typeName, throwOnError, false);
447 if (throwOnError && type == null)
448 throw new TypeLoadException ("Error loading '" + typeName + "'");
453 public static Type GetType(string typeName, bool throwOnError, bool ignoreCase)
455 if (typeName == null)
456 throw new ArgumentNullException ("typeName");
458 Type t = internal_from_name (typeName, throwOnError, ignoreCase);
459 if (throwOnError && t == null)
460 throw new TypeLoadException ("Error loading '" + typeName + "'");
465 public static Type[] GetTypeArray (object[] args) {
467 throw new ArgumentNullException ("args");
470 ret = new Type [args.Length];
471 for (int i = 0; i < args.Length; ++i)
472 ret [i] = args[i].GetType ();
476 [MethodImplAttribute(MethodImplOptions.InternalCall)]
477 internal extern static TypeCode GetTypeCodeInternal (Type type);
479 public static TypeCode GetTypeCode (Type type) {
481 /* MS.NET returns this */
482 return TypeCode.Empty;
484 type = type.UnderlyingSystemType;
486 if (!type.IsSystemType)
487 return Type.GetTypeCode (typeof (object));
489 return GetTypeCodeInternal (type);
493 public static Type GetTypeFromCLSID (Guid clsid)
495 throw new NotImplementedException ();
499 public static Type GetTypeFromCLSID (Guid clsid, bool throwOnError)
501 throw new NotImplementedException ();
505 public static Type GetTypeFromCLSID (Guid clsid, string server)
507 throw new NotImplementedException ();
511 public static Type GetTypeFromCLSID (Guid clsid, string server, bool throwOnError)
513 throw new NotImplementedException ();
516 public static Type GetTypeFromHandle (RuntimeTypeHandle handle)
518 return internal_from_handle (handle.Value);
522 public static Type GetTypeFromProgID (string progID)
524 throw new NotImplementedException ();
528 public static Type GetTypeFromProgID (string progID, bool throwOnError)
530 throw new NotImplementedException ();
534 public static Type GetTypeFromProgID (string progID, string server)
536 throw new NotImplementedException ();
540 public static Type GetTypeFromProgID (string progID, string server, bool throwOnError)
542 throw new NotImplementedException ();
545 public static RuntimeTypeHandle GetTypeHandle (object o)
547 return o.GetType().TypeHandle;
550 [MethodImplAttribute(MethodImplOptions.InternalCall)]
551 internal static extern bool type_is_subtype_of (Type a, Type b, bool check_interfaces);
553 [MethodImplAttribute(MethodImplOptions.InternalCall)]
554 internal static extern bool type_is_assignable_from (Type a, Type b);
556 public new Type GetType ()
558 return base.GetType ();
564 public virtual bool IsSubclassOf (Type c)
566 if (c == null || c == this)
569 // Fast check for system types
571 return c.IsSystemType && type_is_subtype_of (this, c, false);
573 // User defined types depend on this behavior
574 for (Type type = BaseType; type != null; type = type.BaseType)
581 public virtual Type[] FindInterfaces (TypeFilter filter, object filterCriteria)
584 throw new ArgumentNullException ("filter");
586 ArrayList ifaces = new ArrayList ();
587 foreach (Type iface in GetInterfaces ()) {
588 if (filter (iface, filterCriteria))
592 return (Type []) ifaces.ToArray (typeof (Type));
595 public Type GetInterface (string name) {
596 return GetInterface (name, false);
599 public abstract Type GetInterface (string name, bool ignoreCase);
601 [MethodImplAttribute(MethodImplOptions.InternalCall)]
602 internal static extern void GetInterfaceMapData (Type t, Type iface, out MethodInfo[] targets, out MethodInfo[] methods);
607 public virtual InterfaceMapping GetInterfaceMap (Type interfaceType) {
608 InterfaceMapping res;
609 if (interfaceType == null)
610 throw new ArgumentNullException ("interfaceType");
611 if (!interfaceType.IsInterface)
612 throw new ArgumentException (Locale.GetText ("Argument must be an interface."), "interfaceType");
613 res.TargetType = this;
614 res.InterfaceType = interfaceType;
615 GetInterfaceMapData (this, interfaceType, out res.TargetMethods, out res.InterfaceMethods);
616 if (res.TargetMethods == null)
617 throw new ArgumentException (Locale.GetText ("Interface not found"), "interfaceType");
622 public abstract Type[] GetInterfaces ();
624 public virtual bool IsAssignableFrom (Type c)
632 if (c is TypeBuilder)
633 return ((TypeBuilder)c).IsAssignableTo (this);
635 /* Handle user defined type classes */
637 Type systemType = UnderlyingSystemType;
638 if (!systemType.IsSystemType)
640 return systemType.IsAssignableFrom (c);
643 if (!c.IsSystemType) {
644 Type underlyingType = c.UnderlyingSystemType;
645 if (!underlyingType.IsSystemType)
647 return IsAssignableFrom (underlyingType);
650 return type_is_assignable_from (this, c);
653 [MethodImplAttribute(MethodImplOptions.InternalCall)]
654 public extern virtual bool IsInstanceOfType (object o);
656 public virtual int GetArrayRank ()
658 throw new NotSupportedException (); // according to MSDN
661 public abstract Type GetElementType ();
663 public EventInfo GetEvent (string name)
665 return GetEvent (name, DefaultBindingFlags);
668 public abstract EventInfo GetEvent (string name, BindingFlags bindingAttr);
670 public virtual EventInfo[] GetEvents ()
672 return GetEvents (DefaultBindingFlags);
675 public abstract EventInfo[] GetEvents (BindingFlags bindingAttr);
677 public FieldInfo GetField( string name)
679 return GetField (name, DefaultBindingFlags);
682 public abstract FieldInfo GetField( string name, BindingFlags bindingAttr);
684 public FieldInfo[] GetFields ()
686 return GetFields (DefaultBindingFlags);
689 public abstract FieldInfo[] GetFields (BindingFlags bindingAttr);
691 public override int GetHashCode()
693 return (int)_impl.Value;
696 public MemberInfo[] GetMember (string name)
698 return GetMember (name, DefaultBindingFlags);
701 public virtual MemberInfo[] GetMember (string name, BindingFlags bindingAttr)
703 return GetMember (name, MemberTypes.All, bindingAttr);
706 public virtual MemberInfo[] GetMember (string name, MemberTypes type, BindingFlags bindingAttr)
708 if ((bindingAttr & BindingFlags.IgnoreCase) != 0)
709 return FindMembers (type, bindingAttr, FilterNameIgnoreCase, name);
711 return FindMembers (type, bindingAttr, FilterName, name);
714 public MemberInfo[] GetMembers ()
716 return GetMembers (DefaultBindingFlags);
719 public abstract MemberInfo[] GetMembers (BindingFlags bindingAttr);
721 public MethodInfo GetMethod (string name)
724 throw new ArgumentNullException ("name");
725 return GetMethodImpl (name, DefaultBindingFlags, null, CallingConventions.Any, null, null);
728 public MethodInfo GetMethod (string name, BindingFlags bindingAttr)
731 throw new ArgumentNullException ("name");
733 return GetMethodImpl (name, bindingAttr, null, CallingConventions.Any, null, null);
736 public MethodInfo GetMethod (string name, Type[] types)
738 return GetMethod (name, DefaultBindingFlags, null, CallingConventions.Any, types, null);
741 public MethodInfo GetMethod (string name, Type[] types, ParameterModifier[] modifiers)
743 return GetMethod (name, DefaultBindingFlags, null, CallingConventions.Any, types, modifiers);
746 public MethodInfo GetMethod (string name, BindingFlags bindingAttr, Binder binder,
747 Type[] types, ParameterModifier[] modifiers)
750 return GetMethod (name, bindingAttr, binder, CallingConventions.Any, types, modifiers);
753 public MethodInfo GetMethod (string name, BindingFlags bindingAttr, Binder binder,
754 CallingConventions callConvention, Type[] types, ParameterModifier[] modifiers)
757 throw new ArgumentNullException ("name");
759 throw new ArgumentNullException ("types");
761 for (int i = 0; i < types.Length; i++)
762 if (types[i] == null)
763 throw new ArgumentNullException ("types");
765 return GetMethodImpl (name, bindingAttr, binder, callConvention, types, modifiers);
768 protected abstract MethodInfo GetMethodImpl (string name, BindingFlags bindingAttr, Binder binder,
769 CallingConventions callConvention, Type[] types,
770 ParameterModifier[] modifiers);
772 internal MethodInfo GetMethodImplInternal (string name, BindingFlags bindingAttr, Binder binder,
773 CallingConventions callConvention, Type[] types,
774 ParameterModifier[] modifiers)
776 return GetMethodImpl (name, bindingAttr, binder, callConvention, types, modifiers);
779 internal virtual MethodInfo GetMethod (MethodInfo fromNoninstanciated)
781 throw new System.InvalidOperationException ("can only be called in generic type");
784 internal virtual ConstructorInfo GetConstructor (ConstructorInfo fromNoninstanciated)
786 throw new System.InvalidOperationException ("can only be called in generic type");
789 internal virtual FieldInfo GetField (FieldInfo fromNoninstanciated)
791 throw new System.InvalidOperationException ("can only be called in generic type");
795 public MethodInfo[] GetMethods ()
797 return GetMethods (DefaultBindingFlags);
800 public abstract MethodInfo[] GetMethods (BindingFlags bindingAttr);
802 public Type GetNestedType (string name)
804 return GetNestedType (name, DefaultBindingFlags);
807 public abstract Type GetNestedType (string name, BindingFlags bindingAttr);
809 public Type[] GetNestedTypes ()
811 return GetNestedTypes (DefaultBindingFlags);
814 public abstract Type[] GetNestedTypes (BindingFlags bindingAttr);
817 public PropertyInfo[] GetProperties ()
819 return GetProperties (DefaultBindingFlags);
822 public abstract PropertyInfo[] GetProperties (BindingFlags bindingAttr);
825 public PropertyInfo GetProperty (string name)
828 throw new ArgumentNullException ("name");
830 return GetPropertyImpl (name, DefaultBindingFlags, null, null, null, null);
833 public PropertyInfo GetProperty (string name, BindingFlags bindingAttr)
836 throw new ArgumentNullException ("name");
837 return GetPropertyImpl (name, bindingAttr, null, null, null, null);
840 public PropertyInfo GetProperty (string name, Type returnType)
843 throw new ArgumentNullException ("name");
844 return GetPropertyImpl (name, DefaultBindingFlags, null, returnType, null, null);
847 public PropertyInfo GetProperty (string name, Type[] types)
849 return GetProperty (name, DefaultBindingFlags, null, null, types, null);
852 public PropertyInfo GetProperty (string name, Type returnType, Type[] types)
854 return GetProperty (name, DefaultBindingFlags, null, returnType, types, null);
857 public PropertyInfo GetProperty( string name, Type returnType, Type[] types, ParameterModifier[] modifiers)
859 return GetProperty (name, DefaultBindingFlags, null, returnType, types, modifiers);
862 public PropertyInfo GetProperty (string name, BindingFlags bindingAttr, Binder binder, Type returnType,
863 Type[] types, ParameterModifier[] modifiers)
866 throw new ArgumentNullException ("name");
868 throw new ArgumentNullException ("types");
870 foreach (Type t in types) {
872 throw new ArgumentNullException ("types");
875 return GetPropertyImpl (name, bindingAttr, binder, returnType, types, modifiers);
878 protected abstract PropertyInfo GetPropertyImpl (string name, BindingFlags bindingAttr, Binder binder,
879 Type returnType, Type[] types, ParameterModifier[] modifiers);
881 internal PropertyInfo GetPropertyImplInternal (string name, BindingFlags bindingAttr, Binder binder,
882 Type returnType, Type[] types, ParameterModifier[] modifiers)
884 return GetPropertyImpl (name, bindingAttr, binder, returnType, types, modifiers);
887 protected abstract ConstructorInfo GetConstructorImpl (BindingFlags bindingAttr,
889 CallingConventions callConvention,
891 ParameterModifier[] modifiers);
893 protected abstract TypeAttributes GetAttributeFlagsImpl ();
894 protected abstract bool HasElementTypeImpl ();
895 protected abstract bool IsArrayImpl ();
896 protected abstract bool IsByRefImpl ();
897 protected abstract bool IsCOMObjectImpl ();
898 protected abstract bool IsPointerImpl ();
899 protected abstract bool IsPrimitiveImpl ();
901 [MethodImplAttribute(MethodImplOptions.InternalCall)]
902 internal static extern bool IsArrayImpl (Type type);
904 protected virtual bool IsValueTypeImpl ()
906 if (this == typeof (ValueType) || this == typeof (Enum))
909 return IsSubclassOf (typeof (ValueType));
912 protected virtual bool IsContextfulImpl ()
914 return typeof (ContextBoundObject).IsAssignableFrom (this);
917 protected virtual bool IsMarshalByRefImpl ()
919 return typeof (MarshalByRefObject).IsAssignableFrom (this);
925 public ConstructorInfo GetConstructor (Type[] types)
927 return GetConstructor (DefaultBindingFlags, null, CallingConventions.Any, types, null);
933 public ConstructorInfo GetConstructor (BindingFlags bindingAttr, Binder binder,
934 Type[] types, ParameterModifier[] modifiers)
936 return GetConstructor (bindingAttr, binder, CallingConventions.Any, types, modifiers);
942 public ConstructorInfo GetConstructor (BindingFlags bindingAttr, Binder binder,
943 CallingConventions callConvention,
944 Type[] types, ParameterModifier[] modifiers)
947 throw new ArgumentNullException ("types");
949 foreach (Type t in types) {
951 throw new ArgumentNullException ("types");
954 return GetConstructorImpl (bindingAttr, binder, callConvention, types, modifiers);
960 public ConstructorInfo[] GetConstructors ()
962 return GetConstructors (BindingFlags.Public | BindingFlags.Instance);
968 public abstract ConstructorInfo[] GetConstructors (BindingFlags bindingAttr);
970 public virtual MemberInfo[] GetDefaultMembers ()
972 object [] att = GetCustomAttributes (typeof (DefaultMemberAttribute), true);
974 return new MemberInfo [0];
976 MemberInfo [] member = GetMember (((DefaultMemberAttribute) att [0]).MemberName);
977 return (member != null) ? member : new MemberInfo [0];
980 public virtual MemberInfo[] FindMembers (MemberTypes memberType, BindingFlags bindingAttr,
981 MemberFilter filter, object filterCriteria)
984 ArrayList l = new ArrayList ();
986 // Console.WriteLine ("FindMembers for {0} (Type: {1}): {2}",
987 // this.FullName, this.GetType().FullName, this.obj_address());
989 if ((memberType & MemberTypes.Constructor) != 0) {
990 ConstructorInfo[] c = GetConstructors (bindingAttr);
991 if (filter != null) {
992 foreach (MemberInfo m in c) {
993 if (filter (m, filterCriteria))
1000 if ((memberType & MemberTypes.Event) != 0) {
1001 EventInfo[] c = GetEvents (bindingAttr);
1002 if (filter != null) {
1003 foreach (MemberInfo m in c) {
1004 if (filter (m, filterCriteria))
1011 if ((memberType & MemberTypes.Field) != 0) {
1012 FieldInfo[] c = GetFields (bindingAttr);
1013 if (filter != null) {
1014 foreach (MemberInfo m in c) {
1015 if (filter (m, filterCriteria))
1022 if ((memberType & MemberTypes.Method) != 0) {
1023 MethodInfo[] c = GetMethods (bindingAttr);
1024 if (filter != null) {
1025 foreach (MemberInfo m in c) {
1026 if (filter (m, filterCriteria))
1033 if ((memberType & MemberTypes.Property) != 0) {
1035 int count = l.Count;
1037 if (filter != null) {
1039 while ((l.Count == count) && (ptype != null)) {
1040 c = ptype.GetProperties (bindingAttr);
1041 foreach (MemberInfo m in c) {
1042 if (filter (m, filterCriteria))
1045 ptype = ptype.BaseType;
1048 c = GetProperties (bindingAttr);
1052 if ((memberType & MemberTypes.NestedType) != 0) {
1053 Type[] c = GetNestedTypes (bindingAttr);
1054 if (filter != null) {
1055 foreach (MemberInfo m in c) {
1056 if (filter (m, filterCriteria)) {
1064 result = new MemberInfo [l.Count];
1070 [DebuggerStepThrough]
1071 public object InvokeMember (string name, BindingFlags invokeAttr, Binder binder, object target, object[] args)
1073 return InvokeMember (name, invokeAttr, binder, target, args, null, null, null);
1077 [DebuggerStepThrough]
1078 public object InvokeMember (string name, BindingFlags invokeAttr, Binder binder,
1079 object target, object[] args, CultureInfo culture)
1081 return InvokeMember (name, invokeAttr, binder, target, args, null, culture, null);
1084 public abstract object InvokeMember (string name, BindingFlags invokeAttr,
1085 Binder binder, object target, object[] args,
1086 ParameterModifier[] modifiers,
1087 CultureInfo culture, string[] namedParameters);
1089 public override string ToString()
1094 internal bool IsSystemType {
1096 return _impl.Value != IntPtr.Zero;
1100 #if NET_2_0 || BOOTSTRAP_NET_2_0
1101 public virtual Type[] GetGenericArguments ()
1103 throw new NotSupportedException ();
1106 public abstract bool ContainsGenericParameters {
1110 public virtual extern bool IsGenericTypeDefinition {
1111 [MethodImplAttribute(MethodImplOptions.InternalCall)]
1115 [MethodImplAttribute(MethodImplOptions.InternalCall)]
1116 extern Type GetGenericTypeDefinition_impl ();
1118 public virtual Type GetGenericTypeDefinition ()
1120 Type res = GetGenericTypeDefinition_impl ();
1122 throw new InvalidOperationException ();
1127 public virtual extern bool IsGenericType {
1128 [MethodImplAttribute(MethodImplOptions.InternalCall)]
1132 [MethodImplAttribute(MethodImplOptions.InternalCall)]
1133 static extern Type MakeGenericType (Type gt, Type [] types);
1135 public virtual Type MakeGenericType (params Type[] types)
1138 throw new ArgumentNullException ("types");
1139 foreach (Type t in types) {
1141 throw new ArgumentNullException ("types");
1143 Type res = MakeGenericType (this, types);
1145 throw new TypeLoadException ();
1149 public virtual bool IsGenericParameter {
1155 public bool IsNested {
1157 return DeclaringType != null;
1161 public bool IsVisible {
1164 return DeclaringType.IsVisible;
1170 [MethodImplAttribute(MethodImplOptions.InternalCall)]
1171 extern int GetGenericParameterPosition ();
1173 public virtual int GenericParameterPosition {
1175 int res = GetGenericParameterPosition ();
1177 throw new InvalidOperationException ();
1182 [MethodImplAttribute(MethodImplOptions.InternalCall)]
1183 extern GenericParameterAttributes GetGenericParameterAttributes ();
1185 public virtual GenericParameterAttributes GenericParameterAttributes {
1187 if (!IsGenericParameter)
1188 throw new InvalidOperationException ();
1190 return GetGenericParameterAttributes ();
1194 [MethodImplAttribute(MethodImplOptions.InternalCall)]
1195 extern Type[] GetGenericParameterConstraints_impl ();
1197 public virtual Type[] GetGenericParameterConstraints ()
1199 if (!IsGenericParameter)
1200 throw new InvalidOperationException ();
1202 return GetGenericParameterConstraints_impl ();
1205 public virtual MethodBase DeclaringMethod {
1211 [MethodImplAttribute(MethodImplOptions.InternalCall)]
1212 extern Type make_array_type (int rank);
1214 public virtual Type MakeArrayType ()
1216 return MakeArrayType (1);
1219 public virtual Type MakeArrayType (int rank)
1222 throw new IndexOutOfRangeException ();
1223 return make_array_type (rank);
1226 [MethodImplAttribute(MethodImplOptions.InternalCall)]
1227 extern Type make_byref_type ();
1229 public virtual Type MakeByRefType ()
1231 return make_byref_type ();
1234 [MethodImplAttribute(MethodImplOptions.InternalCall)]
1235 public extern virtual Type MakePointerType ();
1238 public static Type ReflectionOnlyGetType (string typeName,
1239 bool throwIfNotFound,
1242 throw new NotImplementedException ();
1245 [MethodImplAttribute(MethodImplOptions.InternalCall)]
1246 extern void GetPacking (out int packing, out int size);
1248 public virtual StructLayoutAttribute StructLayoutAttribute {
1252 if (IsLayoutSequential)
1253 kind = LayoutKind.Sequential;
1254 else if (IsExplicitLayout)
1255 kind = LayoutKind.Explicit;
1257 kind = LayoutKind.Auto;
1259 StructLayoutAttribute attr = new StructLayoutAttribute (kind);
1262 attr.CharSet = CharSet.Unicode;
1263 else if (IsAnsiClass)
1264 attr.CharSet = CharSet.Ansi;
1266 attr.CharSet = CharSet.Auto;
1268 if (kind != LayoutKind.Auto)
1269 GetPacking (out attr.Pack, out attr.Size);
1275 internal object[] GetPseudoCustomAttributes ()
1279 /* IsSerializable returns true for delegates/enums as well */
1280 if ((Attributes & TypeAttributes.Serializable) != 0)
1282 if ((Attributes & TypeAttributes.Import) != 0)
1287 object[] attrs = new object [count];
1290 if ((Attributes & TypeAttributes.Serializable) != 0)
1291 attrs [count ++] = new SerializableAttribute ();
1292 if ((Attributes & TypeAttributes.Import) != 0)
1293 attrs [count ++] = new ComImportAttribute ();
1300 void _Type.GetIDsOfNames ([In] ref Guid riid, IntPtr rgszNames, uint cNames, uint lcid, IntPtr rgDispId)
1302 throw new NotImplementedException ();
1305 void _Type.GetTypeInfo (uint iTInfo, uint lcid, IntPtr ppTInfo)
1307 throw new NotImplementedException ();
1310 void _Type.GetTypeInfoCount (out uint pcTInfo)
1312 throw new NotImplementedException ();
1315 void _Type.Invoke (uint dispIdMember, [In] ref Guid riid, uint lcid, short wFlags, IntPtr pDispParams, IntPtr pVarResult, IntPtr pExcepInfo, IntPtr puArgErr)
1317 throw new NotImplementedException ();