Fix the mobile mscorlib build.
[mono-project.git] / mcs / class / corlib / System / Type.cs
blobb07e088c684c6f569f9a11f4c151fea16f18f78a
1 //
2 // System.Type.cs
3 //
4 // Authors:
5 // Miguel de Icaza (miguel@ximian.com)
6 // Marek Safar (marek.safar@gmail.com)
7 //
8 // (C) Ximian, Inc. http://www.ximian.com
9 //
12 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
14 // Permission is hereby granted, free of charge, to any person obtaining
15 // a copy of this software and associated documentation files (the
16 // "Software"), to deal in the Software without restriction, including
17 // without limitation the rights to use, copy, modify, merge, publish,
18 // distribute, sublicense, and/or sell copies of the Software, and to
19 // permit persons to whom the Software is furnished to do so, subject to
20 // the following conditions:
21 //
22 // The above copyright notice and this permission notice shall be
23 // included in all copies or substantial portions of the Software.
24 //
25 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
26 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
27 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
28 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
29 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
30 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
31 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
34 using System.Diagnostics;
35 using System.Reflection;
36 #if !FULL_AOT_RUNTIME
37 using System.Reflection.Emit;
38 #endif
39 using System.Collections;
40 using System.Collections.Generic;
41 using System.Runtime.InteropServices;
42 using System.Runtime.CompilerServices;
43 using System.Threading;
44 using System.Globalization;
46 namespace System {
48 [Serializable]
49 [ClassInterface (ClassInterfaceType.None)]
50 [ComVisible (true)]
51 [ComDefaultInterface (typeof (_Type))]
52 [StructLayout (LayoutKind.Sequential)]
53 #if MOBILE
54 public abstract class Type : MemberInfo, IReflect {
55 #else
56 public abstract class Type : MemberInfo, IReflect, _Type {
57 #endif
59 internal RuntimeTypeHandle _impl;
61 public static readonly char Delimiter = '.';
62 public static readonly Type[] EmptyTypes = {};
63 public static readonly MemberFilter FilterAttribute = new MemberFilter (FilterAttribute_impl);
64 public static readonly MemberFilter FilterName = new MemberFilter (FilterName_impl);
65 public static readonly MemberFilter FilterNameIgnoreCase = new MemberFilter (FilterNameIgnoreCase_impl);
66 public static readonly object Missing = System.Reflection.Missing.Value;
68 internal const BindingFlags DefaultBindingFlags =
69 BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance;
71 /* implementation of the delegates for MemberFilter */
72 static bool FilterName_impl (MemberInfo m, object filterCriteria)
74 string name = (string) filterCriteria;
75 if (name == null || name.Length == 0 )
76 return false; // because m.Name cannot be null or empty
78 if (name [name.Length - 1] == '*')
79 return m.Name.StartsWithOrdinalUnchecked (name.Substring (0, name.Length - 1));
81 return m.Name == name;
84 static bool FilterNameIgnoreCase_impl (MemberInfo m, object filterCriteria)
86 string name = (string) filterCriteria;
87 if (name == null || name.Length == 0 )
88 return false; // because m.Name cannot be null or empty
90 if (name [name.Length - 1] == '*')
91 return m.Name.StartsWithOrdinalCaseInsensitiveUnchecked (name.Substring (0, name.Length - 1));
93 return string.CompareOrdinalCaseInsensitiveUnchecked (m.Name, name) == 0;
96 static bool FilterAttribute_impl (MemberInfo m, object filterCriteria)
98 if (!(filterCriteria is int))
99 throw new InvalidFilterCriteriaException ("Int32 value is expected for filter criteria");
101 int flags = (int) filterCriteria;
102 if (m is MethodInfo)
103 return ((int)((MethodInfo)m).Attributes & flags) != 0;
104 if (m is FieldInfo)
105 return ((int)((FieldInfo)m).Attributes & flags) != 0;
106 if (m is PropertyInfo)
107 return ((int)((PropertyInfo)m).Attributes & flags) != 0;
108 if (m is EventInfo)
109 return ((int)((EventInfo)m).Attributes & flags) != 0;
110 return false;
113 protected Type ()
117 /// <summary>
118 /// The assembly where the type is defined.
119 /// </summary>
120 public abstract Assembly Assembly {
121 get;
124 /// <summary>
125 /// Gets the fully qualified name for the type including the
126 /// assembly name where the type is defined.
127 /// </summary>
128 public abstract string AssemblyQualifiedName {
129 get;
132 /// <summary>
133 /// Returns the Attributes associated with the type.
134 /// </summary>
135 public TypeAttributes Attributes {
136 get {
137 return GetAttributeFlagsImpl ();
141 /// <summary>
142 /// Returns the basetype for this type
143 /// </summary>
144 public abstract Type BaseType {
145 get;
148 /// <summary>
149 /// Returns the class that declares the member.
150 /// </summary>
151 public override Type DeclaringType {
152 get {
153 return null;
157 /// <summary>
159 /// </summary>
160 public static Binder DefaultBinder {
161 get {
162 return Binder.DefaultBinder;
166 /// <summary>
167 /// The full name of the type including its namespace
168 /// </summary>
169 public abstract string FullName {
170 get;
173 public abstract Guid GUID {
174 get;
177 public bool HasElementType {
178 get {
179 return HasElementTypeImpl ();
183 public bool IsAbstract {
184 get {
185 return (Attributes & TypeAttributes.Abstract) != 0;
189 public bool IsAnsiClass {
190 get {
191 return (Attributes & TypeAttributes.StringFormatMask)
192 == TypeAttributes.AnsiClass;
196 public bool IsArray {
197 get {
198 return IsArrayImpl ();
202 public bool IsAutoClass {
203 get {
204 return (Attributes & TypeAttributes.StringFormatMask) == TypeAttributes.AutoClass;
208 public bool IsAutoLayout {
209 get {
210 return (Attributes & TypeAttributes.LayoutMask) == TypeAttributes.AutoLayout;
214 public bool IsByRef {
215 get {
216 return IsByRefImpl ();
220 public bool IsClass {
221 get {
222 if (IsInterface)
223 return false;
225 return !IsValueType;
229 public bool IsCOMObject {
230 get {
231 return IsCOMObjectImpl ();
235 #if NET_4_5
236 public virtual bool IsConstructedGenericType {
237 get {
238 throw new NotImplementedException ();
241 #endif
243 public bool IsContextful {
244 get {
245 return IsContextfulImpl ();
249 public
250 #if NET_4_0
251 virtual
252 #endif
253 bool IsEnum {
254 get {
255 return IsSubclassOf (typeof (Enum));
259 public bool IsExplicitLayout {
260 get {
261 return (Attributes & TypeAttributes.LayoutMask) == TypeAttributes.ExplicitLayout;
265 public bool IsImport {
266 get {
267 return (Attributes & TypeAttributes.Import) != 0;
271 public bool IsInterface {
272 get {
273 return (Attributes & TypeAttributes.ClassSemanticsMask) == TypeAttributes.Interface;
277 public bool IsLayoutSequential {
278 get {
279 return (Attributes & TypeAttributes.LayoutMask) == TypeAttributes.SequentialLayout;
283 public bool IsMarshalByRef {
284 get {
285 return IsMarshalByRefImpl ();
289 public bool IsNestedAssembly {
290 get {
291 return (Attributes & TypeAttributes.VisibilityMask) == TypeAttributes.NestedAssembly;
295 public bool IsNestedFamANDAssem {
296 get {
297 return (Attributes & TypeAttributes.VisibilityMask) == TypeAttributes.NestedFamANDAssem;
301 public bool IsNestedFamily {
302 get {
303 return (Attributes & TypeAttributes.VisibilityMask) == TypeAttributes.NestedFamily;
307 public bool IsNestedFamORAssem {
308 get {
309 return (Attributes & TypeAttributes.VisibilityMask) == TypeAttributes.NestedFamORAssem;
313 public bool IsNestedPrivate {
314 get {
315 return (Attributes & TypeAttributes.VisibilityMask) == TypeAttributes.NestedPrivate;
319 public bool IsNestedPublic {
320 get {
321 return (Attributes & TypeAttributes.VisibilityMask) == TypeAttributes.NestedPublic;
325 public bool IsNotPublic {
326 get {
327 return (Attributes & TypeAttributes.VisibilityMask) == TypeAttributes.NotPublic;
331 public bool IsPointer {
332 get {
333 return IsPointerImpl ();
337 public bool IsPrimitive {
338 get {
339 return IsPrimitiveImpl ();
343 public bool IsPublic {
344 get {
345 return (Attributes & TypeAttributes.VisibilityMask) == TypeAttributes.Public;
349 public bool IsSealed {
350 get {
351 return (Attributes & TypeAttributes.Sealed) != 0;
355 public
356 #if NET_4_0
357 virtual
358 #endif
359 bool IsSerializable {
360 get {
361 if ((Attributes & TypeAttributes.Serializable) != 0)
362 return true;
364 // Enums and delegates are always serializable
366 Type type = UnderlyingSystemType;
367 if (type == null)
368 return false;
370 // Fast check for system types
371 if (type.IsSystemType)
372 return type_is_subtype_of (type, typeof (Enum), false) || type_is_subtype_of (type, typeof (Delegate), false);
374 // User defined types depend on this behavior
375 do {
376 if ((type == typeof (Enum)) || (type == typeof (Delegate)))
377 return true;
379 type = type.BaseType;
380 } while (type != null);
382 return false;
386 public bool IsSpecialName {
387 get {
388 return (Attributes & TypeAttributes.SpecialName) != 0;
392 public bool IsUnicodeClass {
393 get {
394 return (Attributes & TypeAttributes.StringFormatMask) == TypeAttributes.UnicodeClass;
398 public bool IsValueType {
399 get {
400 return IsValueTypeImpl ();
404 public override MemberTypes MemberType {
405 get {
406 return MemberTypes.TypeInfo;
410 public abstract override Module Module {
411 get;
414 public abstract string Namespace {get;}
416 public override Type ReflectedType {
417 get {
418 return null;
422 public virtual RuntimeTypeHandle TypeHandle {
423 get { throw new ArgumentException ("Derived class must provide implementation."); }
426 [ComVisible (true)]
427 public ConstructorInfo TypeInitializer {
428 get {
429 return GetConstructorImpl (
430 BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static,
431 null,
432 CallingConventions.Any,
433 EmptyTypes,
434 null);
439 * This has NOTHING to do with getting the base type of an enum. Use
440 * Enum.GetUnderlyingType () for that.
442 public abstract Type UnderlyingSystemType {get;}
444 public override bool Equals (object o)
446 #if NET_4_0
447 return Equals (o as Type);
448 #else
449 if (o == this)
450 return true;
452 Type me = UnderlyingSystemType;
453 if (me == null)
454 return false;
455 return me.EqualsInternal (o as Type);
456 #endif
459 #if NET_4_0
460 public virtual bool Equals (Type o)
462 if ((object)o == (object)this)
463 return true;
464 if ((object)o == null)
465 return false;
466 Type me = UnderlyingSystemType;
467 if ((object)me == null)
468 return false;
470 o = o.UnderlyingSystemType;
471 if ((object)o == null)
472 return false;
473 if ((object)o == (object)this)
474 return true;
475 return me.EqualsInternal (o);
477 #else
478 public bool Equals (Type o)
481 if (o == this)
482 return true;
483 if (o == null)
484 return false;
485 Type me = UnderlyingSystemType;
486 if (me == null)
487 return false;
488 return me.EqualsInternal (o.UnderlyingSystemType);
490 #endif
491 #if NET_4_0
492 [MonoTODO ("Implement it properly once 4.0 impl details are known.")]
493 public static bool operator == (Type left, Type right)
495 return Object.ReferenceEquals (left, right);
498 [MonoTODO ("Implement it properly once 4.0 impl details are known.")]
499 public static bool operator != (Type left, Type right)
501 return !Object.ReferenceEquals (left, right);
504 [MonoInternalNote ("Reimplement this in MonoType for bonus speed")]
505 public virtual Type GetEnumUnderlyingType () {
506 if (!IsEnum)
507 throw new ArgumentException ("Type is not an enumeration", "enumType");
509 var fields = GetFields (BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
511 if (fields == null || fields.Length != 1)
512 throw new ArgumentException ("An enum must have exactly one instance field", "enumType");
514 return fields [0].FieldType;
517 [MonoInternalNote ("Reimplement this in MonoType for bonus speed")]
518 public virtual string[] GetEnumNames () {
519 if (!IsEnum)
520 throw new ArgumentException ("Type is not an enumeration", "enumType");
522 var fields = GetFields (BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
524 string [] names = new string [fields.Length];
525 if (0 != names.Length) {
526 for (int i = 0; i < fields.Length; ++i)
527 names [i] = fields [i].Name;
529 var et = GetEnumUnderlyingType ();
530 var values = Array.CreateInstance (et, names.Length);
531 for (int i = 0; i < fields.Length; ++i)
532 values.SetValue (fields [i].GetValue (null), i);
533 MonoEnumInfo.SortEnums (et, values, names);
536 return names;
539 static NotImplementedException CreateNIE () {
540 return new NotImplementedException ();
543 public virtual Array GetEnumValues () {
544 if (!IsEnum)
545 throw new ArgumentException ("Type is not an enumeration", "enumType");
547 throw CreateNIE ();
550 bool IsValidEnumType (Type type) {
551 return (type.IsPrimitive && type != typeof (bool) && type != typeof (double) && type != typeof (float)) || type.IsEnum;
554 [MonoInternalNote ("Reimplement this in MonoType for bonus speed")]
555 public virtual string GetEnumName (object value) {
556 if (value == null)
557 throw new ArgumentException ("Value is null", "value");
558 if (!IsValidEnumType (value.GetType ()))
559 throw new ArgumentException ("Value is not the enum or a valid enum underlying type", "value");
560 if (!IsEnum)
561 throw new ArgumentException ("Type is not an enumeration", "enumType");
563 object obj = null;
564 var fields = GetFields (BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
566 for (int i = 0; i < fields.Length; ++i) {
567 var fv = fields [i].GetValue (null);
568 if (obj == null) {
569 try {
570 //XXX we can't use 'this' as argument as it might be an UserType
571 obj = Enum.ToObject (fv.GetType (), value);
572 } catch (OverflowException) {
573 return null;
574 } catch (InvalidCastException) {
575 throw new ArgumentException ("Value is not valid", "value");
578 if (fv.Equals (obj))
579 return fields [i].Name;
582 return null;
585 [MonoInternalNote ("Reimplement this in MonoType for bonus speed")]
586 public virtual bool IsEnumDefined (object value) {
587 if (value == null)
588 throw new ArgumentException ("Value is null", "value");
589 if (!IsEnum)
590 throw new ArgumentException ("Type is not an enumeration", "enumType");
592 Type vt = value.GetType ();
593 if (!IsValidEnumType (vt) && vt != typeof (string))
594 throw new InvalidOperationException ("Value is not the enum or a valid enum underlying type");
596 var fields = GetFields (BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
598 if (value is string) {
599 for (int i = 0; i < fields.Length; ++i) {
600 if (fields [i].Name.Equals (value))
601 return true;
603 } else {
604 if (vt != this && vt != GetEnumUnderlyingType ())
605 throw new ArgumentException ("Value is not the enum or a valid enum underlying type", "value");
607 object obj = null;
608 for (int i = 0; i < fields.Length; ++i) {
609 var fv = fields [i].GetValue (null);
610 if (obj == null) {
611 try {
612 //XXX we can't use 'this' as argument as it might be an UserType
613 obj = Enum.ToObject (fv.GetType (), value);
614 } catch (OverflowException) {
615 return false;
616 } catch (InvalidCastException) {
617 throw new ArgumentException ("Value is not valid", "value");
620 if (fv.Equals (obj))
621 return true;
624 return false;
627 public static Type GetType (string typeName, Func<AssemblyName,Assembly> assemblyResolver, Func<Assembly,string,bool,Type> typeResolver)
629 return GetType (typeName, assemblyResolver, typeResolver, false, false);
632 public static Type GetType (string typeName, Func<AssemblyName,Assembly> assemblyResolver, Func<Assembly,string,bool,Type> typeResolver, bool throwOnError)
634 return GetType (typeName, assemblyResolver, typeResolver, throwOnError, false);
637 public static Type GetType (string typeName, Func<AssemblyName,Assembly> assemblyResolver, Func<Assembly,string,bool,Type> typeResolver, bool throwOnError, bool ignoreCase)
639 TypeSpec spec = TypeSpec.Parse (typeName);
640 return spec.Resolve (assemblyResolver, typeResolver, throwOnError, ignoreCase);
643 public virtual bool IsSecurityTransparent
645 get { throw CreateNIE (); }
648 public virtual bool IsSecurityCritical
650 get { throw CreateNIE (); }
653 public virtual bool IsSecuritySafeCritical
655 get { throw CreateNIE (); }
657 #endif
659 [MethodImplAttribute(MethodImplOptions.InternalCall)]
660 internal extern bool EqualsInternal (Type type);
662 [MethodImplAttribute(MethodImplOptions.InternalCall)]
663 private static extern Type internal_from_handle (IntPtr handle);
665 [MethodImplAttribute(MethodImplOptions.InternalCall)]
666 private static extern Type internal_from_name (string name, bool throwOnError, bool ignoreCase);
668 public static Type GetType(string typeName)
670 if (typeName == null)
671 throw new ArgumentNullException ("TypeName");
673 return internal_from_name (typeName, false, false);
676 public static Type GetType(string typeName, bool throwOnError)
678 if (typeName == null)
679 throw new ArgumentNullException ("TypeName");
681 Type type = internal_from_name (typeName, throwOnError, false);
682 if (throwOnError && type == null)
683 throw new TypeLoadException ("Error loading '" + typeName + "'");
685 return type;
688 public static Type GetType(string typeName, bool throwOnError, bool ignoreCase)
690 if (typeName == null)
691 throw new ArgumentNullException ("TypeName");
693 Type t = internal_from_name (typeName, throwOnError, ignoreCase);
694 if (throwOnError && t == null)
695 throw new TypeLoadException ("Error loading '" + typeName + "'");
697 return t;
700 public static Type[] GetTypeArray (object[] args) {
701 if (args == null)
702 throw new ArgumentNullException ("args");
704 Type[] ret;
705 ret = new Type [args.Length];
706 for (int i = 0; i < args.Length; ++i)
707 ret [i] = args[i].GetType ();
708 return ret;
711 [MethodImplAttribute(MethodImplOptions.InternalCall)]
712 internal extern static TypeCode GetTypeCodeInternal (Type type);
714 #if NET_4_0
715 protected virtual
716 #endif
717 TypeCode GetTypeCodeImpl () {
718 Type type = this;
719 if (type is MonoType)
720 return GetTypeCodeInternal (type);
721 #if !FULL_AOT_RUNTIME
722 if (type is TypeBuilder)
723 return ((TypeBuilder)type).GetTypeCodeInternal ();
724 #endif
726 type = type.UnderlyingSystemType;
728 if (!type.IsSystemType)
729 return TypeCode.Object;
730 else
731 return GetTypeCodeInternal (type);
734 public static TypeCode GetTypeCode (Type type) {
735 if (type == null)
736 /* MS.NET returns this */
737 return TypeCode.Empty;
738 return type.GetTypeCodeImpl ();
741 #if !FULL_AOT_RUNTIME
742 private static Dictionary<Guid, Type> clsid_types;
743 #if !FULL_AOT_RUNTIME
744 private static AssemblyBuilder clsid_assemblybuilder;
745 #endif
747 [MonoTODO("COM servers only work on Windows")]
748 public static Type GetTypeFromCLSID (Guid clsid)
750 return GetTypeFromCLSID (clsid, null, true);
753 [MonoTODO("COM servers only work on Windows")]
754 public static Type GetTypeFromCLSID (Guid clsid, bool throwOnError)
756 return GetTypeFromCLSID (clsid, null, throwOnError);
759 [MonoTODO("COM servers only work on Windows")]
760 public static Type GetTypeFromCLSID (Guid clsid, string server)
762 return GetTypeFromCLSID (clsid, server, true);
765 [MonoTODO("COM servers only work on Windows")]
766 public static Type GetTypeFromCLSID (Guid clsid, string server, bool throwOnError)
768 #if !FULL_AOT_RUNTIME
769 Type result;
771 if (clsid_types == null)
773 Dictionary<Guid, Type> new_clsid_types = new Dictionary<Guid, Type> ();
774 Interlocked.CompareExchange<Dictionary<Guid, Type>>(
775 ref clsid_types, new_clsid_types, null);
778 lock (clsid_types) {
779 if (clsid_types.TryGetValue(clsid, out result))
780 return result;
782 if (clsid_assemblybuilder == null)
784 AssemblyName assemblyname = new AssemblyName ();
785 assemblyname.Name = "GetTypeFromCLSIDDummyAssembly";
786 clsid_assemblybuilder = AppDomain.CurrentDomain.DefineDynamicAssembly (
787 assemblyname, AssemblyBuilderAccess.Run);
789 ModuleBuilder modulebuilder = clsid_assemblybuilder.DefineDynamicModule (
790 clsid.ToString ());
792 TypeBuilder typebuilder = modulebuilder.DefineType ("System.__ComObject",
793 TypeAttributes.Public | TypeAttributes.Class, typeof(System.__ComObject));
795 Type[] guidattrtypes = new Type[] { typeof(string) };
797 CustomAttributeBuilder customattr = new CustomAttributeBuilder (
798 typeof(GuidAttribute).GetConstructor (guidattrtypes),
799 new object[] { clsid.ToString () });
801 typebuilder.SetCustomAttribute (customattr);
803 customattr = new CustomAttributeBuilder (
804 typeof(ComImportAttribute).GetConstructor (EmptyTypes),
805 new object[0] {});
807 typebuilder.SetCustomAttribute (customattr);
809 result = typebuilder.CreateType ();
811 clsid_types.Add(clsid, result);
813 return result;
815 #else
816 throw new NotImplementedException ();
817 #endif
819 #endif
820 public static Type GetTypeFromHandle (RuntimeTypeHandle handle)
822 if (handle.Value == IntPtr.Zero)
823 // This is not consistent with the other GetXXXFromHandle methods, but
824 // MS.NET seems to do this
825 return null;
827 return internal_from_handle (handle.Value);
830 [MonoTODO("Mono does not support COM")]
831 public static Type GetTypeFromProgID (string progID)
833 throw new NotImplementedException ();
836 [MonoTODO("Mono does not support COM")]
837 public static Type GetTypeFromProgID (string progID, bool throwOnError)
839 throw new NotImplementedException ();
842 [MonoTODO("Mono does not support COM")]
843 public static Type GetTypeFromProgID (string progID, string server)
845 throw new NotImplementedException ();
848 [MonoTODO("Mono does not support COM")]
849 public static Type GetTypeFromProgID (string progID, string server, bool throwOnError)
851 throw new NotImplementedException ();
854 public static RuntimeTypeHandle GetTypeHandle (object o)
856 if (o == null)
857 throw new ArgumentNullException ();
859 return o.GetType().TypeHandle;
862 [MethodImplAttribute(MethodImplOptions.InternalCall)]
863 internal static extern bool type_is_subtype_of (Type a, Type b, bool check_interfaces);
865 [MethodImplAttribute(MethodImplOptions.InternalCall)]
866 internal static extern bool type_is_assignable_from (Type a, Type b);
868 public new Type GetType ()
870 return base.GetType ();
873 [ComVisible (true)]
874 public virtual bool IsSubclassOf (Type c)
876 if (c == null || c == this)
877 return false;
879 // Fast check for system types
880 if (IsSystemType)
881 return c.IsSystemType && type_is_subtype_of (this, c, false);
883 // User defined types depend on this behavior
884 for (Type type = BaseType; type != null; type = type.BaseType)
885 if (type == c)
886 return true;
888 return false;
891 public virtual Type[] FindInterfaces (TypeFilter filter, object filterCriteria)
893 if (filter == null)
894 throw new ArgumentNullException ("filter");
896 var ifaces = new List<Type> ();
897 foreach (Type iface in GetInterfaces ()) {
898 if (filter (iface, filterCriteria))
899 ifaces.Add (iface);
902 return ifaces.ToArray ();
905 public Type GetInterface (string name) {
906 return GetInterface (name, false);
909 public abstract Type GetInterface (string name, bool ignoreCase);
911 [MethodImplAttribute(MethodImplOptions.InternalCall)]
912 internal static extern void GetInterfaceMapData (Type t, Type iface, out MethodInfo[] targets, out MethodInfo[] methods);
914 [ComVisible (true)]
915 public virtual InterfaceMapping GetInterfaceMap (Type interfaceType) {
916 if (!IsSystemType)
917 throw new NotSupportedException ("Derived classes must provide an implementation.");
918 if (interfaceType == null)
919 throw new ArgumentNullException ("interfaceType");
920 if (!interfaceType.IsSystemType)
921 throw new ArgumentException ("interfaceType", "Type is an user type");
922 InterfaceMapping res;
923 if (!interfaceType.IsInterface)
924 throw new ArgumentException (Locale.GetText ("Argument must be an interface."), "interfaceType");
925 if (IsInterface)
926 throw new ArgumentException ("'this' type cannot be an interface itself");
927 res.TargetType = this;
928 res.InterfaceType = interfaceType;
929 GetInterfaceMapData (this, interfaceType, out res.TargetMethods, out res.InterfaceMethods);
930 if (res.TargetMethods == null)
931 throw new ArgumentException (Locale.GetText ("Interface not found"), "interfaceType");
933 return res;
936 public abstract Type[] GetInterfaces ();
938 public virtual bool IsAssignableFrom (Type c)
940 if (c == null)
941 return false;
943 if (Equals (c))
944 return true;
946 #if !FULL_AOT_RUNTIME
947 if (c is TypeBuilder)
948 return ((TypeBuilder)c).IsAssignableTo (this);
949 #endif
951 /* Handle user defined type classes */
952 if (!IsSystemType) {
953 Type systemType = UnderlyingSystemType;
954 if (!systemType.IsSystemType)
955 return false;
957 Type other = c.UnderlyingSystemType;
958 if (!other.IsSystemType)
959 return false;
961 return systemType.IsAssignableFrom (other);
964 if (!c.IsSystemType) {
965 Type underlyingType = c.UnderlyingSystemType;
966 if (!underlyingType.IsSystemType)
967 return false;
968 return IsAssignableFrom (underlyingType);
971 return type_is_assignable_from (this, c);
974 [MethodImplAttribute(MethodImplOptions.InternalCall)]
975 extern static bool IsInstanceOfType (Type type, object o);
977 public virtual bool IsInstanceOfType (object o)
979 Type type = UnderlyingSystemType;
980 if (!type.IsSystemType)
981 return false;
982 return IsInstanceOfType (type, o);
985 public virtual int GetArrayRank ()
987 throw new NotSupportedException (); // according to MSDN
990 public abstract Type GetElementType ();
992 public EventInfo GetEvent (string name)
994 return GetEvent (name, DefaultBindingFlags);
997 public abstract EventInfo GetEvent (string name, BindingFlags bindingAttr);
999 public virtual EventInfo[] GetEvents ()
1001 return GetEvents (DefaultBindingFlags);
1004 public abstract EventInfo[] GetEvents (BindingFlags bindingAttr);
1006 public FieldInfo GetField( string name)
1008 return GetField (name, DefaultBindingFlags);
1011 public abstract FieldInfo GetField( string name, BindingFlags bindingAttr);
1013 public FieldInfo[] GetFields ()
1015 return GetFields (DefaultBindingFlags);
1018 public abstract FieldInfo[] GetFields (BindingFlags bindingAttr);
1020 public override int GetHashCode()
1022 Type t = UnderlyingSystemType;
1023 if (t != null && t != this)
1024 return t.GetHashCode ();
1025 return (int)_impl.Value;
1028 public MemberInfo[] GetMember (string name)
1030 return GetMember (name, MemberTypes.All, DefaultBindingFlags);
1033 public virtual MemberInfo[] GetMember (string name, BindingFlags bindingAttr)
1035 return GetMember (name, MemberTypes.All, bindingAttr);
1038 public virtual MemberInfo[] GetMember (string name, MemberTypes type, BindingFlags bindingAttr)
1040 if (name == null)
1041 throw new ArgumentNullException ("name");
1042 if ((bindingAttr & BindingFlags.IgnoreCase) != 0)
1043 return FindMembers (type, bindingAttr, FilterNameIgnoreCase, name);
1044 else
1045 return FindMembers (type, bindingAttr, FilterName, name);
1048 public MemberInfo[] GetMembers ()
1050 return GetMembers (DefaultBindingFlags);
1053 public abstract MemberInfo[] GetMembers (BindingFlags bindingAttr);
1055 public MethodInfo GetMethod (string name)
1057 if (name == null)
1058 throw new ArgumentNullException ("name");
1059 return GetMethodImpl (name, DefaultBindingFlags, null, CallingConventions.Any, null, null);
1062 public MethodInfo GetMethod (string name, BindingFlags bindingAttr)
1064 if (name == null)
1065 throw new ArgumentNullException ("name");
1067 return GetMethodImpl (name, bindingAttr, null, CallingConventions.Any, null, null);
1070 public MethodInfo GetMethod (string name, Type[] types)
1072 return GetMethod (name, DefaultBindingFlags, null, CallingConventions.Any, types, null);
1075 public MethodInfo GetMethod (string name, Type[] types, ParameterModifier[] modifiers)
1077 return GetMethod (name, DefaultBindingFlags, null, CallingConventions.Any, types, modifiers);
1080 public MethodInfo GetMethod (string name, BindingFlags bindingAttr, Binder binder,
1081 Type[] types, ParameterModifier[] modifiers)
1083 return GetMethod (name, bindingAttr, binder, CallingConventions.Any, types, modifiers);
1086 public MethodInfo GetMethod (string name, BindingFlags bindingAttr, Binder binder,
1087 CallingConventions callConvention, Type[] types, ParameterModifier[] modifiers)
1089 if (name == null)
1090 throw new ArgumentNullException ("name");
1091 if (types == null)
1092 throw new ArgumentNullException ("types");
1094 for (int i = 0; i < types.Length; i++)
1095 if (types[i] == null)
1096 throw new ArgumentNullException ("types");
1098 return GetMethodImpl (name, bindingAttr, binder, callConvention, types, modifiers);
1101 protected abstract MethodInfo GetMethodImpl (string name, BindingFlags bindingAttr, Binder binder,
1102 CallingConventions callConvention, Type[] types,
1103 ParameterModifier[] modifiers);
1105 internal MethodInfo GetMethodImplInternal (string name, BindingFlags bindingAttr, Binder binder,
1106 CallingConventions callConvention, Type[] types,
1107 ParameterModifier[] modifiers)
1109 return GetMethodImpl (name, bindingAttr, binder, callConvention, types, modifiers);
1112 internal virtual MethodInfo GetMethod (MethodInfo fromNoninstanciated)
1114 throw new System.InvalidOperationException ("can only be called in generic type");
1117 internal virtual ConstructorInfo GetConstructor (ConstructorInfo fromNoninstanciated)
1119 throw new System.InvalidOperationException ("can only be called in generic type");
1122 internal virtual FieldInfo GetField (FieldInfo fromNoninstanciated)
1124 throw new System.InvalidOperationException ("can only be called in generic type");
1128 public MethodInfo[] GetMethods ()
1130 return GetMethods (DefaultBindingFlags);
1133 public abstract MethodInfo[] GetMethods (BindingFlags bindingAttr);
1135 public Type GetNestedType (string name)
1137 return GetNestedType (name, DefaultBindingFlags);
1140 public abstract Type GetNestedType (string name, BindingFlags bindingAttr);
1142 public Type[] GetNestedTypes ()
1144 return GetNestedTypes (DefaultBindingFlags);
1147 public abstract Type[] GetNestedTypes (BindingFlags bindingAttr);
1150 public PropertyInfo[] GetProperties ()
1152 return GetProperties (DefaultBindingFlags);
1155 public abstract PropertyInfo[] GetProperties (BindingFlags bindingAttr);
1158 public PropertyInfo GetProperty (string name)
1160 if (name == null)
1161 throw new ArgumentNullException ("name");
1163 return GetPropertyImpl (name, DefaultBindingFlags, null, null, null, null);
1166 public PropertyInfo GetProperty (string name, BindingFlags bindingAttr)
1168 if (name == null)
1169 throw new ArgumentNullException ("name");
1170 return GetPropertyImpl (name, bindingAttr, null, null, null, null);
1173 public PropertyInfo GetProperty (string name, Type returnType)
1175 if (name == null)
1176 throw new ArgumentNullException ("name");
1177 return GetPropertyImpl (name, DefaultBindingFlags, null, returnType, null, null);
1180 public PropertyInfo GetProperty (string name, Type[] types)
1182 return GetProperty (name, DefaultBindingFlags, null, null, types, null);
1185 public PropertyInfo GetProperty (string name, Type returnType, Type[] types)
1187 return GetProperty (name, DefaultBindingFlags, null, returnType, types, null);
1190 public PropertyInfo GetProperty( string name, Type returnType, Type[] types, ParameterModifier[] modifiers)
1192 return GetProperty (name, DefaultBindingFlags, null, returnType, types, modifiers);
1195 public PropertyInfo GetProperty (string name, BindingFlags bindingAttr, Binder binder, Type returnType,
1196 Type[] types, ParameterModifier[] modifiers)
1198 if (name == null)
1199 throw new ArgumentNullException ("name");
1200 if (types == null)
1201 throw new ArgumentNullException ("types");
1203 foreach (Type t in types) {
1204 if (t == null)
1205 throw new ArgumentNullException ("types");
1208 return GetPropertyImpl (name, bindingAttr, binder, returnType, types, modifiers);
1211 protected abstract PropertyInfo GetPropertyImpl (string name, BindingFlags bindingAttr, Binder binder,
1212 Type returnType, Type[] types, ParameterModifier[] modifiers);
1214 internal PropertyInfo GetPropertyImplInternal (string name, BindingFlags bindingAttr, Binder binder,
1215 Type returnType, Type[] types, ParameterModifier[] modifiers)
1217 return GetPropertyImpl (name, bindingAttr, binder, returnType, types, modifiers);
1220 protected abstract ConstructorInfo GetConstructorImpl (BindingFlags bindingAttr,
1221 Binder binder,
1222 CallingConventions callConvention,
1223 Type[] types,
1224 ParameterModifier[] modifiers);
1226 protected abstract TypeAttributes GetAttributeFlagsImpl ();
1227 protected abstract bool HasElementTypeImpl ();
1228 protected abstract bool IsArrayImpl ();
1229 protected abstract bool IsByRefImpl ();
1230 protected abstract bool IsCOMObjectImpl ();
1231 protected abstract bool IsPointerImpl ();
1232 protected abstract bool IsPrimitiveImpl ();
1234 [MethodImplAttribute(MethodImplOptions.InternalCall)]
1235 internal static extern bool IsArrayImpl (Type type);
1237 protected virtual bool IsValueTypeImpl ()
1239 if (this == typeof (ValueType) || this == typeof (Enum))
1240 return false;
1242 return IsSubclassOf (typeof (ValueType));
1245 protected virtual bool IsContextfulImpl ()
1247 return typeof (ContextBoundObject).IsAssignableFrom (this);
1250 protected virtual bool IsMarshalByRefImpl ()
1252 return typeof (MarshalByRefObject).IsAssignableFrom (this);
1255 [ComVisible (true)]
1256 public ConstructorInfo GetConstructor (Type[] types)
1258 return GetConstructor (BindingFlags.Public|BindingFlags.Instance, null, CallingConventions.Any, types, null);
1261 [ComVisible (true)]
1262 public ConstructorInfo GetConstructor (BindingFlags bindingAttr, Binder binder,
1263 Type[] types, ParameterModifier[] modifiers)
1265 return GetConstructor (bindingAttr, binder, CallingConventions.Any, types, modifiers);
1268 [ComVisible (true)]
1269 public ConstructorInfo GetConstructor (BindingFlags bindingAttr, Binder binder,
1270 CallingConventions callConvention,
1271 Type[] types, ParameterModifier[] modifiers)
1273 if (types == null)
1274 throw new ArgumentNullException ("types");
1276 foreach (Type t in types) {
1277 if (t == null)
1278 throw new ArgumentNullException ("types");
1281 return GetConstructorImpl (bindingAttr, binder, callConvention, types, modifiers);
1284 [ComVisible (true)]
1285 public ConstructorInfo[] GetConstructors ()
1287 return GetConstructors (BindingFlags.Public | BindingFlags.Instance);
1290 [ComVisible (true)]
1291 public abstract ConstructorInfo[] GetConstructors (BindingFlags bindingAttr);
1293 public virtual MemberInfo[] GetDefaultMembers ()
1295 object [] att = GetCustomAttributes (typeof (DefaultMemberAttribute), true);
1296 if (att.Length == 0)
1297 return EmptyArray<MemberInfo>.Value;
1299 MemberInfo [] member = GetMember (((DefaultMemberAttribute) att [0]).MemberName);
1300 return (member != null) ? member : EmptyArray<MemberInfo>.Value;
1303 public virtual MemberInfo[] FindMembers (MemberTypes memberType, BindingFlags bindingAttr,
1304 MemberFilter filter, object filterCriteria)
1306 MemberInfo[] result;
1307 ArrayList l = new ArrayList ();
1309 // Console.WriteLine ("FindMembers for {0} (Type: {1}): {2}",
1310 // this.FullName, this.GetType().FullName, this.obj_address());
1311 if ((memberType & MemberTypes.Method) != 0) {
1312 MethodInfo[] c = GetMethods (bindingAttr);
1313 if (filter != null) {
1314 foreach (MemberInfo m in c) {
1315 if (filter (m, filterCriteria))
1316 l.Add (m);
1318 } else {
1319 l.AddRange (c);
1322 if ((memberType & MemberTypes.Constructor) != 0) {
1323 ConstructorInfo[] c = GetConstructors (bindingAttr);
1324 if (filter != null) {
1325 foreach (MemberInfo m in c) {
1326 if (filter (m, filterCriteria))
1327 l.Add (m);
1329 } else {
1330 l.AddRange (c);
1333 if ((memberType & MemberTypes.Property) != 0) {
1334 PropertyInfo[] c = GetProperties (bindingAttr);
1337 if (filter != null) {
1338 foreach (MemberInfo m in c) {
1339 if (filter (m, filterCriteria))
1340 l.Add (m);
1342 } else {
1343 l.AddRange (c);
1347 if ((memberType & MemberTypes.Event) != 0) {
1348 EventInfo[] c = GetEvents (bindingAttr);
1349 if (filter != null) {
1350 foreach (MemberInfo m in c) {
1351 if (filter (m, filterCriteria))
1352 l.Add (m);
1354 } else {
1355 l.AddRange (c);
1358 if ((memberType & MemberTypes.Field) != 0) {
1359 FieldInfo[] c = GetFields (bindingAttr);
1360 if (filter != null) {
1361 foreach (MemberInfo m in c) {
1362 if (filter (m, filterCriteria))
1363 l.Add (m);
1365 } else {
1366 l.AddRange (c);
1369 if ((memberType & MemberTypes.NestedType) != 0) {
1370 Type[] c = GetNestedTypes (bindingAttr);
1371 if (filter != null) {
1372 foreach (MemberInfo m in c) {
1373 if (filter (m, filterCriteria)) {
1374 l.Add (m);
1377 } else {
1378 l.AddRange (c);
1382 switch (memberType) {
1383 case MemberTypes.Constructor :
1384 result = new ConstructorInfo [l.Count];
1385 break;
1386 case MemberTypes.Event :
1387 result = new EventInfo [l.Count];
1388 break;
1389 case MemberTypes.Field :
1390 result = new FieldInfo [l.Count];
1391 break;
1392 case MemberTypes.Method :
1393 result = new MethodInfo [l.Count];
1394 break;
1395 case MemberTypes.NestedType :
1396 case MemberTypes.TypeInfo :
1397 result = new Type [l.Count];
1398 break;
1399 case MemberTypes.Property :
1400 result = new PropertyInfo [l.Count];
1401 break;
1402 default :
1403 result = new MemberInfo [l.Count];
1404 break;
1406 l.CopyTo (result);
1407 return result;
1410 [DebuggerHidden]
1411 [DebuggerStepThrough]
1412 public object InvokeMember (string name, BindingFlags invokeAttr, Binder binder, object target, object[] args)
1414 return InvokeMember (name, invokeAttr, binder, target, args, null, null, null);
1417 [DebuggerHidden]
1418 [DebuggerStepThrough]
1419 public object InvokeMember (string name, BindingFlags invokeAttr, Binder binder,
1420 object target, object[] args, CultureInfo culture)
1422 return InvokeMember (name, invokeAttr, binder, target, args, null, culture, null);
1425 public abstract object InvokeMember (string name, BindingFlags invokeAttr,
1426 Binder binder, object target, object[] args,
1427 ParameterModifier[] modifiers,
1428 CultureInfo culture, string[] namedParameters);
1430 public override string ToString()
1432 return FullName;
1435 internal virtual Type InternalResolve ()
1437 return UnderlyingSystemType;
1440 internal bool IsSystemType {
1441 get {
1442 return _impl.Value != IntPtr.Zero;
1446 #if NET_4_5
1447 public virtual Type[] GenericTypeArguments {
1448 get {
1449 return IsGenericType ? GetGenericArguments () : EmptyTypes;
1452 #endif
1454 public virtual Type[] GetGenericArguments ()
1456 throw new NotSupportedException ();
1459 public virtual bool ContainsGenericParameters {
1460 get { return false; }
1463 public virtual extern bool IsGenericTypeDefinition {
1464 [MethodImplAttribute(MethodImplOptions.InternalCall)]
1465 get;
1468 [MethodImplAttribute(MethodImplOptions.InternalCall)]
1469 internal extern Type GetGenericTypeDefinition_impl ();
1471 public virtual Type GetGenericTypeDefinition ()
1473 throw new NotSupportedException ("Derived classes must provide an implementation.");
1476 public virtual extern bool IsGenericType {
1477 [MethodImplAttribute(MethodImplOptions.InternalCall)]
1478 get;
1481 [MethodImplAttribute(MethodImplOptions.InternalCall)]
1482 static extern Type MakeGenericType (Type gt, Type [] types);
1484 public virtual Type MakeGenericType (params Type[] typeArguments)
1486 if (IsUserType)
1487 throw new NotSupportedException ();
1488 if (!IsGenericTypeDefinition)
1489 throw new InvalidOperationException ("not a generic type definition");
1490 if (typeArguments == null)
1491 throw new ArgumentNullException ("typeArguments");
1492 if (GetGenericArguments().Length != typeArguments.Length)
1493 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, typeArguments.Length), "typeArguments");
1495 bool hasUserType = false;
1497 Type[] systemTypes = new Type[typeArguments.Length];
1498 for (int i = 0; i < typeArguments.Length; ++i) {
1499 Type t = typeArguments [i];
1500 if (t == null)
1501 throw new ArgumentNullException ("typeArguments");
1503 if (!(t is MonoType))
1504 hasUserType = true;
1505 systemTypes [i] = t;
1508 if (hasUserType) {
1509 #if FULL_AOT_RUNTIME
1510 throw new NotSupportedException ("User types are not supported under full aot");
1511 #else
1512 return new MonoGenericClass (this, typeArguments);
1513 #endif
1516 Type res = MakeGenericType (this, systemTypes);
1517 if (res == null)
1518 throw new TypeLoadException ();
1519 return res;
1522 public virtual bool IsGenericParameter {
1523 get {
1524 return false;
1528 public bool IsNested {
1529 get {
1530 return DeclaringType != null;
1534 public bool IsVisible {
1535 get {
1536 if (IsNestedPublic)
1537 return DeclaringType.IsVisible;
1539 return IsPublic;
1543 [MethodImplAttribute(MethodImplOptions.InternalCall)]
1544 extern int GetGenericParameterPosition ();
1546 public virtual int GenericParameterPosition {
1547 get {
1548 int res = GetGenericParameterPosition ();
1549 if (res < 0)
1550 throw new InvalidOperationException ();
1551 return res;
1555 [MethodImplAttribute(MethodImplOptions.InternalCall)]
1556 extern GenericParameterAttributes GetGenericParameterAttributes ();
1558 public virtual GenericParameterAttributes GenericParameterAttributes {
1559 get {
1560 if (!IsSystemType)
1561 throw new NotSupportedException ("Derived classes must provide an implementation.");
1563 if (!IsGenericParameter)
1564 throw new InvalidOperationException ();
1566 return GetGenericParameterAttributes ();
1570 [MethodImplAttribute(MethodImplOptions.InternalCall)]
1571 extern Type[] GetGenericParameterConstraints_impl ();
1573 public virtual Type[] GetGenericParameterConstraints ()
1575 if (!IsSystemType)
1576 throw new InvalidOperationException ();
1578 if (!IsGenericParameter)
1579 throw new InvalidOperationException ();
1581 return GetGenericParameterConstraints_impl ();
1584 public virtual MethodBase DeclaringMethod {
1585 get {
1586 return null;
1590 [MethodImplAttribute(MethodImplOptions.InternalCall)]
1591 extern Type make_array_type (int rank);
1593 public virtual Type MakeArrayType ()
1595 if (!IsSystemType)
1596 throw new NotSupportedException ("Derived classes must provide an implementation.");
1597 return make_array_type (0);
1600 public virtual Type MakeArrayType (int rank)
1602 if (!IsSystemType)
1603 throw new NotSupportedException ("Derived classes must provide an implementation.");
1604 if (rank < 1 || rank > 255)
1605 throw new IndexOutOfRangeException ();
1606 return make_array_type (rank);
1609 [MethodImplAttribute(MethodImplOptions.InternalCall)]
1610 extern Type make_byref_type ();
1612 public virtual Type MakeByRefType ()
1614 if (!IsSystemType)
1615 throw new NotSupportedException ("Derived classes must provide an implementation.");
1616 if (IsByRef)
1617 throw new TypeLoadException ("Can not call MakeByRefType on a ByRef type");
1618 return make_byref_type ();
1621 [MethodImplAttribute(MethodImplOptions.InternalCall)]
1622 static extern Type MakePointerType (Type type);
1624 public virtual Type MakePointerType ()
1626 if (!IsSystemType)
1627 throw new NotSupportedException ("Derived classes must provide an implementation.");
1628 return MakePointerType (this);
1631 public static Type ReflectionOnlyGetType (string typeName,
1632 bool throwIfNotFound,
1633 bool ignoreCase)
1635 if (typeName == null)
1636 throw new ArgumentNullException ("typeName");
1637 int idx = typeName.IndexOf (',');
1638 if (idx < 0 || idx == 0 || idx == typeName.Length - 1)
1639 throw new ArgumentException ("Assembly qualifed type name is required", "typeName");
1640 string an = typeName.Substring (idx + 1);
1641 Assembly a;
1642 try {
1643 a = Assembly.ReflectionOnlyLoad (an);
1644 } catch {
1645 if (throwIfNotFound)
1646 throw;
1647 return null;
1649 return a.GetType (typeName.Substring (0, idx), throwIfNotFound, ignoreCase);
1652 [MethodImplAttribute(MethodImplOptions.InternalCall)]
1653 extern void GetPacking (out int packing, out int size);
1655 public virtual StructLayoutAttribute StructLayoutAttribute {
1656 get {
1657 #if NET_4_0
1658 throw new NotSupportedException ();
1659 #else
1660 return GetStructLayoutAttribute ();
1661 #endif
1665 internal StructLayoutAttribute GetStructLayoutAttribute ()
1667 LayoutKind kind;
1669 if (IsLayoutSequential)
1670 kind = LayoutKind.Sequential;
1671 else if (IsExplicitLayout)
1672 kind = LayoutKind.Explicit;
1673 else
1674 kind = LayoutKind.Auto;
1676 StructLayoutAttribute attr = new StructLayoutAttribute (kind);
1678 if (IsUnicodeClass)
1679 attr.CharSet = CharSet.Unicode;
1680 else if (IsAnsiClass)
1681 attr.CharSet = CharSet.Ansi;
1682 else
1683 attr.CharSet = CharSet.Auto;
1685 if (kind != LayoutKind.Auto) {
1686 int packing;
1687 GetPacking (out packing, out attr.Size);
1688 // 0 means no data provided, we end up with default value
1689 if (packing != 0)
1690 attr.Pack = packing;
1693 return attr;
1696 internal object[] GetPseudoCustomAttributes ()
1698 int count = 0;
1700 /* IsSerializable returns true for delegates/enums as well */
1701 if ((Attributes & TypeAttributes.Serializable) != 0)
1702 count ++;
1703 if ((Attributes & TypeAttributes.Import) != 0)
1704 count ++;
1706 if (count == 0)
1707 return null;
1708 object[] attrs = new object [count];
1709 count = 0;
1711 if ((Attributes & TypeAttributes.Serializable) != 0)
1712 attrs [count ++] = new SerializableAttribute ();
1713 if ((Attributes & TypeAttributes.Import) != 0)
1714 attrs [count ++] = new ComImportAttribute ();
1716 return attrs;
1720 #if NET_4_0
1721 public virtual bool IsEquivalentTo (Type other)
1723 return this == other;
1725 #endif
1728 * Return whenever this object is an instance of a user defined subclass
1729 * of System.Type or an instance of TypeDelegator.
1730 * A user defined type is not simply the opposite of a system type.
1731 * It's any class that's neither a SRE or runtime baked type.
1733 internal virtual bool IsUserType {
1734 get {
1735 return true;
1739 #if !MOBILE
1740 void _Type.GetIDsOfNames ([In] ref Guid riid, IntPtr rgszNames, uint cNames, uint lcid, IntPtr rgDispId)
1742 throw new NotImplementedException ();
1745 void _Type.GetTypeInfo (uint iTInfo, uint lcid, IntPtr ppTInfo)
1747 throw new NotImplementedException ();
1750 void _Type.GetTypeInfoCount (out uint pcTInfo)
1752 throw new NotImplementedException ();
1755 void _Type.Invoke (uint dispIdMember, [In] ref Guid riid, uint lcid, short wFlags, IntPtr pDispParams, IntPtr pVarResult, IntPtr pExcepInfo, IntPtr puArgErr)
1757 throw new NotImplementedException ();
1759 #endif