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) {
472 /* MS.NET returns this */
473 return TypeCode.Empty;
475 type = type.UnderlyingSystemType;
477 if (!type.IsSystemType)
478 return Type.GetTypeCode (typeof (object));
480 return GetTypeCodeInternal (type);
484 public static Type GetTypeFromCLSID (Guid clsid)
486 throw new NotImplementedException ();
490 public static Type GetTypeFromCLSID (Guid clsid, bool throwOnError)
492 throw new NotImplementedException ();
496 public static Type GetTypeFromCLSID (Guid clsid, string server)
498 throw new NotImplementedException ();
502 public static Type GetTypeFromCLSID (Guid clsid, string server, bool throwOnError)
504 throw new NotImplementedException ();
507 public static Type GetTypeFromHandle (RuntimeTypeHandle handle)
509 return internal_from_handle (handle.Value);
513 public static Type GetTypeFromProgID (string progID)
515 throw new NotImplementedException ();
519 public static Type GetTypeFromProgID (string progID, bool throwOnError)
521 throw new NotImplementedException ();
525 public static Type GetTypeFromProgID (string progID, string server)
527 throw new NotImplementedException ();
531 public static Type GetTypeFromProgID (string progID, string server, bool throwOnError)
533 throw new NotImplementedException ();
536 public static RuntimeTypeHandle GetTypeHandle (object o)
538 return o.GetType().TypeHandle;
541 [MethodImplAttribute(MethodImplOptions.InternalCall)]
542 internal static extern bool type_is_subtype_of (Type a, Type b, bool check_interfaces);
544 [MethodImplAttribute(MethodImplOptions.InternalCall)]
545 internal static extern bool type_is_assignable_from (Type a, Type b);
547 internal static bool is_subtype_of (Type a, Type b, bool check_interfaces)
549 a = a.UnderlyingSystemType;
550 b = b.UnderlyingSystemType;
552 if (!a.IsSystemType || !b.IsSystemType)
555 return type_is_subtype_of (a, b, check_interfaces);
558 public new Type GetType ()
560 return base.GetType ();
566 public virtual bool IsSubclassOf (Type c)
571 return (this != c) && is_subtype_of (this, c, false);
574 public virtual Type[] FindInterfaces (TypeFilter filter, object filterCriteria)
577 throw new ArgumentNullException ("filter");
579 ArrayList ifaces = new ArrayList ();
580 foreach (Type iface in GetInterfaces ()) {
581 if (filter (iface, filterCriteria))
585 return (Type []) ifaces.ToArray (typeof (Type));
588 public Type GetInterface (string name) {
589 return GetInterface (name, false);
592 public abstract Type GetInterface (string name, bool ignoreCase);
594 [MethodImplAttribute(MethodImplOptions.InternalCall)]
595 internal static extern void GetInterfaceMapData (Type t, Type iface, out MethodInfo[] targets, out MethodInfo[] methods);
600 public virtual InterfaceMapping GetInterfaceMap (Type interfaceType) {
601 InterfaceMapping res;
602 if (interfaceType == null)
603 throw new ArgumentNullException ("interfaceType");
604 if (!interfaceType.IsInterface)
605 throw new ArgumentException (Locale.GetText ("Argument must be an interface."), "interfaceType");
606 res.TargetType = this;
607 res.InterfaceType = interfaceType;
608 GetInterfaceMapData (this, interfaceType, out res.TargetMethods, out res.InterfaceMethods);
609 if (res.TargetMethods == null)
610 throw new ArgumentException (Locale.GetText ("Interface not found"), "interfaceType");
615 public abstract Type[] GetInterfaces ();
617 public virtual bool IsAssignableFrom (Type c)
625 if (c is TypeBuilder)
626 return ((TypeBuilder)c).IsAssignableTo (this);
628 /* Handle user defined type classes */
630 Type systemType = UnderlyingSystemType;
631 if (!systemType.IsSystemType)
633 return systemType.IsAssignableFrom (c);
636 if (!c.IsSystemType) {
637 Type underlyingType = c.UnderlyingSystemType;
638 if (!underlyingType.IsSystemType)
640 return IsAssignableFrom (underlyingType);
643 return type_is_assignable_from (this, c);
646 [MethodImplAttribute(MethodImplOptions.InternalCall)]
647 public extern virtual bool IsInstanceOfType (object o);
649 public virtual int GetArrayRank ()
651 throw new NotSupportedException (); // according to MSDN
654 public abstract Type GetElementType ();
656 public EventInfo GetEvent (string name)
658 return GetEvent (name, DefaultBindingFlags);
661 public abstract EventInfo GetEvent (string name, BindingFlags bindingAttr);
663 public virtual EventInfo[] GetEvents ()
665 return GetEvents (DefaultBindingFlags);
668 public abstract EventInfo[] GetEvents (BindingFlags bindingAttr);
670 public FieldInfo GetField( string name)
672 return GetField (name, DefaultBindingFlags);
675 public abstract FieldInfo GetField( string name, BindingFlags bindingAttr);
677 public FieldInfo[] GetFields ()
679 return GetFields (DefaultBindingFlags);
682 public abstract FieldInfo[] GetFields (BindingFlags bindingAttr);
684 public override int GetHashCode()
686 return (int)_impl.Value;
689 public MemberInfo[] GetMember (string name)
691 return GetMember (name, DefaultBindingFlags);
694 public virtual MemberInfo[] GetMember (string name, BindingFlags bindingAttr)
696 return GetMember (name, MemberTypes.All, bindingAttr);
699 public virtual MemberInfo[] GetMember (string name, MemberTypes type, BindingFlags bindingAttr)
701 if ((bindingAttr & BindingFlags.IgnoreCase) != 0)
702 return FindMembers (type, bindingAttr, FilterNameIgnoreCase, name);
704 return FindMembers (type, bindingAttr, FilterName, name);
707 public MemberInfo[] GetMembers ()
709 return GetMembers (DefaultBindingFlags);
712 public abstract MemberInfo[] GetMembers (BindingFlags bindingAttr);
714 public MethodInfo GetMethod (string name)
717 throw new ArgumentNullException ("name");
718 return GetMethodImpl (name, DefaultBindingFlags, null, CallingConventions.Any, null, null);
721 public MethodInfo GetMethod (string name, BindingFlags bindingAttr)
724 throw new ArgumentNullException ("name");
726 return GetMethodImpl (name, bindingAttr, null, CallingConventions.Any, null, null);
729 public MethodInfo GetMethod (string name, Type[] types)
731 return GetMethod (name, DefaultBindingFlags, null, CallingConventions.Any, types, null);
734 public MethodInfo GetMethod (string name, Type[] types, ParameterModifier[] modifiers)
736 return GetMethod (name, DefaultBindingFlags, null, CallingConventions.Any, types, modifiers);
739 public MethodInfo GetMethod (string name, BindingFlags bindingAttr, Binder binder,
740 Type[] types, ParameterModifier[] modifiers)
743 return GetMethod (name, bindingAttr, binder, CallingConventions.Any, types, modifiers);
746 public MethodInfo GetMethod (string name, BindingFlags bindingAttr, Binder binder,
747 CallingConventions callConvention, Type[] types, ParameterModifier[] modifiers)
750 throw new ArgumentNullException ("name");
752 throw new ArgumentNullException ("types");
754 for (int i = 0; i < types.Length; i++)
755 if (types[i] == null)
756 throw new ArgumentNullException ("types");
758 return GetMethodImpl (name, bindingAttr, binder, callConvention, types, modifiers);
761 protected abstract MethodInfo GetMethodImpl (string name, BindingFlags bindingAttr, Binder binder,
762 CallingConventions callConvention, Type[] types,
763 ParameterModifier[] modifiers);
765 internal MethodInfo GetMethodImplInternal (string name, BindingFlags bindingAttr, Binder binder,
766 CallingConventions callConvention, Type[] types,
767 ParameterModifier[] modifiers)
769 return GetMethodImpl (name, bindingAttr, binder, callConvention, types, modifiers);
772 internal virtual MethodInfo GetMethod (MethodInfo fromNoninstanciated)
774 throw new System.InvalidOperationException ("can only be called in generic type");
777 internal virtual ConstructorInfo GetConstructor (ConstructorInfo fromNoninstanciated)
779 throw new System.InvalidOperationException ("can only be called in generic type");
782 internal virtual FieldInfo GetField (FieldInfo fromNoninstanciated)
784 throw new System.InvalidOperationException ("can only be called in generic type");
788 public MethodInfo[] GetMethods ()
790 return GetMethods (DefaultBindingFlags);
793 public abstract MethodInfo[] GetMethods (BindingFlags bindingAttr);
795 public Type GetNestedType (string name)
797 return GetNestedType (name, DefaultBindingFlags);
800 public abstract Type GetNestedType (string name, BindingFlags bindingAttr);
802 public Type[] GetNestedTypes ()
804 return GetNestedTypes (DefaultBindingFlags);
807 public abstract Type[] GetNestedTypes (BindingFlags bindingAttr);
810 public PropertyInfo[] GetProperties ()
812 return GetProperties (DefaultBindingFlags);
815 public abstract PropertyInfo[] GetProperties (BindingFlags bindingAttr);
818 public PropertyInfo GetProperty (string name)
821 throw new ArgumentNullException ("name");
823 return GetPropertyImpl (name, DefaultBindingFlags, null, null, null, null);
826 public PropertyInfo GetProperty (string name, BindingFlags bindingAttr)
829 throw new ArgumentNullException ("name");
830 return GetPropertyImpl (name, bindingAttr, null, null, null, null);
833 public PropertyInfo GetProperty (string name, Type returnType)
836 throw new ArgumentNullException ("name");
837 return GetPropertyImpl (name, DefaultBindingFlags, null, returnType, null, null);
840 public PropertyInfo GetProperty (string name, Type[] types)
842 return GetProperty (name, DefaultBindingFlags, null, null, types, null);
845 public PropertyInfo GetProperty (string name, Type returnType, Type[] types)
847 return GetProperty (name, DefaultBindingFlags, null, returnType, types, null);
850 public PropertyInfo GetProperty( string name, Type returnType, Type[] types, ParameterModifier[] modifiers)
852 return GetProperty (name, DefaultBindingFlags, null, returnType, types, modifiers);
855 public PropertyInfo GetProperty (string name, BindingFlags bindingAttr, Binder binder, Type returnType,
856 Type[] types, ParameterModifier[] modifiers)
859 throw new ArgumentNullException ("name");
861 throw new ArgumentNullException ("types");
863 foreach (Type t in types) {
865 throw new ArgumentNullException ("types");
868 return GetPropertyImpl (name, bindingAttr, binder, returnType, types, modifiers);
871 protected abstract PropertyInfo GetPropertyImpl (string name, BindingFlags bindingAttr, Binder binder,
872 Type returnType, Type[] types, ParameterModifier[] modifiers);
874 internal PropertyInfo GetPropertyImplInternal (string name, BindingFlags bindingAttr, Binder binder,
875 Type returnType, Type[] types, ParameterModifier[] modifiers)
877 return GetPropertyImpl (name, bindingAttr, binder, returnType, types, modifiers);
880 protected abstract ConstructorInfo GetConstructorImpl (BindingFlags bindingAttr,
882 CallingConventions callConvention,
884 ParameterModifier[] modifiers);
886 protected abstract TypeAttributes GetAttributeFlagsImpl ();
887 protected abstract bool HasElementTypeImpl ();
888 protected abstract bool IsArrayImpl ();
889 protected abstract bool IsByRefImpl ();
890 protected abstract bool IsCOMObjectImpl ();
891 protected abstract bool IsPointerImpl ();
892 protected abstract bool IsPrimitiveImpl ();
894 [MethodImplAttribute(MethodImplOptions.InternalCall)]
895 internal static extern bool IsArrayImpl (Type type);
897 protected virtual bool IsValueTypeImpl ()
899 if (this == typeof (Enum) || this == typeof (ValueType))
902 return IsSubclassOf (typeof (ValueType));
905 protected virtual bool IsContextfulImpl ()
907 return typeof (ContextBoundObject).IsAssignableFrom (this);
910 protected virtual bool IsMarshalByRefImpl ()
912 return typeof (MarshalByRefObject).IsAssignableFrom (this);
918 public ConstructorInfo GetConstructor (Type[] types)
920 return GetConstructor (DefaultBindingFlags, null, CallingConventions.Any, types, null);
926 public ConstructorInfo GetConstructor (BindingFlags bindingAttr, Binder binder,
927 Type[] types, ParameterModifier[] modifiers)
929 return GetConstructor (bindingAttr, binder, CallingConventions.Any, types, modifiers);
935 public ConstructorInfo GetConstructor (BindingFlags bindingAttr, Binder binder,
936 CallingConventions callConvention,
937 Type[] types, ParameterModifier[] modifiers)
940 throw new ArgumentNullException ("types");
942 foreach (Type t in types) {
944 throw new ArgumentNullException ("types");
947 return GetConstructorImpl (bindingAttr, binder, callConvention, types, modifiers);
953 public ConstructorInfo[] GetConstructors ()
955 return GetConstructors (BindingFlags.Public | BindingFlags.Instance);
961 public abstract ConstructorInfo[] GetConstructors (BindingFlags bindingAttr);
963 public virtual MemberInfo[] GetDefaultMembers ()
965 object [] att = GetCustomAttributes (typeof (DefaultMemberAttribute), true);
967 return new MemberInfo [0];
969 MemberInfo [] member = GetMember (((DefaultMemberAttribute) att [0]).MemberName);
970 return (member != null) ? member : new MemberInfo [0];
973 public virtual MemberInfo[] FindMembers (MemberTypes memberType, BindingFlags bindingAttr,
974 MemberFilter filter, object filterCriteria)
977 ArrayList l = new ArrayList ();
979 // Console.WriteLine ("FindMembers for {0} (Type: {1}): {2}",
980 // this.FullName, this.GetType().FullName, this.obj_address());
982 if ((memberType & MemberTypes.Constructor) != 0) {
983 ConstructorInfo[] c = GetConstructors (bindingAttr);
984 if (filter != null) {
985 foreach (MemberInfo m in c) {
986 if (filter (m, filterCriteria))
993 if ((memberType & MemberTypes.Event) != 0) {
994 EventInfo[] c = GetEvents (bindingAttr);
995 if (filter != null) {
996 foreach (MemberInfo m in c) {
997 if (filter (m, filterCriteria))
1004 if ((memberType & MemberTypes.Field) != 0) {
1005 FieldInfo[] c = GetFields (bindingAttr);
1006 if (filter != null) {
1007 foreach (MemberInfo m in c) {
1008 if (filter (m, filterCriteria))
1015 if ((memberType & MemberTypes.Method) != 0) {
1016 MethodInfo[] c = GetMethods (bindingAttr);
1017 if (filter != null) {
1018 foreach (MemberInfo m in c) {
1019 if (filter (m, filterCriteria))
1026 if ((memberType & MemberTypes.Property) != 0) {
1028 int count = l.Count;
1030 if (filter != null) {
1032 while ((l.Count == count) && (ptype != null)) {
1033 c = ptype.GetProperties (bindingAttr);
1034 foreach (MemberInfo m in c) {
1035 if (filter (m, filterCriteria))
1038 ptype = ptype.BaseType;
1041 c = GetProperties (bindingAttr);
1045 if ((memberType & MemberTypes.NestedType) != 0) {
1046 Type[] c = GetNestedTypes (bindingAttr);
1047 if (filter != null) {
1048 foreach (MemberInfo m in c) {
1049 if (filter (m, filterCriteria)) {
1057 result = new MemberInfo [l.Count];
1063 [DebuggerStepThrough]
1064 public object InvokeMember (string name, BindingFlags invokeAttr, Binder binder, object target, object[] args)
1066 return InvokeMember (name, invokeAttr, binder, target, args, null, null, null);
1070 [DebuggerStepThrough]
1071 public object InvokeMember (string name, BindingFlags invokeAttr, Binder binder,
1072 object target, object[] args, CultureInfo culture)
1074 return InvokeMember (name, invokeAttr, binder, target, args, null, culture, null);
1077 public abstract object InvokeMember (string name, BindingFlags invokeAttr,
1078 Binder binder, object target, object[] args,
1079 ParameterModifier[] modifiers,
1080 CultureInfo culture, string[] namedParameters);
1082 public override string ToString()
1087 internal bool IsSystemType {
1089 return _impl.Value != IntPtr.Zero;
1093 #if NET_2_0 || BOOTSTRAP_NET_2_0
1094 public virtual Type[] GetGenericArguments ()
1096 throw new NotSupportedException ();
1099 public abstract bool ContainsGenericParameters {
1103 public virtual extern bool IsGenericTypeDefinition {
1104 [MethodImplAttribute(MethodImplOptions.InternalCall)]
1108 [MethodImplAttribute(MethodImplOptions.InternalCall)]
1109 extern Type GetGenericTypeDefinition_impl ();
1111 public virtual Type GetGenericTypeDefinition ()
1113 Type res = GetGenericTypeDefinition_impl ();
1115 throw new InvalidOperationException ();
1120 public virtual extern bool IsGenericType {
1121 [MethodImplAttribute(MethodImplOptions.InternalCall)]
1125 [MethodImplAttribute(MethodImplOptions.InternalCall)]
1126 static extern Type MakeGenericType (Type gt, Type [] types);
1128 public virtual Type MakeGenericType (params Type[] types)
1131 throw new ArgumentNullException ("types");
1132 foreach (Type t in types) {
1134 throw new ArgumentNullException ("types");
1136 Type res = MakeGenericType (this, types);
1138 throw new TypeLoadException ();
1142 public virtual bool IsGenericParameter {
1148 public bool IsNested {
1150 return DeclaringType != null;
1154 public bool IsVisible {
1157 return DeclaringType.IsVisible;
1163 [MethodImplAttribute(MethodImplOptions.InternalCall)]
1164 extern int GetGenericParameterPosition ();
1166 public virtual int GenericParameterPosition {
1168 int res = GetGenericParameterPosition ();
1170 throw new InvalidOperationException ();
1175 [MethodImplAttribute(MethodImplOptions.InternalCall)]
1176 extern GenericParameterAttributes GetGenericParameterAttributes ();
1178 public virtual GenericParameterAttributes GenericParameterAttributes {
1180 if (!IsGenericParameter)
1181 throw new InvalidOperationException ();
1183 return GetGenericParameterAttributes ();
1187 [MethodImplAttribute(MethodImplOptions.InternalCall)]
1188 extern Type[] GetGenericParameterConstraints_impl ();
1190 public virtual Type[] GetGenericParameterConstraints ()
1192 if (!IsGenericParameter)
1193 throw new InvalidOperationException ();
1195 return GetGenericParameterConstraints_impl ();
1198 public virtual MethodBase DeclaringMethod {
1204 [MethodImplAttribute(MethodImplOptions.InternalCall)]
1205 extern Type make_array_type (int rank);
1207 public virtual Type MakeArrayType ()
1209 return MakeArrayType (1);
1212 public virtual Type MakeArrayType (int rank)
1215 throw new IndexOutOfRangeException ();
1216 return make_array_type (rank);
1219 [MethodImplAttribute(MethodImplOptions.InternalCall)]
1220 extern Type make_byref_type ();
1222 public virtual Type MakeByRefType ()
1224 return make_byref_type ();
1227 [MethodImplAttribute(MethodImplOptions.InternalCall)]
1228 public extern virtual Type MakePointerType ();
1231 public static Type ReflectionOnlyGetType (string typeName,
1232 bool throwIfNotFound,
1235 throw new NotImplementedException ();
1238 [MethodImplAttribute(MethodImplOptions.InternalCall)]
1239 extern void GetPacking (out int packing, out int size);
1241 public virtual StructLayoutAttribute StructLayoutAttribute {
1245 if (IsLayoutSequential)
1246 kind = LayoutKind.Sequential;
1247 else if (IsExplicitLayout)
1248 kind = LayoutKind.Explicit;
1250 kind = LayoutKind.Auto;
1252 StructLayoutAttribute attr = new StructLayoutAttribute (kind);
1255 attr.CharSet = CharSet.Unicode;
1256 else if (IsAnsiClass)
1257 attr.CharSet = CharSet.Ansi;
1259 attr.CharSet = CharSet.Auto;
1261 if (kind != LayoutKind.Auto)
1262 GetPacking (out attr.Pack, out attr.Size);
1268 internal object[] GetPseudoCustomAttributes ()
1272 /* IsSerializable returns true for delegates/enums as well */
1273 if ((Attributes & TypeAttributes.Serializable) != 0)
1275 if ((Attributes & TypeAttributes.Import) != 0)
1280 object[] attrs = new object [count];
1283 if ((Attributes & TypeAttributes.Serializable) != 0)
1284 attrs [count ++] = new SerializableAttribute ();
1285 if ((Attributes & TypeAttributes.Import) != 0)
1286 attrs [count ++] = new ComImportAttribute ();
1293 void _Type.GetIDsOfNames ([In] ref Guid riid, IntPtr rgszNames, uint cNames, uint lcid, IntPtr rgDispId)
1295 throw new NotImplementedException ();
1298 void _Type.GetTypeInfo (uint iTInfo, uint lcid, IntPtr ppTInfo)
1300 throw new NotImplementedException ();
1303 void _Type.GetTypeInfoCount (out uint pcTInfo)
1305 throw new NotImplementedException ();
1308 void _Type.Invoke (uint dispIdMember, [In] ref Guid riid, uint lcid, short wFlags, IntPtr pDispParams, IntPtr pVarResult, IntPtr pExcepInfo, IntPtr puArgErr)
1310 throw new NotImplementedException ();