**** Merged from MCS ****
[mono-project.git] / mcs / class / corlib / System / Type.cs
blob2a7619c0b4f833c6f955fc8a2bdebd81468abf49
1 //
2 // System.Type.cs
3 //
4 // Author:
5 // Miguel de Icaza (miguel@ximian.com)
6 //
7 // (C) Ximian, Inc. http://www.ximian.com
8 //
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:
20 //
21 // The above copyright notice and this permission notice shall be
22 // included in all copies or substantial portions of the Software.
23 //
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.Collections;
36 using System.Runtime.InteropServices;
37 using System.Runtime.CompilerServices;
38 using System.Globalization;
40 namespace System {
42 [Serializable]
43 [ClassInterface (ClassInterfaceType.AutoDual)]
44 public abstract class Type : MemberInfo, IReflect {
46 internal RuntimeTypeHandle _impl;
48 public static readonly char Delimiter = '.';
49 public static readonly Type[] EmptyTypes = {};
50 public static readonly MemberFilter FilterAttribute = new MemberFilter (FilterAttribute_impl);
51 public static readonly MemberFilter FilterName = new MemberFilter (FilterName_impl);
52 public static readonly MemberFilter FilterNameIgnoreCase = new MemberFilter (FilterNameIgnoreCase_impl);
53 public static readonly object Missing;
55 protected const BindingFlags DefaultBindingFlags =
56 BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance;
58 /* implementation of the delegates for MemberFilter */
59 static bool FilterName_impl (MemberInfo m, object filterCriteria)
61 string name = (string) filterCriteria;
62 return name.Equals (m.Name);
65 static bool FilterNameIgnoreCase_impl (MemberInfo m, object filterCriteria)
67 string name = (string) filterCriteria;
68 if (name.Length != m.Name.Length)
69 return false;
71 return String.Compare (name, m.Name, true, CultureInfo.InvariantCulture) == 0;
74 static bool FilterAttribute_impl (MemberInfo m, object filterCriteria)
76 int flags = ((IConvertible)filterCriteria).ToInt32 (null);
77 if (m is MethodInfo)
78 return ((int)((MethodInfo)m).Attributes & flags) != 0;
79 if (m is FieldInfo)
80 return ((int)((FieldInfo)m).Attributes & flags) != 0;
81 if (m is PropertyInfo)
82 return ((int)((PropertyInfo)m).Attributes & flags) != 0;
83 if (m is EventInfo)
84 return ((int)((EventInfo)m).Attributes & flags) != 0;
85 return false;
88 protected Type ()
92 /// <summary>
93 /// The assembly where the type is defined.
94 /// </summary>
95 public abstract Assembly Assembly {
96 get;
99 /// <summary>
100 /// Gets the fully qualified name for the type including the
101 /// assembly name where the type is defined.
102 /// </summary>
103 public abstract string AssemblyQualifiedName {
104 get;
107 /// <summary>
108 /// Returns the Attributes associated with the type.
109 /// </summary>
110 public TypeAttributes Attributes {
111 get {
112 return GetAttributeFlagsImpl ();
116 /// <summary>
117 /// Returns the basetype for this type
118 /// </summary>
119 public abstract Type BaseType {
120 get;
123 /// <summary>
124 /// Returns the class that declares the member.
125 /// </summary>
126 public override Type DeclaringType {
127 get {
128 return null;
132 /// <summary>
134 /// </summary>
135 public static Binder DefaultBinder {
136 get {
137 return Binder.DefaultBinder;
141 /// <summary>
142 /// The full name of the type including its namespace
143 /// </summary>
144 public abstract string FullName {
145 get;
148 public abstract Guid GUID {
149 get;
152 public bool HasElementType {
153 get {
154 return HasElementTypeImpl ();
158 public bool IsAbstract {
159 get {
160 return (Attributes & TypeAttributes.Abstract) != 0;
164 public bool IsAnsiClass {
165 get {
166 return (Attributes & TypeAttributes.StringFormatMask)
167 == TypeAttributes.AnsiClass;
171 public bool IsArray {
172 get {
173 return IsArrayImpl ();
177 public bool IsAutoClass {
178 get {
179 return (Attributes & TypeAttributes.StringFormatMask) == TypeAttributes.AutoClass;
183 public bool IsAutoLayout {
184 get {
185 return (Attributes & TypeAttributes.LayoutMask) == TypeAttributes.AutoLayout;
189 public bool IsByRef {
190 get {
191 return IsByRefImpl ();
195 public bool IsClass {
196 get {
198 // This code used to probe for "this == typeof (System.Enum)", but in
199 // The .NET Framework 1.0, the above test return false
201 if (this == typeof (System.ValueType))
202 return true;
203 if (IsInterface)
204 return false;
205 return !type_is_subtype_of (this, typeof (System.ValueType), false);
209 public bool IsCOMObject {
210 get {
211 return IsCOMObjectImpl ();
215 public bool IsContextful {
216 get {
217 return IsContextfulImpl ();
221 public bool IsEnum {
222 get {
223 return type_is_subtype_of (this, typeof (System.Enum), false) &&
224 this != typeof (System.Enum);
228 public bool IsExplicitLayout {
229 get {
230 return (Attributes & TypeAttributes.LayoutMask) == TypeAttributes.ExplicitLayout;
234 public bool IsImport {
235 get {
236 return (Attributes & TypeAttributes.Import) != 0;
240 public bool IsInterface {
241 get {
242 return (Attributes & TypeAttributes.ClassSemanticsMask) == TypeAttributes.Interface;
246 public bool IsLayoutSequential {
247 get {
248 return (Attributes & TypeAttributes.LayoutMask) == TypeAttributes.SequentialLayout;
252 public bool IsMarshalByRef {
253 get {
254 return IsMarshalByRefImpl ();
258 public bool IsNestedAssembly {
259 get {
260 return (Attributes & TypeAttributes.VisibilityMask) == TypeAttributes.NestedAssembly;
264 public bool IsNestedFamANDAssem {
265 get {
266 return (Attributes & TypeAttributes.VisibilityMask) == TypeAttributes.NestedFamANDAssem;
270 public bool IsNestedFamily {
271 get {
272 return (Attributes & TypeAttributes.VisibilityMask) == TypeAttributes.NestedFamily;
276 public bool IsNestedFamORAssem {
277 get {
278 return (Attributes & TypeAttributes.VisibilityMask) == TypeAttributes.NestedFamORAssem;
282 public bool IsNestedPrivate {
283 get {
284 return (Attributes & TypeAttributes.VisibilityMask) == TypeAttributes.NestedPrivate;
288 public bool IsNestedPublic {
289 get {
290 return (Attributes & TypeAttributes.VisibilityMask) == TypeAttributes.NestedPublic;
294 public bool IsNotPublic {
295 get {
296 return (Attributes & TypeAttributes.VisibilityMask) == TypeAttributes.NotPublic;
300 public bool IsPointer {
301 get {
302 return IsPointerImpl ();
306 public bool IsPrimitive {
307 get {
308 return IsPrimitiveImpl ();
312 public bool IsPublic {
313 get {
314 return (Attributes & TypeAttributes.VisibilityMask) == TypeAttributes.Public;
318 public bool IsSealed {
319 get {
320 return (Attributes & TypeAttributes.Sealed) != 0;
324 public bool IsSerializable {
325 get {
326 // Enums and delegates are always serializable
327 return (Attributes & TypeAttributes.Serializable) != 0 || IsEnum ||
328 type_is_subtype_of (this, typeof (System.Delegate), false);
332 public bool IsSpecialName {
333 get {
334 return (Attributes & TypeAttributes.SpecialName) != 0;
338 public bool IsUnicodeClass {
339 get {
340 return (Attributes & TypeAttributes.StringFormatMask) == TypeAttributes.UnicodeClass;
344 public bool IsValueType {
345 get {
346 return IsValueTypeImpl ();
350 public override MemberTypes MemberType {
351 get {return MemberTypes.TypeInfo;}
354 #if NET_2_0 || BOOTSTRAP_NET_2_0
355 override
356 #endif
357 public abstract Module Module {get;}
359 public abstract string Namespace {get;}
361 public override Type ReflectedType {
362 get {
363 return null;
367 public abstract RuntimeTypeHandle TypeHandle {get;}
369 public ConstructorInfo TypeInitializer {
370 get {
371 return GetConstructorImpl (
372 BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static,
373 null,
374 CallingConventions.Any,
375 EmptyTypes,
376 null);
380 public abstract Type UnderlyingSystemType {get;}
382 public override bool Equals (object o)
384 if (o == null)
385 return false;
387 // TODO: return UnderlyingSystemType == o.UnderlyingSystemType;
388 Type cmp = o as Type;
389 if (cmp == null)
390 return false;
391 return Equals (cmp);
394 [MethodImplAttribute(MethodImplOptions.InternalCall)]
395 public extern bool Equals (Type type);
397 [MethodImplAttribute(MethodImplOptions.InternalCall)]
398 private static extern Type internal_from_handle (IntPtr handle);
400 [MethodImplAttribute(MethodImplOptions.InternalCall)]
401 private static extern Type internal_from_name (string name, bool throwOnError, bool ignoreCase);
403 public static Type GetType(string typeName)
405 if (typeName == null)
406 throw new ArgumentNullException ("typeName");
408 return internal_from_name (typeName, false, false);
411 public static Type GetType(string typeName, bool throwOnError)
413 if (typeName == null)
414 throw new ArgumentNullException ("typeName");
416 Type type = internal_from_name (typeName, throwOnError, false);
417 if (throwOnError && type == null)
418 throw new TypeLoadException ("Error loading '" + typeName + "'");
420 return type;
423 public static Type GetType(string typeName, bool throwOnError, bool ignoreCase)
425 if (typeName == null)
426 throw new ArgumentNullException ("typeName");
428 Type t = internal_from_name (typeName, throwOnError, ignoreCase);
429 if (throwOnError && t == null)
430 throw new TypeLoadException ("Error loading '" + typeName + "'");
432 return t;
435 public static Type[] GetTypeArray (object[] args) {
436 if (args == null)
437 throw new ArgumentNullException ("args");
439 Type[] ret;
440 ret = new Type [args.Length];
441 for (int i = 0; i < args.Length; ++i)
442 ret [i] = args[i].GetType ();
443 return ret;
446 [MethodImplAttribute(MethodImplOptions.InternalCall)]
447 public extern static TypeCode GetTypeCode (Type type);
449 [MonoTODO]
450 public static Type GetTypeFromCLSID (Guid clsid)
452 throw new NotImplementedException ();
455 [MonoTODO]
456 public static Type GetTypeFromCLSID (Guid clsid, bool throwOnError)
458 throw new NotImplementedException ();
461 [MonoTODO]
462 public static Type GetTypeFromCLSID (Guid clsid, string server)
464 throw new NotImplementedException ();
467 [MonoTODO]
468 public static Type GetTypeFromCLSID (Guid clsid, string server, bool throwOnError)
470 throw new NotImplementedException ();
473 public static Type GetTypeFromHandle (RuntimeTypeHandle handle)
475 return internal_from_handle (handle.Value);
478 [MonoTODO]
479 public static Type GetTypeFromProgID (string progID)
481 throw new NotImplementedException ();
484 [MonoTODO]
485 public static Type GetTypeFromProgID (string progID, bool throwOnError)
487 throw new NotImplementedException ();
490 [MonoTODO]
491 public static Type GetTypeFromProgID (string progID, string server)
493 throw new NotImplementedException ();
496 [MonoTODO]
497 public static Type GetTypeFromProgID (string progID, string server, bool throwOnError)
499 throw new NotImplementedException ();
502 public static RuntimeTypeHandle GetTypeHandle (object o)
504 return o.GetType().TypeHandle;
507 [MethodImplAttribute(MethodImplOptions.InternalCall)]
508 internal static extern bool type_is_subtype_of (Type a, Type b, bool check_interfaces);
510 [MethodImplAttribute(MethodImplOptions.InternalCall)]
511 internal static extern bool type_is_assignable_from (Type a, Type b);
513 public virtual bool IsSubclassOf (Type c)
515 if (c == null)
516 return false;
518 return (this != c) && type_is_subtype_of (this, c, false);
521 public virtual Type[] FindInterfaces (TypeFilter filter, object filterCriteria)
523 if (filter == null)
524 throw new ArgumentNullException ("filter");
526 ArrayList ifaces = new ArrayList ();
527 foreach (Type iface in GetInterfaces ()) {
528 if (filter (iface, filterCriteria))
529 ifaces.Add (iface);
532 return (Type []) ifaces.ToArray (typeof (Type));
535 public Type GetInterface (string name) {
536 return GetInterface (name, false);
539 public abstract Type GetInterface (string name, bool ignoreCase);
541 [MethodImplAttribute(MethodImplOptions.InternalCall)]
542 internal static extern void GetInterfaceMapData (Type t, Type iface, out MethodInfo[] targets, out MethodInfo[] methods);
544 public virtual InterfaceMapping GetInterfaceMap (Type interfaceType) {
545 InterfaceMapping res;
546 if (interfaceType == null)
547 throw new ArgumentNullException ("interfaceType");
548 if (!interfaceType.IsInterface)
549 throw new ArgumentException (Locale.GetText ("Argument must be an interface."), "interfaceType");
550 res.TargetType = this;
551 res.InterfaceType = interfaceType;
552 GetInterfaceMapData (this, interfaceType, out res.TargetMethods, out res.InterfaceMethods);
553 if (res.TargetMethods == null)
554 throw new ArgumentException (Locale.GetText ("Interface not found"), "interfaceType");
556 return res;
559 public abstract Type[] GetInterfaces ();
561 public virtual bool IsAssignableFrom (Type c)
563 if (c == null)
564 return false;
566 if (Equals (c))
567 return true;
569 return type_is_assignable_from (this, c);
572 [MethodImplAttribute(MethodImplOptions.InternalCall)]
573 public extern virtual bool IsInstanceOfType (object o);
575 public virtual int GetArrayRank ()
577 throw new NotSupportedException (); // according to MSDN
580 public abstract Type GetElementType ();
582 public EventInfo GetEvent (string name)
584 return GetEvent (name, DefaultBindingFlags);
587 public abstract EventInfo GetEvent (string name, BindingFlags bindingAttr);
589 public virtual EventInfo[] GetEvents ()
591 return GetEvents (DefaultBindingFlags);
594 public abstract EventInfo[] GetEvents (BindingFlags bindingAttr);
596 public FieldInfo GetField( string name)
598 return GetField (name, DefaultBindingFlags);
601 public abstract FieldInfo GetField( string name, BindingFlags bindingAttr);
603 public FieldInfo[] GetFields ()
605 return GetFields (DefaultBindingFlags);
608 public abstract FieldInfo[] GetFields (BindingFlags bindingAttr);
610 public override int GetHashCode()
612 return (int)_impl.Value;
615 public MemberInfo[] GetMember (string name)
617 return GetMember (name, DefaultBindingFlags);
620 public virtual MemberInfo[] GetMember (string name, BindingFlags bindingAttr)
622 return GetMember (name, MemberTypes.All, bindingAttr);
625 public virtual MemberInfo[] GetMember (string name, MemberTypes type, BindingFlags bindingAttr)
627 if ((bindingAttr & BindingFlags.IgnoreCase) != 0)
628 return FindMembers (type, bindingAttr, FilterNameIgnoreCase, name);
629 else
630 return FindMembers (type, bindingAttr, FilterName, name);
633 public MemberInfo[] GetMembers ()
635 return GetMembers (DefaultBindingFlags);
638 public abstract MemberInfo[] GetMembers (BindingFlags bindingAttr);
640 public MethodInfo GetMethod (string name)
642 if (name == null)
643 throw new ArgumentNullException ("name");
644 return GetMethodImpl (name, DefaultBindingFlags, null, CallingConventions.Any, null, null);
647 public MethodInfo GetMethod (string name, BindingFlags bindingAttr)
649 if (name == null)
650 throw new ArgumentNullException ("name");
652 return GetMethodImpl (name, bindingAttr, null, CallingConventions.Any, null, null);
655 public MethodInfo GetMethod (string name, Type[] types)
657 return GetMethod (name, DefaultBindingFlags, null, CallingConventions.Any, types, null);
660 public MethodInfo GetMethod (string name, Type[] types, ParameterModifier[] modifiers)
662 return GetMethod (name, DefaultBindingFlags, null, CallingConventions.Any, types, modifiers);
665 public MethodInfo GetMethod (string name, BindingFlags bindingAttr, Binder binder,
666 Type[] types, ParameterModifier[] modifiers)
669 return GetMethod (name, bindingAttr, binder, CallingConventions.Any, types, modifiers);
672 public MethodInfo GetMethod (string name, BindingFlags bindingAttr, Binder binder,
673 CallingConventions callConvention, Type[] types, ParameterModifier[] modifiers)
675 if (name == null)
676 throw new ArgumentNullException ("name");
677 if (types == null)
678 throw new ArgumentNullException ("types");
680 for (int i = 0; i < types.Length; i++)
681 if (types[i] == null)
682 throw new ArgumentNullException ("types");
684 return GetMethodImpl (name, bindingAttr, binder, callConvention, types, modifiers);
687 protected abstract MethodInfo GetMethodImpl (string name, BindingFlags bindingAttr, Binder binder,
688 CallingConventions callConvention, Type[] types,
689 ParameterModifier[] modifiers);
691 public MethodInfo[] GetMethods ()
693 return GetMethods (DefaultBindingFlags);
696 public abstract MethodInfo[] GetMethods (BindingFlags bindingAttr);
698 public Type GetNestedType (string name)
700 return GetNestedType (name, DefaultBindingFlags);
703 public abstract Type GetNestedType (string name, BindingFlags bindingAttr);
705 public Type[] GetNestedTypes ()
707 return GetNestedTypes (DefaultBindingFlags);
710 public abstract Type[] GetNestedTypes (BindingFlags bindingAttr);
713 public PropertyInfo[] GetProperties ()
715 return GetProperties (DefaultBindingFlags);
718 public abstract PropertyInfo[] GetProperties (BindingFlags bindingAttr);
721 public PropertyInfo GetProperty (string name)
723 if (name == null)
724 throw new ArgumentNullException ("name");
726 return GetPropertyImpl (name, DefaultBindingFlags, null, null, new Type[0], null);
729 public PropertyInfo GetProperty (string name, BindingFlags bindingAttr)
731 if (name == null)
732 throw new ArgumentNullException ("name");
733 return GetPropertyImpl (name, bindingAttr, null, null, new Type[0], null);
736 public PropertyInfo GetProperty (string name, Type returnType)
738 if (name == null)
739 throw new ArgumentNullException ("name");
740 return GetPropertyImpl (name, DefaultBindingFlags, null, returnType, new Type[0], null);
743 public PropertyInfo GetProperty (string name, Type[] types)
745 return GetProperty (name, DefaultBindingFlags, null, null, types, null);
748 public PropertyInfo GetProperty (string name, Type returnType, Type[] types)
750 return GetProperty (name, DefaultBindingFlags, null, returnType, types, null);
753 public PropertyInfo GetProperty( string name, Type returnType, Type[] types, ParameterModifier[] modifiers)
755 return GetProperty (name, DefaultBindingFlags, null, returnType, types, modifiers);
758 public PropertyInfo GetProperty (string name, BindingFlags bindingAttr, Binder binder, Type returnType,
759 Type[] types, ParameterModifier[] modifiers)
761 if (name == null)
762 throw new ArgumentNullException ("name");
763 if (types == null)
764 throw new ArgumentNullException ("types");
766 return GetPropertyImpl (name, bindingAttr, binder, returnType, types, modifiers);
769 protected abstract PropertyInfo GetPropertyImpl (string name, BindingFlags bindingAttr, Binder binder,
770 Type returnType, Type[] types, ParameterModifier[] modifiers);
772 protected abstract ConstructorInfo GetConstructorImpl (BindingFlags bindingAttr,
773 Binder binder,
774 CallingConventions callConvention,
775 Type[] types,
776 ParameterModifier[] modifiers);
778 protected abstract TypeAttributes GetAttributeFlagsImpl ();
779 protected abstract bool HasElementTypeImpl ();
780 protected abstract bool IsArrayImpl ();
781 protected abstract bool IsByRefImpl ();
782 protected abstract bool IsCOMObjectImpl ();
783 protected abstract bool IsPointerImpl ();
784 protected abstract bool IsPrimitiveImpl ();
786 [MethodImplAttribute(MethodImplOptions.InternalCall)]
787 internal static extern bool IsArrayImpl (Type type);
789 protected virtual bool IsValueTypeImpl ()
791 if (this == typeof (Enum) || this == typeof (ValueType))
792 return false;
794 return IsSubclassOf (typeof (ValueType));
797 protected virtual bool IsContextfulImpl ()
799 return typeof (ContextBoundObject).IsAssignableFrom (this);
802 protected virtual bool IsMarshalByRefImpl ()
804 return typeof (MarshalByRefObject).IsAssignableFrom (this);
807 public ConstructorInfo GetConstructor (Type[] types)
809 return GetConstructorImpl (
810 DefaultBindingFlags, null, CallingConventions.Any, types, null);
813 public ConstructorInfo GetConstructor (BindingFlags bindingAttr, Binder binder,
814 Type[] types, ParameterModifier[] modifiers)
816 return GetConstructorImpl (
817 bindingAttr, binder, CallingConventions.Any, types, modifiers);
820 public ConstructorInfo GetConstructor (BindingFlags bindingAttr, Binder binder,
821 CallingConventions callConvention,
822 Type[] types, ParameterModifier[] modifiers)
824 if (types == null)
825 throw new ArgumentNullException ("types");
827 return GetConstructorImpl (bindingAttr, binder, callConvention, types, modifiers);
830 public ConstructorInfo[] GetConstructors ()
832 return GetConstructors (BindingFlags.Public | BindingFlags.Instance);
835 public abstract ConstructorInfo[] GetConstructors (BindingFlags bindingAttr);
837 public virtual MemberInfo[] GetDefaultMembers ()
839 object [] att = GetCustomAttributes (typeof (DefaultMemberAttribute), true);
840 if (att.Length == 0)
841 return new MemberInfo [0];
843 MemberInfo [] member = GetMember (((DefaultMemberAttribute) att [0]).MemberName);
844 return (member != null) ? member : new MemberInfo [0];
847 public virtual MemberInfo[] FindMembers (MemberTypes memberType, BindingFlags bindingAttr,
848 MemberFilter filter, object filterCriteria)
850 MemberInfo[] result;
851 ArrayList l = new ArrayList ();
853 // Console.WriteLine ("FindMembers for {0} (Type: {1}): {2}",
854 // this.FullName, this.GetType().FullName, this.obj_address());
856 if ((memberType & MemberTypes.Constructor) != 0) {
857 ConstructorInfo[] c = GetConstructors (bindingAttr);
858 if (filter != null) {
859 foreach (MemberInfo m in c) {
860 if (filter (m, filterCriteria))
861 l.Add (m);
863 } else {
864 l.AddRange (c);
867 if ((memberType & MemberTypes.Event) != 0) {
868 EventInfo[] c = GetEvents (bindingAttr);
869 if (filter != null) {
870 foreach (MemberInfo m in c) {
871 if (filter (m, filterCriteria))
872 l.Add (m);
874 } else {
875 l.AddRange (c);
878 if ((memberType & MemberTypes.Field) != 0) {
879 FieldInfo[] c = GetFields (bindingAttr);
880 if (filter != null) {
881 foreach (MemberInfo m in c) {
882 if (filter (m, filterCriteria))
883 l.Add (m);
885 } else {
886 l.AddRange (c);
889 if ((memberType & MemberTypes.Method) != 0) {
890 MethodInfo[] c = GetMethods (bindingAttr);
891 if (filter != null) {
892 foreach (MemberInfo m in c) {
893 if (filter (m, filterCriteria))
894 l.Add (m);
896 } else {
897 l.AddRange (c);
900 if ((memberType & MemberTypes.Property) != 0) {
901 PropertyInfo[] c;
902 int count = l.Count;
903 Type ptype;
904 if (filter != null) {
905 ptype = this;
906 while ((l.Count == count) && (ptype != null)) {
907 c = ptype.GetProperties (bindingAttr);
908 foreach (MemberInfo m in c) {
909 if (filter (m, filterCriteria))
910 l.Add (m);
912 ptype = ptype.BaseType;
914 } else {
915 c = GetProperties (bindingAttr);
916 l.AddRange (c);
919 if ((memberType & MemberTypes.NestedType) != 0) {
920 Type[] c = GetNestedTypes (bindingAttr);
921 if (filter != null) {
922 foreach (MemberInfo m in c) {
923 if (filter (m, filterCriteria)) {
924 l.Add (m);
927 } else {
928 l.AddRange (c);
931 result = new MemberInfo [l.Count];
932 l.CopyTo (result);
933 return result;
936 [DebuggerHidden]
937 [DebuggerStepThrough]
938 public object InvokeMember (string name, BindingFlags invokeAttr, Binder binder, object target, object[] args)
940 return InvokeMember (name, invokeAttr, binder, target, args, null, null, null);
943 [DebuggerHidden]
944 [DebuggerStepThrough]
945 public object InvokeMember (string name, BindingFlags invokeAttr, Binder binder,
946 object target, object[] args, CultureInfo culture)
948 return InvokeMember (name, invokeAttr, binder, target, args, null, culture, null);
951 public abstract object InvokeMember (string name, BindingFlags invokeAttr,
952 Binder binder, object target, object[] args,
953 ParameterModifier[] modifiers,
954 CultureInfo culture, string[] namedParameters);
956 public override string ToString()
958 return FullName;
961 internal object[] GetPseudoCustomAttributes () {
962 int count = 0;
964 /* StructLayoutAttribute is not returned by MS.NET */
966 if (IsSerializable)
967 count ++;
969 if (count == 0)
970 return null;
971 object[] attrs = new object [count];
972 count = 0;
974 if (IsSerializable)
975 attrs [count ++] = new SerializableAttribute ();
977 return attrs;
980 #if NET_2_0 || BOOTSTRAP_NET_2_0
981 public abstract Type[] GetGenericArguments ();
983 public abstract bool HasGenericArguments {
984 get;
987 public abstract bool ContainsGenericParameters {
988 get;
991 public extern bool IsGenericTypeDefinition {
992 [MethodImplAttribute(MethodImplOptions.InternalCall)]
993 get;
996 [MethodImplAttribute(MethodImplOptions.InternalCall)]
997 extern Type GetGenericTypeDefinition_impl ();
999 public virtual Type GetGenericTypeDefinition ()
1001 Type res = GetGenericTypeDefinition_impl ();
1002 if (res == null)
1003 throw new InvalidOperationException ();
1005 return res;
1008 public extern bool IsGenericInstance {
1009 [MethodImplAttribute(MethodImplOptions.InternalCall)]
1010 get;
1013 [MethodImplAttribute(MethodImplOptions.InternalCall)]
1014 static extern Type BindGenericParameters (Type gt, Type [] types);
1016 public Type BindGenericParameters (Type [] types)
1018 if (types == null)
1019 throw new ArgumentNullException ("types");
1020 foreach (Type t in types) {
1021 if (t == null)
1022 throw new ArgumentNullException ("types");
1024 Type res = BindGenericParameters (this, types);
1025 if (res == null)
1026 throw new TypeLoadException ();
1027 return res;
1030 public abstract bool IsGenericParameter {
1031 get;
1034 [MethodImplAttribute(MethodImplOptions.InternalCall)]
1035 extern int GetGenericParameterPosition ();
1037 public virtual int GenericParameterPosition {
1038 get {
1039 int res = GetGenericParameterPosition ();
1040 if (res < 0)
1041 throw new InvalidOperationException ();
1042 return res;
1046 [MethodImplAttribute(MethodImplOptions.InternalCall)]
1047 extern GenericParameterAttributes GetGenericParameterAttributes ();
1049 public virtual GenericParameterAttributes GenericParameterAttributes {
1050 get {
1051 if (!IsGenericParameter)
1052 throw new InvalidOperationException ();
1054 return GetGenericParameterAttributes ();
1058 [MethodImplAttribute(MethodImplOptions.InternalCall)]
1059 extern Type[] GetGenericParameterConstraints_impl ();
1061 public virtual Type[] GetGenericParameterConstraints ()
1063 if (!IsGenericParameter)
1064 throw new InvalidOperationException ();
1066 return GetGenericParameterConstraints_impl ();
1069 public abstract MethodInfo DeclaringMethod {
1070 get;
1073 [MethodImplAttribute(MethodImplOptions.InternalCall)]
1074 extern Type make_array_type (int rank);
1076 public virtual Type MakeArrayType ()
1078 return MakeArrayType (1);
1081 public virtual Type MakeArrayType (int rank)
1083 if (rank < 1)
1084 throw new IndexOutOfRangeException ();
1085 return make_array_type (rank);
1088 [MethodImplAttribute(MethodImplOptions.InternalCall)]
1089 extern Type make_byref_type ();
1091 public virtual Type MakeByRefType ()
1093 return make_byref_type ();
1096 [MethodImplAttribute(MethodImplOptions.InternalCall)]
1097 public extern virtual Type MakePointerType ();
1099 [MonoTODO]
1100 public static Type ReflectionOnlyGetType (string typeName,
1101 bool throwIfNotFound,
1102 bool ignoreCase)
1104 throw new NotImplementedException ();
1107 [MethodImplAttribute(MethodImplOptions.InternalCall)]
1108 extern void GetPacking (out int packing, out int size);
1110 public virtual StructLayoutAttribute StructLayoutAttribute {
1111 get {
1112 LayoutKind kind;
1114 if (IsLayoutSequential)
1115 kind = LayoutKind.Sequential;
1116 else if (IsExplicitLayout)
1117 kind = LayoutKind.Explicit;
1118 else
1119 kind = LayoutKind.Auto;
1121 StructLayoutAttribute attr = new StructLayoutAttribute (kind);
1123 if (IsUnicodeClass)
1124 attr.CharSet = CharSet.Unicode;
1125 else if (IsAnsiClass)
1126 attr.CharSet = CharSet.Ansi;
1127 else
1128 attr.CharSet = CharSet.Auto;
1130 if (kind != LayoutKind.Auto)
1131 GetPacking (out attr.Pack, out attr.Size);
1133 return attr;
1136 #endif