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 {
395 public virtual RuntimeTypeHandle TypeHandle {
396 get { return default (RuntimeTypeHandle); }
399 public abstract RuntimeTypeHandle TypeHandle {get;}
405 public ConstructorInfo TypeInitializer {
407 return GetConstructorImpl (
408 BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static,
410 CallingConventions.Any,
416 public abstract Type UnderlyingSystemType {get;}
418 public override bool Equals (object o)
423 Type cmp = o as Type;
429 public bool Equals (Type type) {
432 return UnderlyingSystemType.EqualsInternal (type.UnderlyingSystemType);
435 [MethodImplAttribute(MethodImplOptions.InternalCall)]
436 internal extern bool EqualsInternal (Type type);
438 [MethodImplAttribute(MethodImplOptions.InternalCall)]
439 private static extern Type internal_from_handle (IntPtr handle);
441 [MethodImplAttribute(MethodImplOptions.InternalCall)]
442 private static extern Type internal_from_name (string name, bool throwOnError, bool ignoreCase);
444 public static Type GetType(string typeName)
446 if (typeName == null)
447 throw new ArgumentNullException ("typeName");
449 return internal_from_name (typeName, false, false);
452 public static Type GetType(string typeName, bool throwOnError)
454 if (typeName == null)
455 throw new ArgumentNullException ("typeName");
457 Type type = internal_from_name (typeName, throwOnError, false);
458 if (throwOnError && type == null)
459 throw new TypeLoadException ("Error loading '" + typeName + "'");
464 public static Type GetType(string typeName, bool throwOnError, bool ignoreCase)
466 if (typeName == null)
467 throw new ArgumentNullException ("typeName");
469 Type t = internal_from_name (typeName, throwOnError, ignoreCase);
470 if (throwOnError && t == null)
471 throw new TypeLoadException ("Error loading '" + typeName + "'");
476 public static Type[] GetTypeArray (object[] args) {
478 throw new ArgumentNullException ("args");
481 ret = new Type [args.Length];
482 for (int i = 0; i < args.Length; ++i)
483 ret [i] = args[i].GetType ();
487 [MethodImplAttribute(MethodImplOptions.InternalCall)]
488 internal extern static TypeCode GetTypeCodeInternal (Type type);
490 public static TypeCode GetTypeCode (Type type) {
492 /* MS.NET returns this */
493 return TypeCode.Empty;
495 type = type.UnderlyingSystemType;
497 if (!type.IsSystemType)
498 return Type.GetTypeCode (typeof (object));
500 return GetTypeCodeInternal (type);
503 [MonoTODO("Mono does not support COM")]
504 public static Type GetTypeFromCLSID (Guid clsid)
506 throw new NotImplementedException ();
509 [MonoTODO("Mono does not support COM")]
510 public static Type GetTypeFromCLSID (Guid clsid, bool throwOnError)
512 throw new NotImplementedException ();
515 [MonoTODO("Mono does not support COM")]
516 public static Type GetTypeFromCLSID (Guid clsid, string server)
518 throw new NotImplementedException ();
521 [MonoTODO("Mono does not support COM")]
522 public static Type GetTypeFromCLSID (Guid clsid, string server, bool throwOnError)
524 throw new NotImplementedException ();
527 public static Type GetTypeFromHandle (RuntimeTypeHandle handle)
529 return internal_from_handle (handle.Value);
532 [MonoTODO("Mono does not support COM")]
533 public static Type GetTypeFromProgID (string progID)
535 throw new NotImplementedException ();
538 [MonoTODO("Mono does not support COM")]
539 public static Type GetTypeFromProgID (string progID, bool throwOnError)
541 throw new NotImplementedException ();
544 [MonoTODO("Mono does not support COM")]
545 public static Type GetTypeFromProgID (string progID, string server)
547 throw new NotImplementedException ();
550 [MonoTODO("Mono does not support COM")]
551 public static Type GetTypeFromProgID (string progID, string server, bool throwOnError)
553 throw new NotImplementedException ();
556 public static RuntimeTypeHandle GetTypeHandle (object o)
558 return o.GetType().TypeHandle;
561 [MethodImplAttribute(MethodImplOptions.InternalCall)]
562 internal static extern bool type_is_subtype_of (Type a, Type b, bool check_interfaces);
564 [MethodImplAttribute(MethodImplOptions.InternalCall)]
565 internal static extern bool type_is_assignable_from (Type a, Type b);
567 public new Type GetType ()
569 return base.GetType ();
575 public virtual bool IsSubclassOf (Type c)
577 if (c == null || c == this)
580 // Fast check for system types
582 return c.IsSystemType && type_is_subtype_of (this, c, false);
584 // User defined types depend on this behavior
585 for (Type type = BaseType; type != null; type = type.BaseType)
592 public virtual Type[] FindInterfaces (TypeFilter filter, object filterCriteria)
595 throw new ArgumentNullException ("filter");
597 ArrayList ifaces = new ArrayList ();
598 foreach (Type iface in GetInterfaces ()) {
599 if (filter (iface, filterCriteria))
603 return (Type []) ifaces.ToArray (typeof (Type));
606 public Type GetInterface (string name) {
607 return GetInterface (name, false);
610 public abstract Type GetInterface (string name, bool ignoreCase);
612 [MethodImplAttribute(MethodImplOptions.InternalCall)]
613 internal static extern void GetInterfaceMapData (Type t, Type iface, out MethodInfo[] targets, out MethodInfo[] methods);
618 public virtual InterfaceMapping GetInterfaceMap (Type interfaceType) {
619 InterfaceMapping res;
620 if (interfaceType == null)
621 throw new ArgumentNullException ("interfaceType");
622 if (!interfaceType.IsInterface)
623 throw new ArgumentException (Locale.GetText ("Argument must be an interface."), "interfaceType");
624 res.TargetType = this;
625 res.InterfaceType = interfaceType;
626 GetInterfaceMapData (this, interfaceType, out res.TargetMethods, out res.InterfaceMethods);
627 if (res.TargetMethods == null)
628 throw new ArgumentException (Locale.GetText ("Interface not found"), "interfaceType");
633 public abstract Type[] GetInterfaces ();
635 public virtual bool IsAssignableFrom (Type c)
643 if (c is TypeBuilder)
644 return ((TypeBuilder)c).IsAssignableTo (this);
646 /* Handle user defined type classes */
648 Type systemType = UnderlyingSystemType;
649 if (!systemType.IsSystemType)
651 return systemType.IsAssignableFrom (c);
654 if (!c.IsSystemType) {
655 Type underlyingType = c.UnderlyingSystemType;
656 if (!underlyingType.IsSystemType)
658 return IsAssignableFrom (underlyingType);
661 return type_is_assignable_from (this, c);
664 [MethodImplAttribute(MethodImplOptions.InternalCall)]
665 public extern virtual bool IsInstanceOfType (object o);
667 public virtual int GetArrayRank ()
669 throw new NotSupportedException (); // according to MSDN
672 public abstract Type GetElementType ();
674 public EventInfo GetEvent (string name)
676 return GetEvent (name, DefaultBindingFlags);
679 public abstract EventInfo GetEvent (string name, BindingFlags bindingAttr);
681 public virtual EventInfo[] GetEvents ()
683 return GetEvents (DefaultBindingFlags);
686 public abstract EventInfo[] GetEvents (BindingFlags bindingAttr);
688 public FieldInfo GetField( string name)
690 return GetField (name, DefaultBindingFlags);
693 public abstract FieldInfo GetField( string name, BindingFlags bindingAttr);
695 public FieldInfo[] GetFields ()
697 return GetFields (DefaultBindingFlags);
700 public abstract FieldInfo[] GetFields (BindingFlags bindingAttr);
702 public override int GetHashCode()
704 return (int)_impl.Value;
707 public MemberInfo[] GetMember (string name)
709 return GetMember (name, DefaultBindingFlags);
712 public virtual MemberInfo[] GetMember (string name, BindingFlags bindingAttr)
714 return GetMember (name, MemberTypes.All, bindingAttr);
717 public virtual MemberInfo[] GetMember (string name, MemberTypes type, BindingFlags bindingAttr)
719 if ((bindingAttr & BindingFlags.IgnoreCase) != 0)
720 return FindMembers (type, bindingAttr, FilterNameIgnoreCase, name);
722 return FindMembers (type, bindingAttr, FilterName, name);
725 public MemberInfo[] GetMembers ()
727 return GetMembers (DefaultBindingFlags);
730 public abstract MemberInfo[] GetMembers (BindingFlags bindingAttr);
732 public MethodInfo GetMethod (string name)
735 throw new ArgumentNullException ("name");
736 return GetMethodImpl (name, DefaultBindingFlags, null, CallingConventions.Any, null, null);
739 public MethodInfo GetMethod (string name, BindingFlags bindingAttr)
742 throw new ArgumentNullException ("name");
744 return GetMethodImpl (name, bindingAttr, null, CallingConventions.Any, null, null);
747 public MethodInfo GetMethod (string name, Type[] types)
749 return GetMethod (name, DefaultBindingFlags, null, CallingConventions.Any, types, null);
752 public MethodInfo GetMethod (string name, Type[] types, ParameterModifier[] modifiers)
754 return GetMethod (name, DefaultBindingFlags, null, CallingConventions.Any, types, modifiers);
757 public MethodInfo GetMethod (string name, BindingFlags bindingAttr, Binder binder,
758 Type[] types, ParameterModifier[] modifiers)
761 return GetMethod (name, bindingAttr, binder, CallingConventions.Any, types, modifiers);
764 public MethodInfo GetMethod (string name, BindingFlags bindingAttr, Binder binder,
765 CallingConventions callConvention, Type[] types, ParameterModifier[] modifiers)
768 throw new ArgumentNullException ("name");
770 throw new ArgumentNullException ("types");
772 for (int i = 0; i < types.Length; i++)
773 if (types[i] == null)
774 throw new ArgumentNullException ("types");
776 return GetMethodImpl (name, bindingAttr, binder, callConvention, types, modifiers);
779 protected abstract MethodInfo GetMethodImpl (string name, BindingFlags bindingAttr, Binder binder,
780 CallingConventions callConvention, Type[] types,
781 ParameterModifier[] modifiers);
783 internal MethodInfo GetMethodImplInternal (string name, BindingFlags bindingAttr, Binder binder,
784 CallingConventions callConvention, Type[] types,
785 ParameterModifier[] modifiers)
787 return GetMethodImpl (name, bindingAttr, binder, callConvention, types, modifiers);
790 internal virtual MethodInfo GetMethod (MethodInfo fromNoninstanciated)
792 throw new System.InvalidOperationException ("can only be called in generic type");
795 internal virtual ConstructorInfo GetConstructor (ConstructorInfo fromNoninstanciated)
797 throw new System.InvalidOperationException ("can only be called in generic type");
800 internal virtual FieldInfo GetField (FieldInfo fromNoninstanciated)
802 throw new System.InvalidOperationException ("can only be called in generic type");
806 public MethodInfo[] GetMethods ()
808 return GetMethods (DefaultBindingFlags);
811 public abstract MethodInfo[] GetMethods (BindingFlags bindingAttr);
813 public Type GetNestedType (string name)
815 return GetNestedType (name, DefaultBindingFlags);
818 public abstract Type GetNestedType (string name, BindingFlags bindingAttr);
820 public Type[] GetNestedTypes ()
822 return GetNestedTypes (DefaultBindingFlags);
825 public abstract Type[] GetNestedTypes (BindingFlags bindingAttr);
828 public PropertyInfo[] GetProperties ()
830 return GetProperties (DefaultBindingFlags);
833 public abstract PropertyInfo[] GetProperties (BindingFlags bindingAttr);
836 public PropertyInfo GetProperty (string name)
839 throw new ArgumentNullException ("name");
841 return GetPropertyImpl (name, DefaultBindingFlags, null, null, null, null);
844 public PropertyInfo GetProperty (string name, BindingFlags bindingAttr)
847 throw new ArgumentNullException ("name");
848 return GetPropertyImpl (name, bindingAttr, null, null, null, null);
851 public PropertyInfo GetProperty (string name, Type returnType)
854 throw new ArgumentNullException ("name");
855 return GetPropertyImpl (name, DefaultBindingFlags, null, returnType, null, null);
858 public PropertyInfo GetProperty (string name, Type[] types)
860 return GetProperty (name, DefaultBindingFlags, null, null, types, null);
863 public PropertyInfo GetProperty (string name, Type returnType, Type[] types)
865 return GetProperty (name, DefaultBindingFlags, null, returnType, types, null);
868 public PropertyInfo GetProperty( string name, Type returnType, Type[] types, ParameterModifier[] modifiers)
870 return GetProperty (name, DefaultBindingFlags, null, returnType, types, modifiers);
873 public PropertyInfo GetProperty (string name, BindingFlags bindingAttr, Binder binder, Type returnType,
874 Type[] types, ParameterModifier[] modifiers)
877 throw new ArgumentNullException ("name");
879 throw new ArgumentNullException ("types");
881 foreach (Type t in types) {
883 throw new ArgumentNullException ("types");
886 return GetPropertyImpl (name, bindingAttr, binder, returnType, types, modifiers);
889 protected abstract PropertyInfo GetPropertyImpl (string name, BindingFlags bindingAttr, Binder binder,
890 Type returnType, Type[] types, ParameterModifier[] modifiers);
892 internal PropertyInfo GetPropertyImplInternal (string name, BindingFlags bindingAttr, Binder binder,
893 Type returnType, Type[] types, ParameterModifier[] modifiers)
895 return GetPropertyImpl (name, bindingAttr, binder, returnType, types, modifiers);
898 protected abstract ConstructorInfo GetConstructorImpl (BindingFlags bindingAttr,
900 CallingConventions callConvention,
902 ParameterModifier[] modifiers);
904 protected abstract TypeAttributes GetAttributeFlagsImpl ();
905 protected abstract bool HasElementTypeImpl ();
906 protected abstract bool IsArrayImpl ();
907 protected abstract bool IsByRefImpl ();
908 protected abstract bool IsCOMObjectImpl ();
909 protected abstract bool IsPointerImpl ();
910 protected abstract bool IsPrimitiveImpl ();
912 [MethodImplAttribute(MethodImplOptions.InternalCall)]
913 internal static extern bool IsArrayImpl (Type type);
915 protected virtual bool IsValueTypeImpl ()
917 if (this == typeof (ValueType) || this == typeof (Enum))
920 return IsSubclassOf (typeof (ValueType));
923 protected virtual bool IsContextfulImpl ()
925 return typeof (ContextBoundObject).IsAssignableFrom (this);
928 protected virtual bool IsMarshalByRefImpl ()
930 return typeof (MarshalByRefObject).IsAssignableFrom (this);
936 public ConstructorInfo GetConstructor (Type[] types)
938 return GetConstructor (DefaultBindingFlags, null, CallingConventions.Any, types, null);
944 public ConstructorInfo GetConstructor (BindingFlags bindingAttr, Binder binder,
945 Type[] types, ParameterModifier[] modifiers)
947 return GetConstructor (bindingAttr, binder, CallingConventions.Any, types, modifiers);
953 public ConstructorInfo GetConstructor (BindingFlags bindingAttr, Binder binder,
954 CallingConventions callConvention,
955 Type[] types, ParameterModifier[] modifiers)
958 throw new ArgumentNullException ("types");
960 foreach (Type t in types) {
962 throw new ArgumentNullException ("types");
965 return GetConstructorImpl (bindingAttr, binder, callConvention, types, modifiers);
971 public ConstructorInfo[] GetConstructors ()
973 return GetConstructors (BindingFlags.Public | BindingFlags.Instance);
979 public abstract ConstructorInfo[] GetConstructors (BindingFlags bindingAttr);
981 public virtual MemberInfo[] GetDefaultMembers ()
983 object [] att = GetCustomAttributes (typeof (DefaultMemberAttribute), true);
985 return new MemberInfo [0];
987 MemberInfo [] member = GetMember (((DefaultMemberAttribute) att [0]).MemberName);
988 return (member != null) ? member : new MemberInfo [0];
991 public virtual MemberInfo[] FindMembers (MemberTypes memberType, BindingFlags bindingAttr,
992 MemberFilter filter, object filterCriteria)
995 ArrayList l = new ArrayList ();
997 // Console.WriteLine ("FindMembers for {0} (Type: {1}): {2}",
998 // this.FullName, this.GetType().FullName, this.obj_address());
1000 if ((memberType & MemberTypes.Constructor) != 0) {
1001 ConstructorInfo[] c = GetConstructors (bindingAttr);
1002 if (filter != null) {
1003 foreach (MemberInfo m in c) {
1004 if (filter (m, filterCriteria))
1011 if ((memberType & MemberTypes.Event) != 0) {
1012 EventInfo[] c = GetEvents (bindingAttr);
1013 if (filter != null) {
1014 foreach (MemberInfo m in c) {
1015 if (filter (m, filterCriteria))
1022 if ((memberType & MemberTypes.Field) != 0) {
1023 FieldInfo[] c = GetFields (bindingAttr);
1024 if (filter != null) {
1025 foreach (MemberInfo m in c) {
1026 if (filter (m, filterCriteria))
1033 if ((memberType & MemberTypes.Method) != 0) {
1034 MethodInfo[] c = GetMethods (bindingAttr);
1035 if (filter != null) {
1036 foreach (MemberInfo m in c) {
1037 if (filter (m, filterCriteria))
1044 if ((memberType & MemberTypes.Property) != 0) {
1046 int count = l.Count;
1048 if (filter != null) {
1050 while ((l.Count == count) && (ptype != null)) {
1051 c = ptype.GetProperties (bindingAttr);
1052 foreach (MemberInfo m in c) {
1053 if (filter (m, filterCriteria))
1056 ptype = ptype.BaseType;
1059 c = GetProperties (bindingAttr);
1063 if ((memberType & MemberTypes.NestedType) != 0) {
1064 Type[] c = GetNestedTypes (bindingAttr);
1065 if (filter != null) {
1066 foreach (MemberInfo m in c) {
1067 if (filter (m, filterCriteria)) {
1075 result = new MemberInfo [l.Count];
1081 [DebuggerStepThrough]
1082 public object InvokeMember (string name, BindingFlags invokeAttr, Binder binder, object target, object[] args)
1084 return InvokeMember (name, invokeAttr, binder, target, args, null, null, null);
1088 [DebuggerStepThrough]
1089 public object InvokeMember (string name, BindingFlags invokeAttr, Binder binder,
1090 object target, object[] args, CultureInfo culture)
1092 return InvokeMember (name, invokeAttr, binder, target, args, null, culture, null);
1095 public abstract object InvokeMember (string name, BindingFlags invokeAttr,
1096 Binder binder, object target, object[] args,
1097 ParameterModifier[] modifiers,
1098 CultureInfo culture, string[] namedParameters);
1100 public override string ToString()
1105 internal bool IsSystemType {
1107 return _impl.Value != IntPtr.Zero;
1111 #if NET_2_0 || BOOTSTRAP_NET_2_0
1112 public virtual Type[] GetGenericArguments ()
1114 throw new NotSupportedException ();
1117 public virtual bool ContainsGenericParameters {
1118 get { return false; }
1121 public virtual extern bool IsGenericTypeDefinition {
1122 [MethodImplAttribute(MethodImplOptions.InternalCall)]
1126 [MethodImplAttribute(MethodImplOptions.InternalCall)]
1127 extern Type GetGenericTypeDefinition_impl ();
1129 public virtual Type GetGenericTypeDefinition ()
1131 Type res = GetGenericTypeDefinition_impl ();
1133 throw new InvalidOperationException ();
1138 public virtual extern bool IsGenericType {
1139 [MethodImplAttribute(MethodImplOptions.InternalCall)]
1143 [MethodImplAttribute(MethodImplOptions.InternalCall)]
1144 static extern Type MakeGenericType (Type gt, Type [] types);
1146 public virtual Type MakeGenericType (params Type[] types)
1148 if (!IsGenericTypeDefinition)
1149 throw new InvalidOperationException ("not a generic type definition");
1151 throw new ArgumentNullException ("types");
1152 foreach (Type t in types) {
1154 throw new ArgumentNullException ("types");
1156 Type res = MakeGenericType (this, types);
1158 throw new TypeLoadException ();
1162 public virtual bool IsGenericParameter {
1168 public bool IsNested {
1170 return DeclaringType != null;
1174 public bool IsVisible {
1177 return DeclaringType.IsVisible;
1183 [MethodImplAttribute(MethodImplOptions.InternalCall)]
1184 extern int GetGenericParameterPosition ();
1186 public virtual int GenericParameterPosition {
1188 int res = GetGenericParameterPosition ();
1190 throw new InvalidOperationException ();
1195 [MethodImplAttribute(MethodImplOptions.InternalCall)]
1196 extern GenericParameterAttributes GetGenericParameterAttributes ();
1198 public virtual GenericParameterAttributes GenericParameterAttributes {
1200 if (!IsGenericParameter)
1201 throw new InvalidOperationException ();
1203 return GetGenericParameterAttributes ();
1207 [MethodImplAttribute(MethodImplOptions.InternalCall)]
1208 extern Type[] GetGenericParameterConstraints_impl ();
1210 public virtual Type[] GetGenericParameterConstraints ()
1212 if (!IsGenericParameter)
1213 throw new InvalidOperationException ();
1215 return GetGenericParameterConstraints_impl ();
1218 public virtual MethodBase DeclaringMethod {
1224 [MethodImplAttribute(MethodImplOptions.InternalCall)]
1225 extern Type make_array_type (int rank);
1227 public virtual Type MakeArrayType ()
1229 return MakeArrayType (1);
1232 public virtual Type MakeArrayType (int rank)
1235 throw new IndexOutOfRangeException ();
1236 return make_array_type (rank);
1239 [MethodImplAttribute(MethodImplOptions.InternalCall)]
1240 extern Type make_byref_type ();
1242 public virtual Type MakeByRefType ()
1244 return make_byref_type ();
1247 [MethodImplAttribute(MethodImplOptions.InternalCall)]
1248 public extern virtual Type MakePointerType ();
1250 public static Type ReflectionOnlyGetType (string typeName,
1251 bool throwIfNotFound,
1254 if (typeName == null)
1255 throw new ArgumentNullException ("typeName");
1256 int idx = typeName.IndexOf (',');
1257 if (idx < 0 || idx == 0 || idx == typeName.Length - 1)
1258 throw new ArgumentException ("Assembly qualifed type name is required", "typeName");
1259 string an = typeName.Substring (idx + 1);
1262 a = Assembly.ReflectionOnlyLoad (an);
1263 } catch (Exception ex) {
1264 if (throwIfNotFound)
1268 return a.GetType (typeName.Substring (0, idx), throwIfNotFound, ignoreCase);
1271 [MethodImplAttribute(MethodImplOptions.InternalCall)]
1272 extern void GetPacking (out int packing, out int size);
1274 public virtual StructLayoutAttribute StructLayoutAttribute {
1278 if (IsLayoutSequential)
1279 kind = LayoutKind.Sequential;
1280 else if (IsExplicitLayout)
1281 kind = LayoutKind.Explicit;
1283 kind = LayoutKind.Auto;
1285 StructLayoutAttribute attr = new StructLayoutAttribute (kind);
1288 attr.CharSet = CharSet.Unicode;
1289 else if (IsAnsiClass)
1290 attr.CharSet = CharSet.Ansi;
1292 attr.CharSet = CharSet.Auto;
1294 if (kind != LayoutKind.Auto)
1295 GetPacking (out attr.Pack, out attr.Size);
1301 internal object[] GetPseudoCustomAttributes ()
1305 /* IsSerializable returns true for delegates/enums as well */
1306 if ((Attributes & TypeAttributes.Serializable) != 0)
1308 if ((Attributes & TypeAttributes.Import) != 0)
1313 object[] attrs = new object [count];
1316 if ((Attributes & TypeAttributes.Serializable) != 0)
1317 attrs [count ++] = new SerializableAttribute ();
1318 if ((Attributes & TypeAttributes.Import) != 0)
1319 attrs [count ++] = new ComImportAttribute ();
1326 void _Type.GetIDsOfNames ([In] ref Guid riid, IntPtr rgszNames, uint cNames, uint lcid, IntPtr rgDispId)
1328 throw new NotImplementedException ();
1331 void _Type.GetTypeInfo (uint iTInfo, uint lcid, IntPtr ppTInfo)
1333 throw new NotImplementedException ();
1336 void _Type.GetTypeInfoCount (out uint pcTInfo)
1338 throw new NotImplementedException ();
1341 void _Type.Invoke (uint dispIdMember, [In] ref Guid riid, uint lcid, short wFlags, IntPtr pDispParams, IntPtr pVarResult, IntPtr pExcepInfo, IntPtr puArgErr)
1343 throw new NotImplementedException ();