2010-01-20 Zoltan Varga <vargaz@gmail.com>
[mono.git] / mcs / class / corlib / System / Type.cs
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 //
9
10 //
11 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
12 //
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.
31 //
32
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;
40
41 namespace System {
42
43         [Serializable]
44         [ClassInterface (ClassInterfaceType.None)]
45         [ComVisible (true)]
46         [ComDefaultInterface (typeof (_Type))]
47         public abstract class Type : MemberInfo, IReflect, _Type {
48                 
49                 internal RuntimeTypeHandle _impl;
50
51                 public static readonly char Delimiter = '.';
52                 public static readonly Type[] EmptyTypes = {};
53                 public static readonly MemberFilter FilterAttribute = new MemberFilter (FilterAttribute_impl);
54                 public static readonly MemberFilter FilterName = new MemberFilter (FilterName_impl);
55                 public static readonly MemberFilter FilterNameIgnoreCase = new MemberFilter (FilterNameIgnoreCase_impl);
56                 public static readonly object Missing = System.Reflection.Missing.Value;
57
58                 internal const BindingFlags DefaultBindingFlags =
59                 BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance;
60
61                 /* implementation of the delegates for MemberFilter */
62                 static bool FilterName_impl (MemberInfo m, object filterCriteria)
63                 {
64                         string name = (string) filterCriteria;
65                         if (name == null || name.Length == 0 )
66                                 return false; // because m.Name cannot be null or empty
67                                 
68                         if (name [name.Length-1] == '*')
69                                 return string.CompareOrdinal (name, 0, m.Name, 0, name.Length-1) == 0;
70
71                 return name.Equals (m.Name);                    
72                 }
73
74                 static bool FilterNameIgnoreCase_impl (MemberInfo m, object filterCriteria)
75                 {
76                         string name = (string) filterCriteria;
77                         if (name == null || name.Length == 0 )
78                                 return false; // because m.Name cannot be null or empty
79                                 
80                         if (name [name.Length-1] == '*')
81                                 return string.Compare (name, 0, m.Name, 0, name.Length-1, StringComparison.OrdinalIgnoreCase) == 0;
82
83                         return string.Equals (name, m.Name, StringComparison.OrdinalIgnoreCase);
84                 }
85
86                 static bool FilterAttribute_impl (MemberInfo m, object filterCriteria)
87                 {
88                         int flags = ((IConvertible)filterCriteria).ToInt32 (null);
89                         if (m is MethodInfo)
90                                 return ((int)((MethodInfo)m).Attributes & flags) != 0;
91                         if (m is FieldInfo)
92                                 return ((int)((FieldInfo)m).Attributes & flags) != 0;
93                         if (m is PropertyInfo)
94                                 return ((int)((PropertyInfo)m).Attributes & flags) != 0;
95                         if (m is EventInfo)
96                                 return ((int)((EventInfo)m).Attributes & flags) != 0;
97                         return false;
98                 }
99
100                 protected Type ()
101                 {
102                 }
103
104                 /// <summary>
105                 ///   The assembly where the type is defined.
106                 /// </summary>
107                 public abstract Assembly Assembly {
108                         get;
109                 }
110
111                 /// <summary>
112                 ///   Gets the fully qualified name for the type including the
113                 ///   assembly name where the type is defined.
114                 /// </summary>
115                 public abstract string AssemblyQualifiedName {
116                         get;
117                 }
118
119                 /// <summary>
120                 ///   Returns the Attributes associated with the type.
121                 /// </summary>
122                 public TypeAttributes Attributes {
123                         get {
124                                 return GetAttributeFlagsImpl ();
125                         }
126                 }
127
128                 /// <summary>
129                 ///   Returns the basetype for this type
130                 /// </summary>
131                 public abstract Type BaseType {
132                         get;
133                 }
134
135                 /// <summary>
136                 ///   Returns the class that declares the member.
137                 /// </summary>
138                 public override Type DeclaringType {
139                         get {
140                                 return null;
141                         }
142                 }
143
144                 /// <summary>
145                 ///
146                 /// </summary>
147                 public static Binder DefaultBinder {
148                         get {
149                                 return Binder.DefaultBinder;
150                         }
151                 }
152
153                 /// <summary>
154                 ///    The full name of the type including its namespace
155                 /// </summary>
156                 public abstract string FullName {
157                         get;
158                 }
159
160                 public abstract Guid GUID {
161                         get;
162                 }
163
164                 public bool HasElementType {
165                         get {
166                                 return HasElementTypeImpl ();
167                         }
168                 }
169
170                 public bool IsAbstract {
171                         get {
172                                 return (Attributes & TypeAttributes.Abstract) != 0;
173                         }
174                 }
175
176                 public bool IsAnsiClass {
177                         get {
178                                 return (Attributes & TypeAttributes.StringFormatMask)
179                                 == TypeAttributes.AnsiClass;
180                         }
181                 }
182
183                 public bool IsArray {
184                         get {
185                                 return IsArrayImpl ();
186                         }
187                 }
188
189                 public bool IsAutoClass {
190                         get {
191                                 return (Attributes & TypeAttributes.StringFormatMask) == TypeAttributes.AutoClass;
192                         }
193                 }
194
195                 public bool IsAutoLayout {
196                         get {
197                                 return (Attributes & TypeAttributes.LayoutMask) == TypeAttributes.AutoLayout;
198                         }
199                 }
200
201                 public bool IsByRef {
202                         get {
203                                 return IsByRefImpl ();
204                         }
205                 }
206
207                 public bool IsClass {
208                         get {
209                                 if (IsInterface)
210                                         return false;
211
212                                 return !IsValueType;
213                         }
214                 }
215
216                 public bool IsCOMObject {
217                         get {
218                                 return IsCOMObjectImpl ();
219                         }
220                 }
221
222                 public bool IsContextful {
223                         get {
224                                 return IsContextfulImpl ();
225                         }
226                 }
227
228                 public bool IsEnum {
229                         get {
230                                 return IsSubclassOf (typeof (Enum));
231                         }
232                 }
233
234                 public bool IsExplicitLayout {
235                         get {
236                                 return (Attributes & TypeAttributes.LayoutMask) == TypeAttributes.ExplicitLayout;
237                         }
238                 }
239
240                 public bool IsImport {
241                         get {
242                                 return (Attributes & TypeAttributes.Import) != 0;
243                         }
244                 }
245
246                 public bool IsInterface {
247                         get {
248                                 return (Attributes & TypeAttributes.ClassSemanticsMask) == TypeAttributes.Interface;
249                         }
250                 }
251
252                 public bool IsLayoutSequential {
253                         get {
254                                 return (Attributes & TypeAttributes.LayoutMask) == TypeAttributes.SequentialLayout;
255                         }
256                 }
257
258                 public bool IsMarshalByRef {
259                         get {
260                                 return IsMarshalByRefImpl ();
261                         }
262                 }
263
264                 public bool IsNestedAssembly {
265                         get {
266                                 return (Attributes & TypeAttributes.VisibilityMask) == TypeAttributes.NestedAssembly;
267                         }
268                 }
269
270                 public bool IsNestedFamANDAssem {
271                         get {
272                                 return (Attributes & TypeAttributes.VisibilityMask) == TypeAttributes.NestedFamANDAssem;
273                         }
274                 }
275
276                 public bool IsNestedFamily {
277                         get {
278                                 return (Attributes & TypeAttributes.VisibilityMask) == TypeAttributes.NestedFamily;
279                         }
280                 }
281
282                 public bool IsNestedFamORAssem {
283                         get {
284                                 return (Attributes & TypeAttributes.VisibilityMask) == TypeAttributes.NestedFamORAssem;
285                         }
286                 }
287
288                 public bool IsNestedPrivate {
289                         get {
290                                 return (Attributes & TypeAttributes.VisibilityMask) == TypeAttributes.NestedPrivate;
291                         }
292                 }
293
294                 public bool IsNestedPublic {
295                         get {
296                                 return (Attributes & TypeAttributes.VisibilityMask) == TypeAttributes.NestedPublic;
297                         }
298                 }
299
300                 public bool IsNotPublic {
301                         get {
302                                 return (Attributes & TypeAttributes.VisibilityMask) == TypeAttributes.NotPublic;
303                         }
304                 }
305
306                 public bool IsPointer {
307                         get {
308                                 return IsPointerImpl ();
309                         }
310                 }
311
312                 public bool IsPrimitive {
313                         get {
314                                 return IsPrimitiveImpl ();
315                         }
316                 }
317
318                 public bool IsPublic {
319                         get {
320                                 return (Attributes & TypeAttributes.VisibilityMask) == TypeAttributes.Public;
321                         }
322                 }
323
324                 public bool IsSealed {
325                         get {
326                                 return (Attributes & TypeAttributes.Sealed) != 0;
327                         }
328                 }
329
330                 public bool IsSerializable {
331                         get {
332                                 if ((Attributes & TypeAttributes.Serializable) != 0)
333                                         return true;
334
335                                 // Enums and delegates are always serializable
336
337                                 Type type = UnderlyingSystemType;
338                                 if (type == null)
339                                         return false;
340
341                                 // Fast check for system types
342                                 if (type.IsSystemType)
343                                         return type_is_subtype_of (type, typeof (Enum), false) || type_is_subtype_of (type, typeof (Delegate), false);
344
345                                 // User defined types depend on this behavior
346                                 do {
347                                         if ((type == typeof (Enum)) || (type == typeof (Delegate)))
348                                                 return true;
349
350                                         type = type.BaseType;
351                                 } while (type != null);
352
353                                 return false;
354                         }
355                 }
356
357                 public bool IsSpecialName {
358                         get {
359                                 return (Attributes & TypeAttributes.SpecialName) != 0;
360                         }
361                 }
362
363                 public bool IsUnicodeClass {
364                         get {
365                                 return (Attributes & TypeAttributes.StringFormatMask) == TypeAttributes.UnicodeClass;
366                         }
367                 }
368
369                 public bool IsValueType {
370                         get {
371                                 return IsValueTypeImpl ();
372                         }
373                 }
374
375                 public override MemberTypes MemberType {
376                         get {return MemberTypes.TypeInfo;}
377                 }
378
379                 override
380                 public abstract Module Module {get;}
381         
382                 public abstract string Namespace {get;}
383
384                 public override Type ReflectedType {
385                         get {
386                                 return null;
387                         }
388                 }
389
390                 public virtual RuntimeTypeHandle TypeHandle {
391                         get { throw new ArgumentException ("Derived class must provide implementation."); }
392                 }
393
394                 [ComVisible (true)]
395                 public ConstructorInfo TypeInitializer {
396                         get {
397                                 return GetConstructorImpl (
398                                         BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static,
399                                         null,
400                                         CallingConventions.Any,
401                                         EmptyTypes,
402                                         null);
403                         }
404                 }
405
406                 /*
407                  * This has NOTHING to do with getting the base type of an enum. Use
408                  * Enum.GetUnderlyingType () for that.
409                  */
410                 public abstract Type UnderlyingSystemType {get;}
411
412                 public override bool Equals (object o)
413                 {
414                         if (o == this)
415                                 return true;
416                         Type me = UnderlyingSystemType;
417                         if (me == null)
418                                 return false;
419                         return me.EqualsInternal (o as Type);
420                 }
421
422                 public bool Equals (Type o) {
423                         if (o == this)
424                                 return true;
425                         if (o == null)
426                                 return false;
427                         Type me = UnderlyingSystemType;
428                         if (me == null)
429                                 return false;
430                         return me.EqualsInternal (o.UnderlyingSystemType);
431                 }
432
433 #if NET_4_0
434                 [MonoTODO ("Implement it properly once 4.0 impl details are known.")]
435                 public static bool operator == (Type left, Type right)
436                 {
437                         return Object.ReferenceEquals (left, right);
438                 }
439
440                 [MonoTODO ("Implement it properly once 4.0 impl details are known.")]
441                 public static bool operator != (Type left, Type right)
442                 {
443                         return !Object.ReferenceEquals (left, right);
444                 }
445 #endif
446                 
447                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
448                 internal extern bool EqualsInternal (Type type);
449                 
450                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
451                 private static extern Type internal_from_handle (IntPtr handle);
452                 
453                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
454                 private static extern Type internal_from_name (string name, bool throwOnError, bool ignoreCase);
455
456                 public static Type GetType(string typeName)
457                 {
458                         if (typeName == null)
459                                 throw new ArgumentNullException ("TypeName");
460
461                         return internal_from_name (typeName, false, false);
462                 }
463
464                 public static Type GetType(string typeName, bool throwOnError)
465                 {
466                         if (typeName == null)
467                                 throw new ArgumentNullException ("TypeName");
468
469                         Type type = internal_from_name (typeName, throwOnError, false);
470                         if (throwOnError && type == null)
471                                 throw new TypeLoadException ("Error loading '" + typeName + "'");
472
473                         return type;
474                 }
475
476                 public static Type GetType(string typeName, bool throwOnError, bool ignoreCase)
477                 {
478                         if (typeName == null)
479                                 throw new ArgumentNullException ("TypeName");
480
481                         Type t = internal_from_name (typeName, throwOnError, ignoreCase);
482                         if (throwOnError && t == null)
483                                 throw new TypeLoadException ("Error loading '" + typeName + "'");
484
485                         return t;
486                 }
487
488                 public static Type[] GetTypeArray (object[] args) {
489                         if (args == null)
490                                 throw new ArgumentNullException ("args");
491
492                         Type[] ret;
493                         ret = new Type [args.Length];
494                         for (int i = 0; i < args.Length; ++i)
495                                 ret [i] = args[i].GetType ();
496                         return ret;
497                 }
498
499                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
500                 internal extern static TypeCode GetTypeCodeInternal (Type type);
501
502                 public static TypeCode GetTypeCode (Type type) {
503                         if (type is MonoType)
504                                 return GetTypeCodeInternal (type);
505                         if (type == null)
506                                 /* MS.NET returns this */
507                                 return TypeCode.Empty;
508
509                         type = type.UnderlyingSystemType;
510
511                         if (!type.IsSystemType)
512                                 return TypeCode.Object;
513                         else
514                                 return GetTypeCodeInternal (type);
515                 }
516
517                 [MonoTODO("This operation is currently not supported by Mono")]
518                 public static Type GetTypeFromCLSID (Guid clsid)
519                 {
520                         throw new NotImplementedException ();
521                 }
522
523                 [MonoTODO("This operation is currently not supported by Mono")]
524                 public static Type GetTypeFromCLSID (Guid clsid, bool throwOnError)
525                 {
526                         throw new NotImplementedException ();
527                 }
528
529                 [MonoTODO("This operation is currently not supported by Mono")]
530                 public static Type GetTypeFromCLSID (Guid clsid, string server)
531                 {
532                         throw new NotImplementedException ();
533                 }
534
535                 [MonoTODO("This operation is currently not supported by Mono")]
536                 public static Type GetTypeFromCLSID (Guid clsid, string server, bool throwOnError)
537                 {
538                         throw new NotImplementedException ();
539                 }
540
541                 public static Type GetTypeFromHandle (RuntimeTypeHandle handle)
542                 {
543                         if (handle.Value == IntPtr.Zero)
544                                 // This is not consistent with the other GetXXXFromHandle methods, but
545                                 // MS.NET seems to do this
546                                 return null;
547
548                         return internal_from_handle (handle.Value);
549                 }
550
551                 [MonoTODO("Mono does not support COM")]
552                 public static Type GetTypeFromProgID (string progID)
553                 {
554                         throw new NotImplementedException ();
555                 }
556
557                 [MonoTODO("Mono does not support COM")]
558                 public static Type GetTypeFromProgID (string progID, bool throwOnError)
559                 {
560                         throw new NotImplementedException ();
561                 }
562
563                 [MonoTODO("Mono does not support COM")]
564                 public static Type GetTypeFromProgID (string progID, string server)
565                 {
566                         throw new NotImplementedException ();
567                 }
568
569                 [MonoTODO("Mono does not support COM")]
570                 public static Type GetTypeFromProgID (string progID, string server, bool throwOnError)
571                 {
572                         throw new NotImplementedException ();
573                 }
574
575                 public static RuntimeTypeHandle GetTypeHandle (object o)
576                 {
577                         if (o == null)
578                                 throw new ArgumentNullException ();
579
580                         return o.GetType().TypeHandle;
581                 }
582
583                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
584                 internal static extern bool type_is_subtype_of (Type a, Type b, bool check_interfaces);
585
586                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
587                 internal static extern bool type_is_assignable_from (Type a, Type b);
588
589                 public new Type GetType ()
590                 {
591                         return base.GetType ();
592                 }
593
594                 [ComVisible (true)]
595                 public virtual bool IsSubclassOf (Type c)
596                 {
597                         if (c == null || c == this)
598                                 return false;
599
600                         // Fast check for system types
601                         if (IsSystemType)
602                                 return c.IsSystemType && type_is_subtype_of (this, c, false);
603
604                         // User defined types depend on this behavior
605                         for (Type type = BaseType; type != null; type = type.BaseType)
606                                 if (type == c)
607                                         return true;
608
609                         return false;
610                 }
611
612                 public virtual Type[] FindInterfaces (TypeFilter filter, object filterCriteria)
613                 {
614                         if (filter == null)
615                                 throw new ArgumentNullException ("filter");
616
617                         ArrayList ifaces = new ArrayList ();
618                         foreach (Type iface in GetInterfaces ()) {
619                                 if (filter (iface, filterCriteria))
620                                         ifaces.Add (iface);
621                         }
622
623                         return (Type []) ifaces.ToArray (typeof (Type));
624                 }
625                 
626                 public Type GetInterface (string name) {
627                         return GetInterface (name, false);
628                 }
629
630                 public abstract Type GetInterface (string name, bool ignoreCase);
631
632                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
633                 internal static extern void GetInterfaceMapData (Type t, Type iface, out MethodInfo[] targets, out MethodInfo[] methods);
634
635                 [ComVisible (true)]
636                 public virtual InterfaceMapping GetInterfaceMap (Type interfaceType) {
637                         if (!IsSystemType)
638                                 throw new NotSupportedException ("Derived classes must provide an implementation.");
639                         if (!interfaceType.IsSystemType)
640                                 throw new ArgumentException ("interfaceType", "Type is an user type");
641                         InterfaceMapping res;
642                         if (interfaceType == null)
643                                 throw new ArgumentNullException ("interfaceType");
644                         if (!interfaceType.IsInterface)
645                                 throw new ArgumentException (Locale.GetText ("Argument must be an interface."), "interfaceType");
646                         if (IsInterface)
647                                 throw new ArgumentException ("'this' type cannot be an interface itself");
648                         res.TargetType = this;
649                         res.InterfaceType = interfaceType;
650                         GetInterfaceMapData (this, interfaceType, out res.TargetMethods, out res.InterfaceMethods);
651                         if (res.TargetMethods == null)
652                                 throw new ArgumentException (Locale.GetText ("Interface not found"), "interfaceType");
653
654                         return res;
655                 }
656
657                 public abstract Type[] GetInterfaces ();
658
659                 public virtual bool IsAssignableFrom (Type c)
660                 {
661                         if (c == null)
662                                 return false;
663
664                         if (Equals (c))
665                                 return true;
666
667                         if (c is TypeBuilder)
668                                 return ((TypeBuilder)c).IsAssignableTo (this);
669
670                         /* Handle user defined type classes */
671                         if (!IsSystemType) {
672                                 Type systemType = UnderlyingSystemType;
673                                 if (!systemType.IsSystemType)
674                                         return false;
675
676                                 Type other = c.UnderlyingSystemType;
677                                 if (!other.IsSystemType)
678                                         return false;
679
680                                 return systemType.IsAssignableFrom (other);
681                         }
682
683                         if (!c.IsSystemType) {
684                                 Type underlyingType = c.UnderlyingSystemType;
685                                 if (!underlyingType.IsSystemType)
686                                         return false;
687                                 return IsAssignableFrom (underlyingType);
688                         }
689
690                         return type_is_assignable_from (this, c);
691                 }
692
693                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
694                 extern static bool IsInstanceOfType (Type type, object o);
695
696                 public virtual bool IsInstanceOfType (object o)
697                 {
698                         Type type = UnderlyingSystemType;
699                         if (!type.IsSystemType)
700                                 return false;
701                         return IsInstanceOfType (type, o);
702                 }
703
704                 public virtual int GetArrayRank ()
705                 {
706                         throw new NotSupportedException ();     // according to MSDN
707                 }
708
709                 public abstract Type GetElementType ();
710
711                 public EventInfo GetEvent (string name)
712                 {
713                         return GetEvent (name, DefaultBindingFlags);
714                 }
715
716                 public abstract EventInfo GetEvent (string name, BindingFlags bindingAttr);
717
718                 public virtual EventInfo[] GetEvents ()
719                 {
720                         return GetEvents (DefaultBindingFlags);
721                 }
722
723                 public abstract EventInfo[] GetEvents (BindingFlags bindingAttr);
724
725                 public FieldInfo GetField( string name)
726                 {
727                         return GetField (name, DefaultBindingFlags);
728                 }
729
730                 public abstract FieldInfo GetField( string name, BindingFlags bindingAttr);
731
732                 public FieldInfo[] GetFields ()
733                 {
734                         return GetFields (DefaultBindingFlags);
735                 }
736
737                 public abstract FieldInfo[] GetFields (BindingFlags bindingAttr);
738                 
739                 public override int GetHashCode()
740                 {
741                         Type t = UnderlyingSystemType;
742                         if (t != null && t != this)
743                                 return t.GetHashCode ();
744                         return (int)_impl.Value;
745                 }
746
747                 public MemberInfo[] GetMember (string name)
748                 {
749                         return GetMember (name, MemberTypes.All, DefaultBindingFlags);
750                 }
751                 
752                 public virtual MemberInfo[] GetMember (string name, BindingFlags bindingAttr)
753                 {
754                         return GetMember (name, MemberTypes.All, bindingAttr);
755                 }
756
757                 public virtual MemberInfo[] GetMember (string name, MemberTypes type, BindingFlags bindingAttr)
758                 {
759                         if (name == null)
760                                 throw new ArgumentNullException ("name");
761                         if ((bindingAttr & BindingFlags.IgnoreCase) != 0)
762                                 return FindMembers (type, bindingAttr, FilterNameIgnoreCase, name);
763                         else
764                                 return FindMembers (type, bindingAttr, FilterName, name);
765                 }
766
767                 public MemberInfo[] GetMembers ()
768                 {
769                         return GetMembers (DefaultBindingFlags);
770                 }
771
772                 public abstract MemberInfo[] GetMembers (BindingFlags bindingAttr);
773
774                 public MethodInfo GetMethod (string name)
775                 {
776                         if (name == null)
777                                 throw new ArgumentNullException ("name");
778                         return GetMethodImpl (name, DefaultBindingFlags, null, CallingConventions.Any, null, null);
779                 }
780
781                 public MethodInfo GetMethod (string name, BindingFlags bindingAttr)
782                 {
783                         if (name == null)
784                                 throw new ArgumentNullException ("name");
785                         
786                         return GetMethodImpl (name, bindingAttr, null, CallingConventions.Any, null, null);
787                 }
788                 
789                 public MethodInfo GetMethod (string name, Type[] types)
790                 {
791                         return GetMethod (name, DefaultBindingFlags, null, CallingConventions.Any, types, null);
792                 }
793
794                 public MethodInfo GetMethod (string name, Type[] types, ParameterModifier[] modifiers)
795                 {
796                         return GetMethod (name, DefaultBindingFlags, null, CallingConventions.Any, types, modifiers);
797                 }
798
799                 public MethodInfo GetMethod (string name, BindingFlags bindingAttr, Binder binder,
800                                              Type[] types, ParameterModifier[] modifiers)
801                 {
802                         return GetMethod (name, bindingAttr, binder, CallingConventions.Any, types, modifiers);
803                 }
804
805                 public MethodInfo GetMethod (string name, BindingFlags bindingAttr, Binder binder,
806                                              CallingConventions callConvention, Type[] types, ParameterModifier[] modifiers)
807                 {
808                         if (name == null)
809                                 throw new ArgumentNullException ("name");
810                         if (types == null)
811                                 throw new ArgumentNullException ("types");
812
813                         for (int i = 0; i < types.Length; i++) 
814                                 if (types[i] == null)
815                                         throw new ArgumentNullException ("types");
816
817                         return GetMethodImpl (name, bindingAttr, binder, callConvention, types, modifiers);
818                 }
819
820                 protected abstract MethodInfo GetMethodImpl (string name, BindingFlags bindingAttr, Binder binder,
821                                                              CallingConventions callConvention, Type[] types,
822                                                              ParameterModifier[] modifiers);
823
824                 internal MethodInfo GetMethodImplInternal (string name, BindingFlags bindingAttr, Binder binder,
825                                                                                                                         CallingConventions callConvention, Type[] types,
826                                                                                                                         ParameterModifier[] modifiers)
827                 {
828                         return GetMethodImpl (name, bindingAttr, binder, callConvention, types, modifiers);
829                 }
830
831                 internal virtual MethodInfo GetMethod (MethodInfo fromNoninstanciated)
832                 {
833                         throw new System.InvalidOperationException ("can only be called in generic type");
834                 }
835
836                 internal virtual ConstructorInfo GetConstructor (ConstructorInfo fromNoninstanciated)
837                 {
838                         throw new System.InvalidOperationException ("can only be called in generic type");
839                 }
840
841                 internal virtual FieldInfo GetField (FieldInfo fromNoninstanciated)
842                 {
843                         throw new System.InvalidOperationException ("can only be called in generic type");
844                 }
845
846                 
847                 public MethodInfo[] GetMethods ()
848                 {
849                         return GetMethods (DefaultBindingFlags);
850                 }
851
852                 public abstract MethodInfo[] GetMethods (BindingFlags bindingAttr);
853
854                 public Type GetNestedType (string name)
855                 {
856                         return GetNestedType (name, DefaultBindingFlags);
857                 }
858
859                 public abstract Type GetNestedType (string name, BindingFlags bindingAttr);
860
861                 public Type[] GetNestedTypes ()
862                 {
863                         return GetNestedTypes (DefaultBindingFlags);
864                 }
865
866                 public abstract Type[] GetNestedTypes (BindingFlags bindingAttr);
867
868
869                 public PropertyInfo[] GetProperties ()
870                 {
871                         return GetProperties (DefaultBindingFlags);
872                 }
873
874                 public abstract PropertyInfo[] GetProperties (BindingFlags bindingAttr);
875
876
877                 public PropertyInfo GetProperty (string name)
878                 {
879                         if (name == null)
880                                 throw new ArgumentNullException ("name");
881
882                         return GetPropertyImpl (name, DefaultBindingFlags, null, null, null, null);
883                 }
884
885                 public PropertyInfo GetProperty (string name, BindingFlags bindingAttr)
886                 {
887                         if (name == null)
888                                 throw new ArgumentNullException ("name");
889                         return GetPropertyImpl (name, bindingAttr, null, null, null, null);
890                 }
891
892                 public PropertyInfo GetProperty (string name, Type returnType)
893                 {
894                         if (name == null)
895                                 throw new ArgumentNullException ("name");
896                         return GetPropertyImpl (name, DefaultBindingFlags, null, returnType, null, null);
897                 }
898
899                 public PropertyInfo GetProperty (string name, Type[] types)
900                 {
901                         return GetProperty (name, DefaultBindingFlags, null, null, types, null);
902                 }
903
904                 public PropertyInfo GetProperty (string name, Type returnType, Type[] types)
905                 {
906                         return GetProperty (name, DefaultBindingFlags, null, returnType, types, null);
907                 }
908
909                 public PropertyInfo GetProperty( string name, Type returnType, Type[] types, ParameterModifier[] modifiers)
910                 {
911                         return GetProperty (name, DefaultBindingFlags, null, returnType, types, modifiers);
912                 }
913
914                 public PropertyInfo GetProperty (string name, BindingFlags bindingAttr, Binder binder, Type returnType,
915                                                  Type[] types, ParameterModifier[] modifiers)
916                 {
917                         if (name == null)
918                                 throw new ArgumentNullException ("name");
919                         if (types == null)
920                                 throw new ArgumentNullException ("types");
921
922                         foreach (Type t in types) {
923                                 if (t == null)
924                                         throw new ArgumentNullException ("types");
925                         }
926
927                         return GetPropertyImpl (name, bindingAttr, binder, returnType, types, modifiers);
928                 }
929
930                 protected abstract PropertyInfo GetPropertyImpl (string name, BindingFlags bindingAttr, Binder binder,
931                                                                  Type returnType, Type[] types, ParameterModifier[] modifiers);
932
933                 internal PropertyInfo GetPropertyImplInternal (string name, BindingFlags bindingAttr, Binder binder,
934                                                                                                            Type returnType, Type[] types, ParameterModifier[] modifiers)
935                 {
936                         return GetPropertyImpl (name, bindingAttr, binder, returnType, types, modifiers);
937                 }
938
939                 protected abstract ConstructorInfo GetConstructorImpl (BindingFlags bindingAttr,
940                                                                        Binder binder,
941                                                                        CallingConventions callConvention,
942                                                                        Type[] types,
943                                                                        ParameterModifier[] modifiers);
944
945                 protected abstract TypeAttributes GetAttributeFlagsImpl ();
946                 protected abstract bool HasElementTypeImpl ();
947                 protected abstract bool IsArrayImpl ();
948                 protected abstract bool IsByRefImpl ();
949                 protected abstract bool IsCOMObjectImpl ();
950                 protected abstract bool IsPointerImpl ();
951                 protected abstract bool IsPrimitiveImpl ();
952                 
953                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
954                 internal static extern bool IsArrayImpl (Type type);
955
956                 protected virtual bool IsValueTypeImpl ()
957                 {
958                         if (this == typeof (ValueType) || this == typeof (Enum))
959                                 return false;
960
961                         return IsSubclassOf (typeof (ValueType));
962                 }
963                 
964                 protected virtual bool IsContextfulImpl ()
965                 {
966                         return typeof (ContextBoundObject).IsAssignableFrom (this);
967                 }
968
969                 protected virtual bool IsMarshalByRefImpl ()
970                 {
971                         return typeof (MarshalByRefObject).IsAssignableFrom (this);
972                 }
973
974                 [ComVisible (true)]
975                 public ConstructorInfo GetConstructor (Type[] types)
976                 {
977                         return GetConstructor (BindingFlags.Public|BindingFlags.Instance, null, CallingConventions.Any, types, null);
978                 }
979
980                 [ComVisible (true)]
981                 public ConstructorInfo GetConstructor (BindingFlags bindingAttr, Binder binder,
982                                                        Type[] types, ParameterModifier[] modifiers)
983                 {
984                         return GetConstructor (bindingAttr, binder, CallingConventions.Any, types, modifiers);
985                 }
986
987                 [ComVisible (true)]
988                 public ConstructorInfo GetConstructor (BindingFlags bindingAttr, Binder binder,
989                                                        CallingConventions callConvention,
990                                                        Type[] types, ParameterModifier[] modifiers)
991                 {
992                         if (types == null)
993                                 throw new ArgumentNullException ("types");
994
995                         foreach (Type t in types) {
996                                 if (t == null)
997                                         throw new ArgumentNullException ("types");
998                         }
999
1000                         return GetConstructorImpl (bindingAttr, binder, callConvention, types, modifiers);
1001                 }
1002
1003                 [ComVisible (true)]
1004                 public ConstructorInfo[] GetConstructors ()
1005                 {
1006                         return GetConstructors (BindingFlags.Public | BindingFlags.Instance);
1007                 }
1008
1009                 [ComVisible (true)]
1010                 public abstract ConstructorInfo[] GetConstructors (BindingFlags bindingAttr);
1011
1012                 public virtual MemberInfo[] GetDefaultMembers ()
1013                 {
1014                         object [] att = GetCustomAttributes (typeof (DefaultMemberAttribute), true);
1015                         if (att.Length == 0)
1016                                 return new MemberInfo [0];
1017
1018                         MemberInfo [] member = GetMember (((DefaultMemberAttribute) att [0]).MemberName);
1019                         return (member != null) ? member : new MemberInfo [0];
1020                 }
1021
1022                 public virtual MemberInfo[] FindMembers (MemberTypes memberType, BindingFlags bindingAttr,
1023                                                          MemberFilter filter, object filterCriteria)
1024                 {
1025                         MemberInfo[] result;
1026                         ArrayList l = new ArrayList ();
1027
1028                         // Console.WriteLine ("FindMembers for {0} (Type: {1}): {2}",
1029                         // this.FullName, this.GetType().FullName, this.obj_address());
1030                         if ((memberType & MemberTypes.Method) != 0) {
1031                                 MethodInfo[] c = GetMethods (bindingAttr);
1032                                 if (filter != null) {
1033                                         foreach (MemberInfo m in c) {
1034                                                 if (filter (m, filterCriteria))
1035                                                         l.Add (m);
1036                                         }
1037                                 } else {
1038                                         l.AddRange (c);
1039                                 }
1040                         }
1041                         if ((memberType & MemberTypes.Constructor) != 0) {
1042                                 ConstructorInfo[] c = GetConstructors (bindingAttr);
1043                                 if (filter != null) {
1044                                         foreach (MemberInfo m in c) {
1045                                                 if (filter (m, filterCriteria))
1046                                                         l.Add (m);
1047                                         }
1048                                 } else {
1049                                         l.AddRange (c);
1050                                 }
1051                         }
1052                         if ((memberType & MemberTypes.Property) != 0) {
1053                                 PropertyInfo[] c;
1054                                 int count = l.Count;
1055                                 Type ptype;
1056                                 if (filter != null) {
1057                                         ptype = this;
1058                                         while ((l.Count == count) && (ptype != null)) {
1059                                                 c = ptype.GetProperties (bindingAttr);
1060                                                 foreach (MemberInfo m in c) {
1061                                                         if (filter (m, filterCriteria))
1062                                                                 l.Add (m);
1063                                                 }
1064                                                 ptype = ptype.BaseType;
1065                                         }
1066                                 } else {
1067                                         c = GetProperties (bindingAttr);
1068                                         l.AddRange (c);
1069                                 }
1070                         }
1071                         if ((memberType & MemberTypes.Event) != 0) {
1072                                 EventInfo[] c = GetEvents (bindingAttr);
1073                                 if (filter != null) {
1074                                         foreach (MemberInfo m in c) {
1075                                                 if (filter (m, filterCriteria))
1076                                                         l.Add (m);
1077                                         }
1078                                 } else {
1079                                         l.AddRange (c);
1080                                 }
1081                         }
1082                         if ((memberType & MemberTypes.Field) != 0) {
1083                                 FieldInfo[] c = GetFields (bindingAttr);
1084                                 if (filter != null) {
1085                                         foreach (MemberInfo m in c) {
1086                                                 if (filter (m, filterCriteria))
1087                                                         l.Add (m);
1088                                         }
1089                                 } else {
1090                                         l.AddRange (c);
1091                                 }
1092                         }
1093                         if ((memberType & MemberTypes.NestedType) != 0) {
1094                                 Type[] c = GetNestedTypes (bindingAttr);
1095                                 if (filter != null) {
1096                                         foreach (MemberInfo m in c) {
1097                                                 if (filter (m, filterCriteria)) {
1098                                                         l.Add (m);
1099                                                 }
1100                                         }
1101                                 } else {
1102                                         l.AddRange (c);
1103                                 }
1104                         }
1105
1106                         switch (memberType) {
1107                         case MemberTypes.Constructor :
1108                                 result = new ConstructorInfo [l.Count];
1109                                 break;
1110                         case MemberTypes.Event :
1111                                 result = new EventInfo [l.Count];
1112                                 break;
1113                         case MemberTypes.Field :
1114                                 result = new FieldInfo [l.Count];
1115                                 break;
1116                         case MemberTypes.Method :
1117                                 result = new MethodInfo [l.Count];
1118                                 break;
1119                         case MemberTypes.NestedType :
1120                         case MemberTypes.TypeInfo :
1121                                 result = new Type [l.Count];
1122                                 break;
1123                         case MemberTypes.Property :
1124                                 result = new PropertyInfo [l.Count];
1125                                 break;
1126                         default :
1127                                 result = new MemberInfo [l.Count];
1128                                 break;
1129                         }
1130                         l.CopyTo (result);
1131                         return result;
1132                 }
1133
1134                 [DebuggerHidden]
1135                 [DebuggerStepThrough] 
1136                 public object InvokeMember (string name, BindingFlags invokeAttr, Binder binder, object target, object[] args)
1137                 {
1138                         return InvokeMember (name, invokeAttr, binder, target, args, null, null, null);
1139                 }
1140
1141                 [DebuggerHidden]
1142                 [DebuggerStepThrough] 
1143                 public object InvokeMember (string name, BindingFlags invokeAttr, Binder binder,
1144                                             object target, object[] args, CultureInfo culture)
1145                 {
1146                         return InvokeMember (name, invokeAttr, binder, target, args, null, culture, null);
1147                 }
1148
1149                 public abstract object InvokeMember (string name, BindingFlags invokeAttr,
1150                                                      Binder binder, object target, object[] args,
1151                                                      ParameterModifier[] modifiers,
1152                                                      CultureInfo culture, string[] namedParameters);
1153
1154                 public override string ToString()
1155                 {
1156                         return FullName;
1157                 }
1158
1159                 internal virtual bool IsCompilerContext {
1160                         get {
1161                                 AssemblyBuilder builder = Assembly as AssemblyBuilder;
1162                                 return builder != null && builder.IsCompilerContext;
1163                         }
1164                 }
1165
1166                 internal bool IsSystemType {
1167                         get {
1168                                 return _impl.Value != IntPtr.Zero;
1169                         }
1170                 }
1171
1172                 public virtual Type[] GetGenericArguments ()
1173                 {
1174                         throw new NotSupportedException ();
1175                 }
1176
1177                 public virtual bool ContainsGenericParameters {
1178                         get { return false; }
1179                 }
1180
1181                 public virtual extern bool IsGenericTypeDefinition {
1182                         [MethodImplAttribute(MethodImplOptions.InternalCall)]
1183                         get;
1184                 }
1185
1186                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
1187                 internal extern Type GetGenericTypeDefinition_impl ();
1188
1189                 public virtual Type GetGenericTypeDefinition ()
1190                 {
1191                         throw new NotSupportedException ("Derived classes must provide an implementation.");
1192                 }
1193
1194                 public virtual extern bool IsGenericType {
1195                         [MethodImplAttribute(MethodImplOptions.InternalCall)]
1196                         get;
1197                 }
1198
1199                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
1200                 static extern Type MakeGenericType (Type gt, Type [] types);
1201
1202                 static AssemblyBuilder PeelAssemblyBuilder (Type type)
1203                 {
1204                         if (type.Assembly is AssemblyBuilder)
1205                                 return (AssemblyBuilder)type.Assembly;
1206
1207                         if (type.HasElementType)
1208                                 return PeelAssemblyBuilder (type.GetElementType ());
1209
1210                         if (!type.IsGenericType || type.IsGenericParameter || type.IsGenericTypeDefinition)
1211                                 return null;
1212
1213                         foreach (Type arg in type.GetGenericArguments ()) {
1214                                 AssemblyBuilder ab = PeelAssemblyBuilder (arg);
1215                                 if (ab != null)
1216                                         return ab;
1217                         }
1218                         return null;
1219                 }
1220
1221                 public virtual Type MakeGenericType (params Type[] typeArguments)
1222                 {
1223                         if (IsUserType)
1224                                 throw new NotSupportedException ();
1225                         if (!IsGenericTypeDefinition)
1226                                 throw new InvalidOperationException ("not a generic type definition");
1227                         if (typeArguments == null)
1228                                 throw new ArgumentNullException ("typeArguments");
1229                         if (GetGenericArguments().Length != typeArguments.Length)
1230                                 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");
1231
1232                         bool hasUserType = false;
1233                         AssemblyBuilder compilerContext = null;
1234
1235                         Type[] systemTypes = new Type[typeArguments.Length];
1236                         for (int i = 0; i < typeArguments.Length; ++i) {
1237                                 Type t = typeArguments [i];
1238                                 if (t == null)
1239                                         throw new ArgumentNullException ("typeArguments");
1240
1241                                 if (!(t is MonoType))
1242                                         hasUserType = true;
1243                                 if (t.IsCompilerContext)
1244                                         compilerContext = PeelAssemblyBuilder (t);
1245                                 systemTypes [i] = t;
1246                         }
1247
1248                         if (hasUserType) {
1249                                 if (compilerContext != null)
1250                                         return compilerContext.MakeGenericType (this, typeArguments);
1251                                 return new MonoGenericClass (this, typeArguments);
1252                         }
1253
1254                         Type res = MakeGenericType (this, systemTypes);
1255                         if (res == null)
1256                                 throw new TypeLoadException ();
1257                         return res;
1258                 }
1259
1260                 public virtual bool IsGenericParameter {
1261                         get {
1262                                 return false;
1263                         }
1264                 }
1265
1266                 public bool IsNested {
1267                         get {
1268                                 return DeclaringType != null;
1269                         }
1270                 }
1271
1272                 public bool IsVisible {
1273                         get {
1274                                 if (IsNestedPublic)
1275                                         return DeclaringType.IsVisible;
1276
1277                                 return IsPublic;
1278                         }
1279                 }
1280
1281                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
1282                 extern int GetGenericParameterPosition ();
1283                 
1284                 public virtual int GenericParameterPosition {
1285                         get {
1286                                 int res = GetGenericParameterPosition ();
1287                                 if (res < 0)
1288                                         throw new InvalidOperationException ();
1289                                 return res;
1290                         }
1291                 }
1292
1293                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
1294                 extern GenericParameterAttributes GetGenericParameterAttributes ();
1295
1296                 public virtual GenericParameterAttributes GenericParameterAttributes {
1297                         get {
1298                                 if (!IsSystemType)
1299                                         throw new NotSupportedException ("Derived classes must provide an implementation.");
1300
1301                                 if (!IsGenericParameter)
1302                                         throw new InvalidOperationException ();
1303
1304                                 return GetGenericParameterAttributes ();
1305                         }
1306                 }
1307
1308                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
1309                 extern Type[] GetGenericParameterConstraints_impl ();
1310
1311                 public virtual Type[] GetGenericParameterConstraints ()
1312                 {
1313                         if (!IsSystemType)
1314                                 throw new InvalidOperationException ();
1315
1316                         if (!IsGenericParameter)
1317                                 throw new InvalidOperationException ();
1318
1319                         return GetGenericParameterConstraints_impl ();
1320                 }
1321
1322                 public virtual MethodBase DeclaringMethod {
1323                         get {
1324                                 return null;
1325                         }
1326                 }
1327
1328                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
1329                 extern Type make_array_type (int rank);
1330
1331                 public virtual Type MakeArrayType ()
1332                 {
1333                         if (!IsSystemType)
1334                                 throw new NotSupportedException ("Derived classes must provide an implementation.");
1335                         return make_array_type (0);
1336                 }
1337
1338                 public virtual Type MakeArrayType (int rank)
1339                 {
1340                         if (!IsSystemType)
1341                                 throw new NotSupportedException ("Derived classes must provide an implementation.");
1342                         if (rank < 1 || rank > 255)
1343                                 throw new IndexOutOfRangeException ();
1344                         return make_array_type (rank);
1345                 }
1346
1347                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
1348                 extern Type make_byref_type ();
1349
1350                 public virtual Type MakeByRefType ()
1351                 {
1352                         if (!IsSystemType)
1353                                 throw new NotSupportedException ("Derived classes must provide an implementation.");
1354                         if (IsByRef)
1355                                 throw new TypeLoadException ("Can not call MakeByRefType on a ByRef type");
1356                         return make_byref_type ();
1357                 }
1358
1359                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
1360                 static extern Type MakePointerType (Type type);
1361
1362                 public virtual Type MakePointerType ()
1363                 {
1364                         if (!IsSystemType)
1365                                 throw new NotSupportedException ("Derived classes must provide an implementation.");
1366                         return MakePointerType (this);
1367                 }
1368
1369                 public static Type ReflectionOnlyGetType (string typeName, 
1370                                                           bool throwIfNotFound, 
1371                                                           bool ignoreCase)
1372                 {
1373                         if (typeName == null)
1374                                 throw new ArgumentNullException ("typeName");
1375                         int idx = typeName.IndexOf (',');
1376                         if (idx < 0 || idx == 0 || idx == typeName.Length - 1)
1377                                 throw new ArgumentException ("Assembly qualifed type name is required", "typeName");
1378                         string an = typeName.Substring (idx + 1);
1379                         Assembly a;
1380                         try {
1381                                 a = Assembly.ReflectionOnlyLoad (an);
1382                         } catch {
1383                                 if (throwIfNotFound)
1384                                         throw;
1385                                 return null;
1386                         }
1387                         return a.GetType (typeName.Substring (0, idx), throwIfNotFound, ignoreCase);
1388                 }
1389
1390                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
1391                 extern void GetPacking (out int packing, out int size);         
1392
1393                 public virtual StructLayoutAttribute StructLayoutAttribute {
1394                         get {
1395                                 LayoutKind kind;
1396
1397                                 if (IsLayoutSequential)
1398                                         kind = LayoutKind.Sequential;
1399                                 else if (IsExplicitLayout)
1400                                         kind = LayoutKind.Explicit;
1401                                 else
1402                                         kind = LayoutKind.Auto;
1403
1404                                 StructLayoutAttribute attr = new StructLayoutAttribute (kind);
1405
1406                                 if (IsUnicodeClass)
1407                                         attr.CharSet = CharSet.Unicode;
1408                                 else if (IsAnsiClass)
1409                                         attr.CharSet = CharSet.Ansi;
1410                                 else
1411                                         attr.CharSet = CharSet.Auto;
1412
1413                                 if (kind != LayoutKind.Auto)
1414                                         GetPacking (out attr.Pack, out attr.Size);
1415
1416                                 return attr;
1417                         }
1418                 }
1419
1420                 internal object[] GetPseudoCustomAttributes ()
1421                 {
1422                         int count = 0;
1423
1424                         /* IsSerializable returns true for delegates/enums as well */
1425                         if ((Attributes & TypeAttributes.Serializable) != 0)
1426                                 count ++;
1427                         if ((Attributes & TypeAttributes.Import) != 0)
1428                                 count ++;
1429
1430                         if (count == 0)
1431                                 return null;
1432                         object[] attrs = new object [count];
1433                         count = 0;
1434
1435                         if ((Attributes & TypeAttributes.Serializable) != 0)
1436                                 attrs [count ++] = new SerializableAttribute ();
1437                         if ((Attributes & TypeAttributes.Import) != 0)
1438                                 attrs [count ++] = new ComImportAttribute ();
1439
1440                         return attrs;
1441                 }                       
1442
1443
1444 #if NET_4_0 || BOOTSTRAP_NET_4_0
1445                 public virtual bool IsEquivalentTo (Type other)
1446                 {
1447                         return this == other;
1448                 }
1449 #endif
1450
1451                 /* 
1452                  * Return whenever this object is an instance of a user defined subclass
1453                  * of System.Type or an instance of TypeDelegator.
1454                  */
1455                 internal bool IsUserType {
1456                         get {
1457                                 /* 
1458                                  * subclasses cannot modify _impl so if it is zero, it means the
1459                                  * type is not created by the runtime.
1460                                  */
1461                                 return _impl.Value == IntPtr.Zero &&
1462                                         (GetType ().Assembly != typeof (Type).Assembly || GetType () == typeof (TypeDelegator));
1463                         }
1464                 }
1465
1466                 void _Type.GetIDsOfNames ([In] ref Guid riid, IntPtr rgszNames, uint cNames, uint lcid, IntPtr rgDispId)
1467                 {
1468                         throw new NotImplementedException ();
1469                 }
1470
1471                 void _Type.GetTypeInfo (uint iTInfo, uint lcid, IntPtr ppTInfo)
1472                 {
1473                         throw new NotImplementedException ();
1474                 }
1475
1476                 void _Type.GetTypeInfoCount (out uint pcTInfo)
1477                 {
1478                         throw new NotImplementedException ();
1479                 }
1480
1481                 void _Type.Invoke (uint dispIdMember, [In] ref Guid riid, uint lcid, short wFlags, IntPtr pDispParams, IntPtr pVarResult, IntPtr pExcepInfo, IntPtr puArgErr)
1482                 {
1483                         throw new NotImplementedException ();
1484                 }
1485         }
1486 }