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,
417 * This has NOTHING to do with getting the base type of an enum. Use
418 * Enum.GetUnderlyingType () for that.
420 public abstract Type UnderlyingSystemType {get;}
422 public override bool Equals (object o)
427 Type cmp = o as Type;
433 public bool Equals (Type type) {
436 return UnderlyingSystemType.EqualsInternal (type.UnderlyingSystemType);
439 [MethodImplAttribute(MethodImplOptions.InternalCall)]
440 internal extern bool EqualsInternal (Type type);
442 [MethodImplAttribute(MethodImplOptions.InternalCall)]
443 private static extern Type internal_from_handle (IntPtr handle);
445 [MethodImplAttribute(MethodImplOptions.InternalCall)]
446 private static extern Type internal_from_name (string name, bool throwOnError, bool ignoreCase);
448 public static Type GetType(string typeName)
450 if (typeName == null)
451 throw new ArgumentNullException ("typeName");
453 return internal_from_name (typeName, false, false);
456 public static Type GetType(string typeName, bool throwOnError)
458 if (typeName == null)
459 throw new ArgumentNullException ("typeName");
461 Type type = internal_from_name (typeName, throwOnError, false);
462 if (throwOnError && type == null)
463 throw new TypeLoadException ("Error loading '" + typeName + "'");
468 public static Type GetType(string typeName, bool throwOnError, bool ignoreCase)
470 if (typeName == null)
471 throw new ArgumentNullException ("typeName");
473 Type t = internal_from_name (typeName, throwOnError, ignoreCase);
474 if (throwOnError && t == null)
475 throw new TypeLoadException ("Error loading '" + typeName + "'");
480 public static Type[] GetTypeArray (object[] args) {
482 throw new ArgumentNullException ("args");
485 ret = new Type [args.Length];
486 for (int i = 0; i < args.Length; ++i)
487 ret [i] = args[i].GetType ();
491 [MethodImplAttribute(MethodImplOptions.InternalCall)]
492 internal extern static TypeCode GetTypeCodeInternal (Type type);
494 public static TypeCode GetTypeCode (Type type) {
495 if (type is MonoType)
496 return GetTypeCodeInternal (type);
498 /* MS.NET returns this */
499 return TypeCode.Empty;
501 type = type.UnderlyingSystemType;
503 if (!type.IsSystemType)
504 return TypeCode.Object;
506 return GetTypeCodeInternal (type);
509 [MonoTODO("Mono does not support COM")]
510 public static Type GetTypeFromCLSID (Guid clsid)
512 throw new NotImplementedException ();
515 [MonoTODO("Mono does not support COM")]
516 public static Type GetTypeFromCLSID (Guid clsid, bool throwOnError)
518 throw new NotImplementedException ();
521 [MonoTODO("Mono does not support COM")]
522 public static Type GetTypeFromCLSID (Guid clsid, string server)
524 throw new NotImplementedException ();
527 [MonoTODO("Mono does not support COM")]
528 public static Type GetTypeFromCLSID (Guid clsid, string server, bool throwOnError)
530 throw new NotImplementedException ();
533 public static Type GetTypeFromHandle (RuntimeTypeHandle handle)
535 if (handle.Value == IntPtr.Zero)
536 // This is not consistent with the other GetXXXFromHandle methods, but
537 // MS.NET seems to do this
539 return internal_from_handle (handle.Value);
542 [MonoTODO("Mono does not support COM")]
543 public static Type GetTypeFromProgID (string progID)
545 throw new NotImplementedException ();
548 [MonoTODO("Mono does not support COM")]
549 public static Type GetTypeFromProgID (string progID, bool throwOnError)
551 throw new NotImplementedException ();
554 [MonoTODO("Mono does not support COM")]
555 public static Type GetTypeFromProgID (string progID, string server)
557 throw new NotImplementedException ();
560 [MonoTODO("Mono does not support COM")]
561 public static Type GetTypeFromProgID (string progID, string server, bool throwOnError)
563 throw new NotImplementedException ();
566 public static RuntimeTypeHandle GetTypeHandle (object o)
568 return o.GetType().TypeHandle;
571 [MethodImplAttribute(MethodImplOptions.InternalCall)]
572 internal static extern bool type_is_subtype_of (Type a, Type b, bool check_interfaces);
574 [MethodImplAttribute(MethodImplOptions.InternalCall)]
575 internal static extern bool type_is_assignable_from (Type a, Type b);
577 public new Type GetType ()
579 return base.GetType ();
585 public virtual bool IsSubclassOf (Type c)
587 if (c == null || c == this)
590 // Fast check for system types
592 return c.IsSystemType && type_is_subtype_of (this, c, false);
594 // User defined types depend on this behavior
595 for (Type type = BaseType; type != null; type = type.BaseType)
602 public virtual Type[] FindInterfaces (TypeFilter filter, object filterCriteria)
605 throw new ArgumentNullException ("filter");
607 ArrayList ifaces = new ArrayList ();
608 foreach (Type iface in GetInterfaces ()) {
609 if (filter (iface, filterCriteria))
613 return (Type []) ifaces.ToArray (typeof (Type));
616 public Type GetInterface (string name) {
617 return GetInterface (name, false);
620 public abstract Type GetInterface (string name, bool ignoreCase);
622 [MethodImplAttribute(MethodImplOptions.InternalCall)]
623 internal static extern void GetInterfaceMapData (Type t, Type iface, out MethodInfo[] targets, out MethodInfo[] methods);
628 public virtual InterfaceMapping GetInterfaceMap (Type interfaceType) {
629 InterfaceMapping res;
630 if (interfaceType == null)
631 throw new ArgumentNullException ("interfaceType");
632 if (!interfaceType.IsInterface)
633 throw new ArgumentException (Locale.GetText ("Argument must be an interface."), "interfaceType");
634 res.TargetType = this;
635 res.InterfaceType = interfaceType;
636 GetInterfaceMapData (this, interfaceType, out res.TargetMethods, out res.InterfaceMethods);
637 if (res.TargetMethods == null)
638 throw new ArgumentException (Locale.GetText ("Interface not found"), "interfaceType");
643 public abstract Type[] GetInterfaces ();
645 public virtual bool IsAssignableFrom (Type c)
653 if (c is TypeBuilder)
654 return ((TypeBuilder)c).IsAssignableTo (this);
656 /* Handle user defined type classes */
658 Type systemType = UnderlyingSystemType;
659 if (!systemType.IsSystemType)
661 return systemType.IsAssignableFrom (c);
664 if (!c.IsSystemType) {
665 Type underlyingType = c.UnderlyingSystemType;
666 if (!underlyingType.IsSystemType)
668 return IsAssignableFrom (underlyingType);
671 return type_is_assignable_from (this, c);
674 [MethodImplAttribute(MethodImplOptions.InternalCall)]
675 public extern virtual bool IsInstanceOfType (object o);
677 public virtual int GetArrayRank ()
679 throw new NotSupportedException (); // according to MSDN
682 public abstract Type GetElementType ();
684 public EventInfo GetEvent (string name)
686 return GetEvent (name, DefaultBindingFlags);
689 public abstract EventInfo GetEvent (string name, BindingFlags bindingAttr);
691 public virtual EventInfo[] GetEvents ()
693 return GetEvents (DefaultBindingFlags);
696 public abstract EventInfo[] GetEvents (BindingFlags bindingAttr);
698 public FieldInfo GetField( string name)
700 return GetField (name, DefaultBindingFlags);
703 public abstract FieldInfo GetField( string name, BindingFlags bindingAttr);
705 public FieldInfo[] GetFields ()
707 return GetFields (DefaultBindingFlags);
710 public abstract FieldInfo[] GetFields (BindingFlags bindingAttr);
712 public override int GetHashCode()
714 return (int)_impl.Value;
717 public MemberInfo[] GetMember (string name)
719 return GetMember (name, DefaultBindingFlags);
722 public virtual MemberInfo[] GetMember (string name, BindingFlags bindingAttr)
724 return GetMember (name, MemberTypes.All, bindingAttr);
727 public virtual MemberInfo[] GetMember (string name, MemberTypes type, BindingFlags bindingAttr)
729 if ((bindingAttr & BindingFlags.IgnoreCase) != 0)
730 return FindMembers (type, bindingAttr, FilterNameIgnoreCase, name);
732 return FindMembers (type, bindingAttr, FilterName, name);
735 public MemberInfo[] GetMembers ()
737 return GetMembers (DefaultBindingFlags);
740 public abstract MemberInfo[] GetMembers (BindingFlags bindingAttr);
742 public MethodInfo GetMethod (string name)
745 throw new ArgumentNullException ("name");
746 return GetMethodImpl (name, DefaultBindingFlags, null, CallingConventions.Any, null, null);
749 public MethodInfo GetMethod (string name, BindingFlags bindingAttr)
752 throw new ArgumentNullException ("name");
754 return GetMethodImpl (name, bindingAttr, null, CallingConventions.Any, null, null);
757 public MethodInfo GetMethod (string name, Type[] types)
759 return GetMethod (name, DefaultBindingFlags, null, CallingConventions.Any, types, null);
762 public MethodInfo GetMethod (string name, Type[] types, ParameterModifier[] modifiers)
764 return GetMethod (name, DefaultBindingFlags, null, CallingConventions.Any, types, modifiers);
767 public MethodInfo GetMethod (string name, BindingFlags bindingAttr, Binder binder,
768 Type[] types, ParameterModifier[] modifiers)
771 return GetMethod (name, bindingAttr, binder, CallingConventions.Any, types, modifiers);
774 public MethodInfo GetMethod (string name, BindingFlags bindingAttr, Binder binder,
775 CallingConventions callConvention, Type[] types, ParameterModifier[] modifiers)
778 throw new ArgumentNullException ("name");
780 throw new ArgumentNullException ("types");
782 for (int i = 0; i < types.Length; i++)
783 if (types[i] == null)
784 throw new ArgumentNullException ("types");
786 return GetMethodImpl (name, bindingAttr, binder, callConvention, types, modifiers);
789 protected abstract MethodInfo GetMethodImpl (string name, BindingFlags bindingAttr, Binder binder,
790 CallingConventions callConvention, Type[] types,
791 ParameterModifier[] modifiers);
793 internal MethodInfo GetMethodImplInternal (string name, BindingFlags bindingAttr, Binder binder,
794 CallingConventions callConvention, Type[] types,
795 ParameterModifier[] modifiers)
797 return GetMethodImpl (name, bindingAttr, binder, callConvention, types, modifiers);
800 internal virtual MethodInfo GetMethod (MethodInfo fromNoninstanciated)
802 throw new System.InvalidOperationException ("can only be called in generic type");
805 internal virtual ConstructorInfo GetConstructor (ConstructorInfo fromNoninstanciated)
807 throw new System.InvalidOperationException ("can only be called in generic type");
810 internal virtual FieldInfo GetField (FieldInfo fromNoninstanciated)
812 throw new System.InvalidOperationException ("can only be called in generic type");
816 public MethodInfo[] GetMethods ()
818 return GetMethods (DefaultBindingFlags);
821 public abstract MethodInfo[] GetMethods (BindingFlags bindingAttr);
823 public Type GetNestedType (string name)
825 return GetNestedType (name, DefaultBindingFlags);
828 public abstract Type GetNestedType (string name, BindingFlags bindingAttr);
830 public Type[] GetNestedTypes ()
832 return GetNestedTypes (DefaultBindingFlags);
835 public abstract Type[] GetNestedTypes (BindingFlags bindingAttr);
838 public PropertyInfo[] GetProperties ()
840 return GetProperties (DefaultBindingFlags);
843 public abstract PropertyInfo[] GetProperties (BindingFlags bindingAttr);
846 public PropertyInfo GetProperty (string name)
849 throw new ArgumentNullException ("name");
851 return GetPropertyImpl (name, DefaultBindingFlags, null, null, null, null);
854 public PropertyInfo GetProperty (string name, BindingFlags bindingAttr)
857 throw new ArgumentNullException ("name");
858 return GetPropertyImpl (name, bindingAttr, null, null, null, null);
861 public PropertyInfo GetProperty (string name, Type returnType)
864 throw new ArgumentNullException ("name");
865 return GetPropertyImpl (name, DefaultBindingFlags, null, returnType, null, null);
868 public PropertyInfo GetProperty (string name, Type[] types)
870 return GetProperty (name, DefaultBindingFlags, null, null, types, null);
873 public PropertyInfo GetProperty (string name, Type returnType, Type[] types)
875 return GetProperty (name, DefaultBindingFlags, null, returnType, types, null);
878 public PropertyInfo GetProperty( string name, Type returnType, Type[] types, ParameterModifier[] modifiers)
880 return GetProperty (name, DefaultBindingFlags, null, returnType, types, modifiers);
883 public PropertyInfo GetProperty (string name, BindingFlags bindingAttr, Binder binder, Type returnType,
884 Type[] types, ParameterModifier[] modifiers)
887 throw new ArgumentNullException ("name");
889 throw new ArgumentNullException ("types");
891 foreach (Type t in types) {
893 throw new ArgumentNullException ("types");
896 return GetPropertyImpl (name, bindingAttr, binder, returnType, types, modifiers);
899 protected abstract PropertyInfo GetPropertyImpl (string name, BindingFlags bindingAttr, Binder binder,
900 Type returnType, Type[] types, ParameterModifier[] modifiers);
902 internal PropertyInfo GetPropertyImplInternal (string name, BindingFlags bindingAttr, Binder binder,
903 Type returnType, Type[] types, ParameterModifier[] modifiers)
905 return GetPropertyImpl (name, bindingAttr, binder, returnType, types, modifiers);
908 protected abstract ConstructorInfo GetConstructorImpl (BindingFlags bindingAttr,
910 CallingConventions callConvention,
912 ParameterModifier[] modifiers);
914 protected abstract TypeAttributes GetAttributeFlagsImpl ();
915 protected abstract bool HasElementTypeImpl ();
916 protected abstract bool IsArrayImpl ();
917 protected abstract bool IsByRefImpl ();
918 protected abstract bool IsCOMObjectImpl ();
919 protected abstract bool IsPointerImpl ();
920 protected abstract bool IsPrimitiveImpl ();
922 [MethodImplAttribute(MethodImplOptions.InternalCall)]
923 internal static extern bool IsArrayImpl (Type type);
925 protected virtual bool IsValueTypeImpl ()
927 if (this == typeof (ValueType) || this == typeof (Enum))
930 return IsSubclassOf (typeof (ValueType));
933 protected virtual bool IsContextfulImpl ()
935 return typeof (ContextBoundObject).IsAssignableFrom (this);
938 protected virtual bool IsMarshalByRefImpl ()
940 return typeof (MarshalByRefObject).IsAssignableFrom (this);
946 public ConstructorInfo GetConstructor (Type[] types)
948 return GetConstructor (BindingFlags.Public|BindingFlags.Instance, null, CallingConventions.Any, types, null);
954 public ConstructorInfo GetConstructor (BindingFlags bindingAttr, Binder binder,
955 Type[] types, ParameterModifier[] modifiers)
957 return GetConstructor (bindingAttr, binder, CallingConventions.Any, types, modifiers);
963 public ConstructorInfo GetConstructor (BindingFlags bindingAttr, Binder binder,
964 CallingConventions callConvention,
965 Type[] types, ParameterModifier[] modifiers)
968 throw new ArgumentNullException ("types");
970 foreach (Type t in types) {
972 throw new ArgumentNullException ("types");
975 return GetConstructorImpl (bindingAttr, binder, callConvention, types, modifiers);
981 public ConstructorInfo[] GetConstructors ()
983 return GetConstructors (BindingFlags.Public | BindingFlags.Instance);
989 public abstract ConstructorInfo[] GetConstructors (BindingFlags bindingAttr);
991 public virtual MemberInfo[] GetDefaultMembers ()
993 object [] att = GetCustomAttributes (typeof (DefaultMemberAttribute), true);
995 return new MemberInfo [0];
997 MemberInfo [] member = GetMember (((DefaultMemberAttribute) att [0]).MemberName);
998 return (member != null) ? member : new MemberInfo [0];
1001 public virtual MemberInfo[] FindMembers (MemberTypes memberType, BindingFlags bindingAttr,
1002 MemberFilter filter, object filterCriteria)
1004 MemberInfo[] result;
1005 ArrayList l = new ArrayList ();
1007 // Console.WriteLine ("FindMembers for {0} (Type: {1}): {2}",
1008 // this.FullName, this.GetType().FullName, this.obj_address());
1010 if ((memberType & MemberTypes.Constructor) != 0) {
1011 ConstructorInfo[] c = GetConstructors (bindingAttr);
1012 if (filter != null) {
1013 foreach (MemberInfo m in c) {
1014 if (filter (m, filterCriteria))
1021 if ((memberType & MemberTypes.Event) != 0) {
1022 EventInfo[] c = GetEvents (bindingAttr);
1023 if (filter != null) {
1024 foreach (MemberInfo m in c) {
1025 if (filter (m, filterCriteria))
1032 if ((memberType & MemberTypes.Field) != 0) {
1033 FieldInfo[] c = GetFields (bindingAttr);
1034 if (filter != null) {
1035 foreach (MemberInfo m in c) {
1036 if (filter (m, filterCriteria))
1043 if ((memberType & MemberTypes.Method) != 0) {
1044 MethodInfo[] c = GetMethods (bindingAttr);
1045 if (filter != null) {
1046 foreach (MemberInfo m in c) {
1047 if (filter (m, filterCriteria))
1054 if ((memberType & MemberTypes.Property) != 0) {
1056 int count = l.Count;
1058 if (filter != null) {
1060 while ((l.Count == count) && (ptype != null)) {
1061 c = ptype.GetProperties (bindingAttr);
1062 foreach (MemberInfo m in c) {
1063 if (filter (m, filterCriteria))
1066 ptype = ptype.BaseType;
1069 c = GetProperties (bindingAttr);
1073 if ((memberType & MemberTypes.NestedType) != 0) {
1074 Type[] c = GetNestedTypes (bindingAttr);
1075 if (filter != null) {
1076 foreach (MemberInfo m in c) {
1077 if (filter (m, filterCriteria)) {
1085 result = new MemberInfo [l.Count];
1091 [DebuggerStepThrough]
1092 public object InvokeMember (string name, BindingFlags invokeAttr, Binder binder, object target, object[] args)
1094 return InvokeMember (name, invokeAttr, binder, target, args, null, null, null);
1098 [DebuggerStepThrough]
1099 public object InvokeMember (string name, BindingFlags invokeAttr, Binder binder,
1100 object target, object[] args, CultureInfo culture)
1102 return InvokeMember (name, invokeAttr, binder, target, args, null, culture, null);
1105 public abstract object InvokeMember (string name, BindingFlags invokeAttr,
1106 Binder binder, object target, object[] args,
1107 ParameterModifier[] modifiers,
1108 CultureInfo culture, string[] namedParameters);
1110 public override string ToString()
1115 internal bool IsSystemType {
1117 return _impl.Value != IntPtr.Zero;
1121 #if NET_2_0 || BOOTSTRAP_NET_2_0
1122 public virtual Type[] GetGenericArguments ()
1124 throw new NotSupportedException ();
1127 public virtual bool ContainsGenericParameters {
1128 get { return false; }
1131 public virtual extern bool IsGenericTypeDefinition {
1132 [MethodImplAttribute(MethodImplOptions.InternalCall)]
1136 [MethodImplAttribute(MethodImplOptions.InternalCall)]
1137 extern Type GetGenericTypeDefinition_impl ();
1139 public virtual Type GetGenericTypeDefinition ()
1141 Type res = GetGenericTypeDefinition_impl ();
1143 throw new InvalidOperationException ();
1148 public virtual extern bool IsGenericType {
1149 [MethodImplAttribute(MethodImplOptions.InternalCall)]
1153 [MethodImplAttribute(MethodImplOptions.InternalCall)]
1154 static extern Type MakeGenericType (Type gt, Type [] types);
1156 public virtual Type MakeGenericType (params Type[] types)
1158 if (!IsGenericTypeDefinition)
1159 throw new InvalidOperationException ("not a generic type definition");
1161 throw new ArgumentNullException ("types");
1162 if (GetGenericArguments().Length != types.Length)
1163 throw new ArgumentException (String.Format ("The type or method has {0} generic parameter(s) but {1} generic argument(s) where provided. A generic argument must be provided for each generic parameter.", GetGenericArguments ().Length, types.Length), "types");
1165 Type[] systemTypes = new Type[types.Length];
1166 for (int i = 0; i < types.Length; ++i) {
1169 throw new ArgumentNullException ("types");
1171 t = t.UnderlyingSystemType;
1172 if (t == null || !t.IsSystemType)
1173 throw new ArgumentNullException ("types");
1174 systemTypes [i] = types [i].UnderlyingSystemType;
1177 Type res = MakeGenericType (this, systemTypes);
1179 throw new TypeLoadException ();
1183 public virtual bool IsGenericParameter {
1189 public bool IsNested {
1191 return DeclaringType != null;
1195 public bool IsVisible {
1198 return DeclaringType.IsVisible;
1204 [MethodImplAttribute(MethodImplOptions.InternalCall)]
1205 extern int GetGenericParameterPosition ();
1207 public virtual int GenericParameterPosition {
1209 int res = GetGenericParameterPosition ();
1211 throw new InvalidOperationException ();
1216 [MethodImplAttribute(MethodImplOptions.InternalCall)]
1217 extern GenericParameterAttributes GetGenericParameterAttributes ();
1219 public virtual GenericParameterAttributes GenericParameterAttributes {
1221 if (!IsGenericParameter)
1222 throw new InvalidOperationException ();
1224 return GetGenericParameterAttributes ();
1228 [MethodImplAttribute(MethodImplOptions.InternalCall)]
1229 extern Type[] GetGenericParameterConstraints_impl ();
1231 public virtual Type[] GetGenericParameterConstraints ()
1233 if (!IsGenericParameter)
1234 throw new InvalidOperationException ();
1236 return GetGenericParameterConstraints_impl ();
1239 public virtual MethodBase DeclaringMethod {
1245 [MethodImplAttribute(MethodImplOptions.InternalCall)]
1246 extern Type make_array_type (int rank);
1248 public virtual Type MakeArrayType ()
1250 return MakeArrayType (1);
1253 public virtual Type MakeArrayType (int rank)
1256 throw new IndexOutOfRangeException ();
1257 return make_array_type (rank);
1260 [MethodImplAttribute(MethodImplOptions.InternalCall)]
1261 extern Type make_byref_type ();
1263 public virtual Type MakeByRefType ()
1265 return make_byref_type ();
1268 [MethodImplAttribute(MethodImplOptions.InternalCall)]
1269 public extern virtual Type MakePointerType ();
1271 public static Type ReflectionOnlyGetType (string typeName,
1272 bool throwIfNotFound,
1275 if (typeName == null)
1276 throw new ArgumentNullException ("typeName");
1277 int idx = typeName.IndexOf (',');
1278 if (idx < 0 || idx == 0 || idx == typeName.Length - 1)
1279 throw new ArgumentException ("Assembly qualifed type name is required", "typeName");
1280 string an = typeName.Substring (idx + 1);
1283 a = Assembly.ReflectionOnlyLoad (an);
1285 if (throwIfNotFound)
1289 return a.GetType (typeName.Substring (0, idx), throwIfNotFound, ignoreCase);
1292 [MethodImplAttribute(MethodImplOptions.InternalCall)]
1293 extern void GetPacking (out int packing, out int size);
1295 public virtual StructLayoutAttribute StructLayoutAttribute {
1299 if (IsLayoutSequential)
1300 kind = LayoutKind.Sequential;
1301 else if (IsExplicitLayout)
1302 kind = LayoutKind.Explicit;
1304 kind = LayoutKind.Auto;
1306 StructLayoutAttribute attr = new StructLayoutAttribute (kind);
1309 attr.CharSet = CharSet.Unicode;
1310 else if (IsAnsiClass)
1311 attr.CharSet = CharSet.Ansi;
1313 attr.CharSet = CharSet.Auto;
1315 if (kind != LayoutKind.Auto)
1316 GetPacking (out attr.Pack, out attr.Size);
1322 internal object[] GetPseudoCustomAttributes ()
1326 /* IsSerializable returns true for delegates/enums as well */
1327 if ((Attributes & TypeAttributes.Serializable) != 0)
1329 if ((Attributes & TypeAttributes.Import) != 0)
1334 object[] attrs = new object [count];
1337 if ((Attributes & TypeAttributes.Serializable) != 0)
1338 attrs [count ++] = new SerializableAttribute ();
1339 if ((Attributes & TypeAttributes.Import) != 0)
1340 attrs [count ++] = new ComImportAttribute ();
1347 void _Type.GetIDsOfNames ([In] ref Guid riid, IntPtr rgszNames, uint cNames, uint lcid, IntPtr rgDispId)
1349 throw new NotImplementedException ();
1352 void _Type.GetTypeInfo (uint iTInfo, uint lcid, IntPtr ppTInfo)
1354 throw new NotImplementedException ();
1357 void _Type.GetTypeInfoCount (out uint pcTInfo)
1359 throw new NotImplementedException ();
1362 void _Type.Invoke (uint dispIdMember, [In] ref Guid riid, uint lcid, short wFlags, IntPtr pDispParams, IntPtr pVarResult, IntPtr pExcepInfo, IntPtr puArgErr)
1364 throw new NotImplementedException ();