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 Type cmp = o as Type;
423 public bool Equals (Type type) {
424 return UnderlyingSystemType.EqualsInternal (type.UnderlyingSystemType);
427 [MethodImplAttribute(MethodImplOptions.InternalCall)]
428 internal extern bool EqualsInternal (Type type);
430 [MethodImplAttribute(MethodImplOptions.InternalCall)]
431 private static extern Type internal_from_handle (IntPtr handle);
433 [MethodImplAttribute(MethodImplOptions.InternalCall)]
434 private static extern Type internal_from_name (string name, bool throwOnError, bool ignoreCase);
436 public static Type GetType(string typeName)
438 if (typeName == null)
439 throw new ArgumentNullException ("typeName");
441 return internal_from_name (typeName, false, false);
444 public static Type GetType(string typeName, bool throwOnError)
446 if (typeName == null)
447 throw new ArgumentNullException ("typeName");
449 Type type = internal_from_name (typeName, throwOnError, false);
450 if (throwOnError && type == null)
451 throw new TypeLoadException ("Error loading '" + typeName + "'");
456 public static Type GetType(string typeName, bool throwOnError, bool ignoreCase)
458 if (typeName == null)
459 throw new ArgumentNullException ("typeName");
461 Type t = internal_from_name (typeName, throwOnError, ignoreCase);
462 if (throwOnError && t == null)
463 throw new TypeLoadException ("Error loading '" + typeName + "'");
468 public static Type[] GetTypeArray (object[] args) {
470 throw new ArgumentNullException ("args");
473 ret = new Type [args.Length];
474 for (int i = 0; i < args.Length; ++i)
475 ret [i] = args[i].GetType ();
479 [MethodImplAttribute(MethodImplOptions.InternalCall)]
480 internal extern static TypeCode GetTypeCodeInternal (Type type);
482 public static TypeCode GetTypeCode (Type type) {
484 /* MS.NET returns this */
485 return TypeCode.Empty;
487 type = type.UnderlyingSystemType;
489 if (!type.IsSystemType)
490 return Type.GetTypeCode (typeof (object));
492 return GetTypeCodeInternal (type);
495 [MonoTODO("Mono does not support COM")]
496 public static Type GetTypeFromCLSID (Guid clsid)
498 throw new NotImplementedException ();
501 [MonoTODO("Mono does not support COM")]
502 public static Type GetTypeFromCLSID (Guid clsid, bool throwOnError)
504 throw new NotImplementedException ();
507 [MonoTODO("Mono does not support COM")]
508 public static Type GetTypeFromCLSID (Guid clsid, string server)
510 throw new NotImplementedException ();
513 [MonoTODO("Mono does not support COM")]
514 public static Type GetTypeFromCLSID (Guid clsid, string server, bool throwOnError)
516 throw new NotImplementedException ();
519 public static Type GetTypeFromHandle (RuntimeTypeHandle handle)
521 return internal_from_handle (handle.Value);
524 [MonoTODO("Mono does not support COM")]
525 public static Type GetTypeFromProgID (string progID)
527 throw new NotImplementedException ();
530 [MonoTODO("Mono does not support COM")]
531 public static Type GetTypeFromProgID (string progID, bool throwOnError)
533 throw new NotImplementedException ();
536 [MonoTODO("Mono does not support COM")]
537 public static Type GetTypeFromProgID (string progID, string server)
539 throw new NotImplementedException ();
542 [MonoTODO("Mono does not support COM")]
543 public static Type GetTypeFromProgID (string progID, string server, bool throwOnError)
545 throw new NotImplementedException ();
548 public static RuntimeTypeHandle GetTypeHandle (object o)
550 return o.GetType().TypeHandle;
553 [MethodImplAttribute(MethodImplOptions.InternalCall)]
554 internal static extern bool type_is_subtype_of (Type a, Type b, bool check_interfaces);
556 [MethodImplAttribute(MethodImplOptions.InternalCall)]
557 internal static extern bool type_is_assignable_from (Type a, Type b);
559 public new Type GetType ()
561 return base.GetType ();
567 public virtual bool IsSubclassOf (Type c)
569 if (c == null || c == this)
572 // Fast check for system types
574 return c.IsSystemType && type_is_subtype_of (this, c, false);
576 // User defined types depend on this behavior
577 for (Type type = BaseType; type != null; type = type.BaseType)
584 public virtual Type[] FindInterfaces (TypeFilter filter, object filterCriteria)
587 throw new ArgumentNullException ("filter");
589 ArrayList ifaces = new ArrayList ();
590 foreach (Type iface in GetInterfaces ()) {
591 if (filter (iface, filterCriteria))
595 return (Type []) ifaces.ToArray (typeof (Type));
598 public Type GetInterface (string name) {
599 return GetInterface (name, false);
602 public abstract Type GetInterface (string name, bool ignoreCase);
604 [MethodImplAttribute(MethodImplOptions.InternalCall)]
605 internal static extern void GetInterfaceMapData (Type t, Type iface, out MethodInfo[] targets, out MethodInfo[] methods);
610 public virtual InterfaceMapping GetInterfaceMap (Type interfaceType) {
611 InterfaceMapping res;
612 if (interfaceType == null)
613 throw new ArgumentNullException ("interfaceType");
614 if (!interfaceType.IsInterface)
615 throw new ArgumentException (Locale.GetText ("Argument must be an interface."), "interfaceType");
616 res.TargetType = this;
617 res.InterfaceType = interfaceType;
618 GetInterfaceMapData (this, interfaceType, out res.TargetMethods, out res.InterfaceMethods);
619 if (res.TargetMethods == null)
620 throw new ArgumentException (Locale.GetText ("Interface not found"), "interfaceType");
625 public abstract Type[] GetInterfaces ();
627 public virtual bool IsAssignableFrom (Type c)
635 if (c is TypeBuilder)
636 return ((TypeBuilder)c).IsAssignableTo (this);
638 /* Handle user defined type classes */
640 Type systemType = UnderlyingSystemType;
641 if (!systemType.IsSystemType)
643 return systemType.IsAssignableFrom (c);
646 if (!c.IsSystemType) {
647 Type underlyingType = c.UnderlyingSystemType;
648 if (!underlyingType.IsSystemType)
650 return IsAssignableFrom (underlyingType);
653 return type_is_assignable_from (this, c);
656 [MethodImplAttribute(MethodImplOptions.InternalCall)]
657 public extern virtual bool IsInstanceOfType (object o);
659 public virtual int GetArrayRank ()
661 throw new NotSupportedException (); // according to MSDN
664 public abstract Type GetElementType ();
666 public EventInfo GetEvent (string name)
668 return GetEvent (name, DefaultBindingFlags);
671 public abstract EventInfo GetEvent (string name, BindingFlags bindingAttr);
673 public virtual EventInfo[] GetEvents ()
675 return GetEvents (DefaultBindingFlags);
678 public abstract EventInfo[] GetEvents (BindingFlags bindingAttr);
680 public FieldInfo GetField( string name)
682 return GetField (name, DefaultBindingFlags);
685 public abstract FieldInfo GetField( string name, BindingFlags bindingAttr);
687 public FieldInfo[] GetFields ()
689 return GetFields (DefaultBindingFlags);
692 public abstract FieldInfo[] GetFields (BindingFlags bindingAttr);
694 public override int GetHashCode()
696 return (int)_impl.Value;
699 public MemberInfo[] GetMember (string name)
701 return GetMember (name, DefaultBindingFlags);
704 public virtual MemberInfo[] GetMember (string name, BindingFlags bindingAttr)
706 return GetMember (name, MemberTypes.All, bindingAttr);
709 public virtual MemberInfo[] GetMember (string name, MemberTypes type, BindingFlags bindingAttr)
711 if ((bindingAttr & BindingFlags.IgnoreCase) != 0)
712 return FindMembers (type, bindingAttr, FilterNameIgnoreCase, name);
714 return FindMembers (type, bindingAttr, FilterName, name);
717 public MemberInfo[] GetMembers ()
719 return GetMembers (DefaultBindingFlags);
722 public abstract MemberInfo[] GetMembers (BindingFlags bindingAttr);
724 public MethodInfo GetMethod (string name)
727 throw new ArgumentNullException ("name");
728 return GetMethodImpl (name, DefaultBindingFlags, null, CallingConventions.Any, null, null);
731 public MethodInfo GetMethod (string name, BindingFlags bindingAttr)
734 throw new ArgumentNullException ("name");
736 return GetMethodImpl (name, bindingAttr, null, CallingConventions.Any, null, null);
739 public MethodInfo GetMethod (string name, Type[] types)
741 return GetMethod (name, DefaultBindingFlags, null, CallingConventions.Any, types, null);
744 public MethodInfo GetMethod (string name, Type[] types, ParameterModifier[] modifiers)
746 return GetMethod (name, DefaultBindingFlags, null, CallingConventions.Any, types, modifiers);
749 public MethodInfo GetMethod (string name, BindingFlags bindingAttr, Binder binder,
750 Type[] types, ParameterModifier[] modifiers)
753 return GetMethod (name, bindingAttr, binder, CallingConventions.Any, types, modifiers);
756 public MethodInfo GetMethod (string name, BindingFlags bindingAttr, Binder binder,
757 CallingConventions callConvention, Type[] types, ParameterModifier[] modifiers)
760 throw new ArgumentNullException ("name");
762 throw new ArgumentNullException ("types");
764 for (int i = 0; i < types.Length; i++)
765 if (types[i] == null)
766 throw new ArgumentNullException ("types");
768 return GetMethodImpl (name, bindingAttr, binder, callConvention, types, modifiers);
771 protected abstract MethodInfo GetMethodImpl (string name, BindingFlags bindingAttr, Binder binder,
772 CallingConventions callConvention, Type[] types,
773 ParameterModifier[] modifiers);
775 internal MethodInfo GetMethodImplInternal (string name, BindingFlags bindingAttr, Binder binder,
776 CallingConventions callConvention, Type[] types,
777 ParameterModifier[] modifiers)
779 return GetMethodImpl (name, bindingAttr, binder, callConvention, types, modifiers);
782 internal virtual MethodInfo GetMethod (MethodInfo fromNoninstanciated)
784 throw new System.InvalidOperationException ("can only be called in generic type");
787 internal virtual ConstructorInfo GetConstructor (ConstructorInfo fromNoninstanciated)
789 throw new System.InvalidOperationException ("can only be called in generic type");
792 internal virtual FieldInfo GetField (FieldInfo fromNoninstanciated)
794 throw new System.InvalidOperationException ("can only be called in generic type");
798 public MethodInfo[] GetMethods ()
800 return GetMethods (DefaultBindingFlags);
803 public abstract MethodInfo[] GetMethods (BindingFlags bindingAttr);
805 public Type GetNestedType (string name)
807 return GetNestedType (name, DefaultBindingFlags);
810 public abstract Type GetNestedType (string name, BindingFlags bindingAttr);
812 public Type[] GetNestedTypes ()
814 return GetNestedTypes (DefaultBindingFlags);
817 public abstract Type[] GetNestedTypes (BindingFlags bindingAttr);
820 public PropertyInfo[] GetProperties ()
822 return GetProperties (DefaultBindingFlags);
825 public abstract PropertyInfo[] GetProperties (BindingFlags bindingAttr);
828 public PropertyInfo GetProperty (string name)
831 throw new ArgumentNullException ("name");
833 return GetPropertyImpl (name, DefaultBindingFlags, null, null, null, null);
836 public PropertyInfo GetProperty (string name, BindingFlags bindingAttr)
839 throw new ArgumentNullException ("name");
840 return GetPropertyImpl (name, bindingAttr, null, null, null, null);
843 public PropertyInfo GetProperty (string name, Type returnType)
846 throw new ArgumentNullException ("name");
847 return GetPropertyImpl (name, DefaultBindingFlags, null, returnType, null, null);
850 public PropertyInfo GetProperty (string name, Type[] types)
852 return GetProperty (name, DefaultBindingFlags, null, null, types, null);
855 public PropertyInfo GetProperty (string name, Type returnType, Type[] types)
857 return GetProperty (name, DefaultBindingFlags, null, returnType, types, null);
860 public PropertyInfo GetProperty( string name, Type returnType, Type[] types, ParameterModifier[] modifiers)
862 return GetProperty (name, DefaultBindingFlags, null, returnType, types, modifiers);
865 public PropertyInfo GetProperty (string name, BindingFlags bindingAttr, Binder binder, Type returnType,
866 Type[] types, ParameterModifier[] modifiers)
869 throw new ArgumentNullException ("name");
871 throw new ArgumentNullException ("types");
873 foreach (Type t in types) {
875 throw new ArgumentNullException ("types");
878 return GetPropertyImpl (name, bindingAttr, binder, returnType, types, modifiers);
881 protected abstract PropertyInfo GetPropertyImpl (string name, BindingFlags bindingAttr, Binder binder,
882 Type returnType, Type[] types, ParameterModifier[] modifiers);
884 internal PropertyInfo GetPropertyImplInternal (string name, BindingFlags bindingAttr, Binder binder,
885 Type returnType, Type[] types, ParameterModifier[] modifiers)
887 return GetPropertyImpl (name, bindingAttr, binder, returnType, types, modifiers);
890 protected abstract ConstructorInfo GetConstructorImpl (BindingFlags bindingAttr,
892 CallingConventions callConvention,
894 ParameterModifier[] modifiers);
896 protected abstract TypeAttributes GetAttributeFlagsImpl ();
897 protected abstract bool HasElementTypeImpl ();
898 protected abstract bool IsArrayImpl ();
899 protected abstract bool IsByRefImpl ();
900 protected abstract bool IsCOMObjectImpl ();
901 protected abstract bool IsPointerImpl ();
902 protected abstract bool IsPrimitiveImpl ();
904 [MethodImplAttribute(MethodImplOptions.InternalCall)]
905 internal static extern bool IsArrayImpl (Type type);
907 protected virtual bool IsValueTypeImpl ()
909 if (this == typeof (ValueType) || this == typeof (Enum))
912 return IsSubclassOf (typeof (ValueType));
915 protected virtual bool IsContextfulImpl ()
917 return typeof (ContextBoundObject).IsAssignableFrom (this);
920 protected virtual bool IsMarshalByRefImpl ()
922 return typeof (MarshalByRefObject).IsAssignableFrom (this);
928 public ConstructorInfo GetConstructor (Type[] types)
930 return GetConstructor (DefaultBindingFlags, null, CallingConventions.Any, types, null);
936 public ConstructorInfo GetConstructor (BindingFlags bindingAttr, Binder binder,
937 Type[] types, ParameterModifier[] modifiers)
939 return GetConstructor (bindingAttr, binder, CallingConventions.Any, types, modifiers);
945 public ConstructorInfo GetConstructor (BindingFlags bindingAttr, Binder binder,
946 CallingConventions callConvention,
947 Type[] types, ParameterModifier[] modifiers)
950 throw new ArgumentNullException ("types");
952 foreach (Type t in types) {
954 throw new ArgumentNullException ("types");
957 return GetConstructorImpl (bindingAttr, binder, callConvention, types, modifiers);
963 public ConstructorInfo[] GetConstructors ()
965 return GetConstructors (BindingFlags.Public | BindingFlags.Instance);
971 public abstract ConstructorInfo[] GetConstructors (BindingFlags bindingAttr);
973 public virtual MemberInfo[] GetDefaultMembers ()
975 object [] att = GetCustomAttributes (typeof (DefaultMemberAttribute), true);
977 return new MemberInfo [0];
979 MemberInfo [] member = GetMember (((DefaultMemberAttribute) att [0]).MemberName);
980 return (member != null) ? member : new MemberInfo [0];
983 public virtual MemberInfo[] FindMembers (MemberTypes memberType, BindingFlags bindingAttr,
984 MemberFilter filter, object filterCriteria)
987 ArrayList l = new ArrayList ();
989 // Console.WriteLine ("FindMembers for {0} (Type: {1}): {2}",
990 // this.FullName, this.GetType().FullName, this.obj_address());
992 if ((memberType & MemberTypes.Constructor) != 0) {
993 ConstructorInfo[] c = GetConstructors (bindingAttr);
994 if (filter != null) {
995 foreach (MemberInfo m in c) {
996 if (filter (m, filterCriteria))
1003 if ((memberType & MemberTypes.Event) != 0) {
1004 EventInfo[] c = GetEvents (bindingAttr);
1005 if (filter != null) {
1006 foreach (MemberInfo m in c) {
1007 if (filter (m, filterCriteria))
1014 if ((memberType & MemberTypes.Field) != 0) {
1015 FieldInfo[] c = GetFields (bindingAttr);
1016 if (filter != null) {
1017 foreach (MemberInfo m in c) {
1018 if (filter (m, filterCriteria))
1025 if ((memberType & MemberTypes.Method) != 0) {
1026 MethodInfo[] c = GetMethods (bindingAttr);
1027 if (filter != null) {
1028 foreach (MemberInfo m in c) {
1029 if (filter (m, filterCriteria))
1036 if ((memberType & MemberTypes.Property) != 0) {
1038 int count = l.Count;
1040 if (filter != null) {
1042 while ((l.Count == count) && (ptype != null)) {
1043 c = ptype.GetProperties (bindingAttr);
1044 foreach (MemberInfo m in c) {
1045 if (filter (m, filterCriteria))
1048 ptype = ptype.BaseType;
1051 c = GetProperties (bindingAttr);
1055 if ((memberType & MemberTypes.NestedType) != 0) {
1056 Type[] c = GetNestedTypes (bindingAttr);
1057 if (filter != null) {
1058 foreach (MemberInfo m in c) {
1059 if (filter (m, filterCriteria)) {
1067 result = new MemberInfo [l.Count];
1073 [DebuggerStepThrough]
1074 public object InvokeMember (string name, BindingFlags invokeAttr, Binder binder, object target, object[] args)
1076 return InvokeMember (name, invokeAttr, binder, target, args, null, null, null);
1080 [DebuggerStepThrough]
1081 public object InvokeMember (string name, BindingFlags invokeAttr, Binder binder,
1082 object target, object[] args, CultureInfo culture)
1084 return InvokeMember (name, invokeAttr, binder, target, args, null, culture, null);
1087 public abstract object InvokeMember (string name, BindingFlags invokeAttr,
1088 Binder binder, object target, object[] args,
1089 ParameterModifier[] modifiers,
1090 CultureInfo culture, string[] namedParameters);
1092 public override string ToString()
1097 internal bool IsSystemType {
1099 return _impl.Value != IntPtr.Zero;
1103 #if NET_2_0 || BOOTSTRAP_NET_2_0
1104 public virtual Type[] GetGenericArguments ()
1106 throw new NotSupportedException ();
1109 public abstract bool ContainsGenericParameters {
1113 public virtual extern bool IsGenericTypeDefinition {
1114 [MethodImplAttribute(MethodImplOptions.InternalCall)]
1118 [MethodImplAttribute(MethodImplOptions.InternalCall)]
1119 extern Type GetGenericTypeDefinition_impl ();
1121 public virtual Type GetGenericTypeDefinition ()
1123 Type res = GetGenericTypeDefinition_impl ();
1125 throw new InvalidOperationException ();
1130 public virtual extern bool IsGenericType {
1131 [MethodImplAttribute(MethodImplOptions.InternalCall)]
1135 [MethodImplAttribute(MethodImplOptions.InternalCall)]
1136 static extern Type MakeGenericType (Type gt, Type [] types);
1138 public virtual Type MakeGenericType (params Type[] types)
1140 if (!IsGenericTypeDefinition)
1141 throw new InvalidOperationException ("not a generic type definition");
1143 throw new ArgumentNullException ("types");
1144 foreach (Type t in types) {
1146 throw new ArgumentNullException ("types");
1148 Type res = MakeGenericType (this, types);
1150 throw new TypeLoadException ();
1154 public virtual bool IsGenericParameter {
1160 public bool IsNested {
1162 return DeclaringType != null;
1166 public bool IsVisible {
1169 return DeclaringType.IsVisible;
1175 [MethodImplAttribute(MethodImplOptions.InternalCall)]
1176 extern int GetGenericParameterPosition ();
1178 public virtual int GenericParameterPosition {
1180 int res = GetGenericParameterPosition ();
1182 throw new InvalidOperationException ();
1187 [MethodImplAttribute(MethodImplOptions.InternalCall)]
1188 extern GenericParameterAttributes GetGenericParameterAttributes ();
1190 public virtual GenericParameterAttributes GenericParameterAttributes {
1192 if (!IsGenericParameter)
1193 throw new InvalidOperationException ();
1195 return GetGenericParameterAttributes ();
1199 [MethodImplAttribute(MethodImplOptions.InternalCall)]
1200 extern Type[] GetGenericParameterConstraints_impl ();
1202 public virtual Type[] GetGenericParameterConstraints ()
1204 if (!IsGenericParameter)
1205 throw new InvalidOperationException ();
1207 return GetGenericParameterConstraints_impl ();
1210 public virtual MethodBase DeclaringMethod {
1216 [MethodImplAttribute(MethodImplOptions.InternalCall)]
1217 extern Type make_array_type (int rank);
1219 public virtual Type MakeArrayType ()
1221 return MakeArrayType (1);
1224 public virtual Type MakeArrayType (int rank)
1227 throw new IndexOutOfRangeException ();
1228 return make_array_type (rank);
1231 [MethodImplAttribute(MethodImplOptions.InternalCall)]
1232 extern Type make_byref_type ();
1234 public virtual Type MakeByRefType ()
1236 return make_byref_type ();
1239 [MethodImplAttribute(MethodImplOptions.InternalCall)]
1240 public extern virtual Type MakePointerType ();
1242 [MonoTODO("Not implemented")]
1243 public static Type ReflectionOnlyGetType (string typeName,
1244 bool throwIfNotFound,
1247 throw new NotImplementedException ();
1250 [MethodImplAttribute(MethodImplOptions.InternalCall)]
1251 extern void GetPacking (out int packing, out int size);
1253 public virtual StructLayoutAttribute StructLayoutAttribute {
1257 if (IsLayoutSequential)
1258 kind = LayoutKind.Sequential;
1259 else if (IsExplicitLayout)
1260 kind = LayoutKind.Explicit;
1262 kind = LayoutKind.Auto;
1264 StructLayoutAttribute attr = new StructLayoutAttribute (kind);
1267 attr.CharSet = CharSet.Unicode;
1268 else if (IsAnsiClass)
1269 attr.CharSet = CharSet.Ansi;
1271 attr.CharSet = CharSet.Auto;
1273 if (kind != LayoutKind.Auto)
1274 GetPacking (out attr.Pack, out attr.Size);
1280 internal object[] GetPseudoCustomAttributes ()
1284 /* IsSerializable returns true for delegates/enums as well */
1285 if ((Attributes & TypeAttributes.Serializable) != 0)
1287 if ((Attributes & TypeAttributes.Import) != 0)
1292 object[] attrs = new object [count];
1295 if ((Attributes & TypeAttributes.Serializable) != 0)
1296 attrs [count ++] = new SerializableAttribute ();
1297 if ((Attributes & TypeAttributes.Import) != 0)
1298 attrs [count ++] = new ComImportAttribute ();
1305 void _Type.GetIDsOfNames ([In] ref Guid riid, IntPtr rgszNames, uint cNames, uint lcid, IntPtr rgDispId)
1307 throw new NotImplementedException ();
1310 void _Type.GetTypeInfo (uint iTInfo, uint lcid, IntPtr ppTInfo)
1312 throw new NotImplementedException ();
1315 void _Type.GetTypeInfoCount (out uint pcTInfo)
1317 throw new NotImplementedException ();
1320 void _Type.Invoke (uint dispIdMember, [In] ref Guid riid, uint lcid, short wFlags, IntPtr pDispParams, IntPtr pVarResult, IntPtr pExcepInfo, IntPtr puArgErr)
1322 throw new NotImplementedException ();