2003-09-04 Martin Baulig <martin@ximian.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 // TODO: Mucho left to implement.
10 //
11
12 using System.Reflection;
13 using System.Collections;
14 using System.Runtime.CompilerServices;
15 using System.Globalization;
16
17 namespace System {
18
19         //
20         // FIXME: Implement the various IReflect dependencies
21         //
22
23         [MonoTODO]
24         [Serializable]
25         public abstract class Type : MemberInfo, IReflect {
26                 
27                 internal RuntimeTypeHandle _impl;
28
29                 public static readonly char Delimiter = '.';
30                 public static readonly Type[] EmptyTypes = {};
31                 public static readonly MemberFilter FilterAttribute = new MemberFilter (FilterAttribute_impl);
32                 public static readonly MemberFilter FilterName = new MemberFilter (FilterName_impl);
33                 public static readonly MemberFilter FilterNameIgnoreCase = new MemberFilter (FilterNameIgnoreCase_impl);
34                 public static readonly object Missing;
35
36                 private const BindingFlags DefaultBindingFlags =
37                 BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance;
38
39                 /* implementation of the delegates for MemberFilter */
40                 static bool FilterName_impl (MemberInfo m, object filterCriteria)
41                 {
42                         string name = (string) filterCriteria;
43                         return name.Equals (m.Name);
44                 }
45                 
46                 static bool FilterNameIgnoreCase_impl (MemberInfo m, object filterCriteria)
47                 {
48                         string name = (string) filterCriteria;
49                         return String.Compare (name, m.Name, true) == 0;
50                 }
51                 
52                 [MonoTODO]
53                 static bool FilterAttribute_impl (MemberInfo m, object filterCriteria)
54                 {
55                         throw new NotImplementedException ("FilterAttribute_impl");
56                 }
57
58                 protected Type ()
59                 {
60                 }
61
62                 /// <summary>
63                 ///   The assembly where the type is defined.
64                 /// </summary>
65                 public abstract Assembly Assembly {
66                         get;
67                 }
68
69                 /// <summary>
70                 ///   Gets the fully qualified name for the type including the
71                 ///   assembly name where the type is defined.
72                 /// </summary>
73                 public abstract string AssemblyQualifiedName {
74                         get;
75                 }
76
77                 /// <summary>
78                 ///   Returns the Attributes associated with the type.
79                 /// </summary>
80                 public TypeAttributes Attributes {
81                         get {
82                                 return GetAttributeFlagsImpl ();
83                         }
84                 }
85                 
86                 /// <summary>
87                 ///   Returns the basetype for this type
88                 /// </summary>
89                 public abstract Type BaseType {
90                         get;
91                 }
92                         
93                 /// <summary>
94                 ///   Returns the class that declares the member.
95                 /// </summary>
96                 public override Type DeclaringType {
97                         get {
98                                 return null;
99                         }
100                 }
101
102                 /// <summary>
103                 ///
104                 /// </summary>
105                 public static Binder DefaultBinder {
106                         get {
107                                 return Binder.DefaultBinder;
108                         }
109                 }
110                 
111                 /// <summary>
112                 ///    The full name of the type including its namespace
113                 /// </summary>
114                 public abstract string FullName {
115                         get;
116                 }
117
118                 public abstract Guid GUID {
119                         get;
120                 }
121
122                 public bool HasElementType {
123                         get {
124                                 return HasElementTypeImpl ();
125                         }
126                 }
127
128                 public bool IsAbstract {
129                         get {
130                                 return (Attributes & TypeAttributes.Abstract) != 0;
131                         }
132                 }
133
134                 public bool IsAnsiClass {
135                         get {
136                                 return (Attributes & TypeAttributes.StringFormatMask)
137                                 == TypeAttributes.AnsiClass;
138                         }
139                 }
140
141                 public bool IsArray {
142                         get {
143                                 return IsArrayImpl ();
144                         }
145                 }
146
147                 public bool IsAutoClass {
148                         get {
149                                 return (Attributes & TypeAttributes.StringFormatMask) == TypeAttributes.AutoClass;
150                         }
151                 }
152
153                 public bool IsAutoLayout {
154                         get {
155                                 return (Attributes & TypeAttributes.LayoutMask) == TypeAttributes.AutoLayout;
156                         }
157                 }
158
159                 public bool IsByRef {
160                         get {
161                                 return IsByRefImpl ();
162                         }
163                 }
164
165                 public bool IsClass {
166                         get {
167                                 //
168                                 // This code used to probe for "this == typeof (System.Enum)", but in
169                                 // The .NET Framework 1.0, the above test return false
170                                 //
171                                 if (this == typeof (System.ValueType))
172                                         return true;
173                                 if (IsInterface)
174                                         return false;
175                                 return !type_is_subtype_of (this, typeof (System.ValueType), false);
176                         }
177                 }
178
179                 public bool IsCOMObject {
180                         get {
181                                 return IsCOMObjectImpl ();
182                         }
183                 }
184
185                 public bool IsContextful {
186                         get {
187                                 return IsContextfulImpl ();
188                         }
189                 }
190
191                 public bool IsEnum {
192                         get {
193                                 return type_is_subtype_of (this, typeof (System.Enum), false) &&
194                                         this != typeof (System.Enum);
195                         }
196                 }
197
198                 public bool IsExplicitLayout {
199                         get {
200                                 return (Attributes & TypeAttributes.LayoutMask) == TypeAttributes.ExplicitLayout;
201                         }
202                 }
203
204                 public bool IsImport {
205                         get {
206                                 return (Attributes & TypeAttributes.Import) != 0;
207                         }
208                 }
209
210                 public bool IsInterface {
211                         get {
212                                 return (Attributes & TypeAttributes.ClassSemanticsMask) == TypeAttributes.Interface;
213                         }
214                 }
215
216                 public bool IsLayoutSequential {
217                         get {
218                                 return (Attributes & TypeAttributes.LayoutMask) == TypeAttributes.SequentialLayout;
219                         }
220                 }
221
222                 public bool IsMarshalByRef {
223                         get {
224                                 return IsMarshalByRefImpl ();
225                         }
226                 }
227
228                 public bool IsNestedAssembly {
229                         get {
230                                 return (Attributes & TypeAttributes.VisibilityMask) == TypeAttributes.NestedAssembly;
231                         }
232                 }
233
234                 public bool IsNestedFamANDAssem {
235                         get {
236                                 return (Attributes & TypeAttributes.VisibilityMask) == TypeAttributes.NestedFamANDAssem;
237                         }
238                 }
239
240                 public bool IsNestedFamily {
241                         get {
242                                 return (Attributes & TypeAttributes.VisibilityMask) == TypeAttributes.NestedFamily;
243                         }
244                 }
245
246                 public bool IsNestedFamORAssem {
247                         get {
248                                 return (Attributes & TypeAttributes.VisibilityMask) == TypeAttributes.NestedFamORAssem;
249                         }
250                 }
251
252                 public bool IsNestedPrivate {
253                         get {
254                                 return (Attributes & TypeAttributes.VisibilityMask) == TypeAttributes.NestedPrivate;
255                         }
256                 }
257
258                 public bool IsNestedPublic {
259                         get {
260                                 return (Attributes & TypeAttributes.VisibilityMask) == TypeAttributes.NestedPublic;
261                         }
262                 }
263
264                 public bool IsNotPublic {
265                         get {
266                                 return !IsPublic;
267                         }
268                 }
269
270                 public bool IsPointer {
271                         get {
272                                 return IsPointerImpl ();
273                         }
274                 }
275
276                 public bool IsPrimitive {
277                         get {
278                                 return IsPrimitiveImpl ();
279                         }
280                 }
281
282                 public bool IsPublic {
283                         get {
284                                 return (Attributes & TypeAttributes.VisibilityMask) == TypeAttributes.Public;
285                         }
286                 }
287
288                 public bool IsSealed {
289                         get {
290                                 return (Attributes & TypeAttributes.Sealed) != 0;
291                         }
292                 }
293
294                 public bool IsSerializable {
295                         get {
296                                 // Enums and delegates are always serializable
297                                 return (Attributes & TypeAttributes.Serializable) != 0 || IsEnum || 
298                                         type_is_subtype_of (this, typeof (System.Delegate), false);
299                         }
300                 }
301
302                 public bool IsSpecialName {
303                         get {
304                                 return (Attributes & TypeAttributes.SpecialName) != 0;
305                         }
306                 }
307
308                 public bool IsUnicodeClass {
309                         get {
310                                 return (Attributes & TypeAttributes.StringFormatMask) == TypeAttributes.UnicodeClass;
311                         }
312                 }
313
314                 public bool IsValueType {
315                         get {
316                                 return IsValueTypeImpl ();
317                         }
318                 }
319
320                 public override MemberTypes MemberType {
321                         get {return MemberTypes.TypeInfo;}
322                 }
323
324                 public abstract Module Module {get;}
325         
326                 public abstract string Namespace {get;}
327
328                 public override Type ReflectedType {
329                         get {
330                                 return null;
331                         }
332                 }
333
334                 public abstract RuntimeTypeHandle TypeHandle {get;}
335
336                 public ConstructorInfo TypeInitializer {
337                         get {
338                                 return GetConstructorImpl (
339                                         BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static,
340                                         null,
341                                         CallingConventions.Any,
342                                         EmptyTypes,
343                                         null);
344                         }
345                 }
346
347                 public abstract Type UnderlyingSystemType {get;}
348
349                 public override bool Equals (object o)
350                 {
351                         if (o == null)
352                                 return false;
353                         
354                         // TODO: return UnderlyingSystemType == o.UnderlyingSystemType;
355                         Type cmp = o as Type;
356                         if (cmp == null)
357                                 return false;
358                         return Equals (cmp);
359                 }
360                 
361                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
362                 public extern bool Equals (Type type);
363                 
364                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
365                 private static extern Type internal_from_handle (IntPtr handle);
366                 
367                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
368                 private static extern Type internal_from_name (string name, bool throwOnError, bool ignoreCase);
369
370                 public static Type GetType(string typeName)
371                 {
372                         if (typeName == null)
373                                 throw new ArgumentNullException ("typeName");
374
375                         return internal_from_name (typeName, false, false);
376                 }
377
378                 public static Type GetType(string typeName, bool throwOnError)
379                 {
380                         if (typeName == null)
381                                 throw new ArgumentNullException ("typeName");
382
383                         Type type = internal_from_name (typeName, throwOnError, false);
384                         if (throwOnError && type == null)
385                                 throw new TypeLoadException ("Error loading '" + typeName + "'");
386
387                         return type;
388                 }
389
390                 public static Type GetType(string typeName, bool throwOnError, bool ignoreCase)
391                 {
392                         if (typeName == null)
393                                 throw new ArgumentNullException ("typeName");
394
395                         Type t = internal_from_name (typeName, throwOnError, ignoreCase);
396                         if (throwOnError && t == null)
397                                 throw new TypeLoadException ("Error loading '" + typeName + "'");
398
399                         return t;
400                 }
401
402                 public static Type[] GetTypeArray (object[] args) {
403                         if (args == null)
404                                 throw new ArgumentNullException ("args");
405
406                         Type[] ret;
407                         ret = new Type [args.Length];
408                         for (int i = 0; i < args.Length; ++i)
409                                 ret [i] = args[i].GetType ();
410                         return ret;
411                 }
412
413                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
414                 public extern static TypeCode GetTypeCode (Type type);
415
416                 [MonoTODO]
417                 public static Type GetTypeFromCLSID (Guid clsid)
418                 {
419                         throw new NotImplementedException ();
420                 }
421
422                 [MonoTODO]
423                 public static Type GetTypeFromCLSID (Guid clsid, bool throwOnError)
424                 {
425                         throw new NotImplementedException ();
426                 }
427
428                 [MonoTODO]
429                 public static Type GetTypeFromCLSID (Guid clsid, string server)
430                 {
431                         throw new NotImplementedException ();
432                 }
433
434                 [MonoTODO]
435                 public static Type GetTypeFromCLSID (Guid clsid, string server, bool throwOnError)
436                 {
437                         throw new NotImplementedException ();
438                 }
439
440                 public static Type GetTypeFromHandle (RuntimeTypeHandle handle)
441                 { 
442                         return internal_from_handle (handle.Value);
443                 }
444
445                 [MonoTODO]
446                 public static Type GetTypeFromProgID (string progID)
447                 {
448                         throw new NotImplementedException ();
449                 }
450
451                 [MonoTODO]
452                 public static Type GetTypeFromProgID (string progID, bool throwOnError)
453                 {
454                         throw new NotImplementedException ();
455                 }
456
457                 [MonoTODO]
458                 public static Type GetTypeFromProgID (string progID, string server)
459                 {
460                         throw new NotImplementedException ();
461                 }
462
463                 [MonoTODO]
464                 public static Type GetTypeFromProgID (string progID, string server, bool throwOnError)
465                 {
466                         throw new NotImplementedException ();
467                 }
468
469                 public static RuntimeTypeHandle GetTypeHandle (object o)
470                 {
471                         return o.GetType().TypeHandle;
472                 }
473
474                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
475                 internal static extern bool type_is_subtype_of (Type a, Type b, bool check_interfaces);
476
477                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
478                 internal static extern bool type_is_assignable_from (Type a, Type b);
479                 
480                 public virtual bool IsSubclassOf (Type c)
481                 {
482                         if (c == null)
483                                 return false;
484
485                         return (this != c) && type_is_subtype_of (this, c, false);
486                 }
487
488                 public virtual Type[] FindInterfaces (TypeFilter filter, object filterCriteria)
489                 {
490                         if (filter == null)
491                                 throw new ArgumentNullException ("filter");
492
493                         ArrayList ifaces = new ArrayList ();
494                         foreach (Type iface in GetInterfaces ()) {
495                                 if (filter (iface, filterCriteria))
496                                         ifaces.Add (iface);
497                         }
498
499                         return (Type []) ifaces.ToArray (typeof (Type));
500                 }
501                 
502                 public Type GetInterface (string name) {
503                         return GetInterface (name, false);
504                 }
505
506                 public abstract Type GetInterface (string name, bool ignoreCase);
507
508                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
509                 internal static extern void GetInterfaceMapData (Type t, Type iface, out MethodInfo[] targets, out MethodInfo[] methods);
510                 
511                 public virtual InterfaceMapping GetInterfaceMap (Type interfaceType) {
512                         InterfaceMapping res;
513                         if (interfaceType == null)
514                                 throw new ArgumentNullException ("interfaceType");
515                         if (!interfaceType.IsInterface)
516                                 throw new ArgumentException ("type argument must be an interface", "interfaceType");
517                         res.TargetType = this;
518                         res.InterfaceType = interfaceType;
519                         GetInterfaceMapData (this, interfaceType, out res.TargetMethods, out res.InterfaceMethods);
520                         if (res.TargetMethods == null)
521                                 throw new ArgumentException ("interface not found", "interfaceType");
522
523                         return res;
524                 }
525
526                 public abstract Type[] GetInterfaces ();
527
528                 public virtual bool IsAssignableFrom (Type c)
529                 {
530                         if (c == null)
531                                 return false;
532
533                         if (Equals (c))
534                                 return true;
535
536                         return type_is_assignable_from (this, c);
537                 }
538
539                 public virtual bool IsInstanceOfType (object o) {
540                         if (o != null)
541                                 return IsAssignableFrom (o.GetType ());
542
543                         return false;
544                 }
545
546                 public virtual int GetArrayRank ()
547                 {
548                         throw new NotSupportedException ();     // according to MSDN
549                 }
550
551                 public abstract Type GetElementType ();
552
553                 public EventInfo GetEvent (string name)
554                 {
555                         return GetEvent (name, DefaultBindingFlags);
556                 }
557
558                 public abstract EventInfo GetEvent (string name, BindingFlags bindingAttr);
559
560                 public virtual EventInfo[] GetEvents ()
561                 {
562                         return GetEvents (DefaultBindingFlags);
563                 }
564
565                 public abstract EventInfo[] GetEvents (BindingFlags bindingAttr);
566
567                 public FieldInfo GetField( string name)
568                 {
569                         return GetField (name, DefaultBindingFlags);
570                 }
571
572                 public abstract FieldInfo GetField( string name, BindingFlags bindingAttr);
573
574                 public FieldInfo[] GetFields ()
575                 {
576                         return GetFields (DefaultBindingFlags);
577                 }
578
579                 public abstract FieldInfo[] GetFields (BindingFlags bindingAttr);
580                 
581                 public override int GetHashCode()
582                 {
583                         return (int)_impl.Value;
584                 }
585
586                 public MemberInfo[] GetMember( string name)
587                 {
588                         return GetMember (name, DefaultBindingFlags);
589                 }
590                 
591                 public virtual MemberInfo[] GetMember( string name, BindingFlags bindingAttr)
592                 {
593                         return GetMember (name, MemberTypes.All, bindingAttr);
594                 }
595
596                 public virtual MemberInfo[] GetMember (string name, MemberTypes type,
597                                                        BindingFlags bindingAttr)
598                 {
599                         return FindMembers (type, bindingAttr, FilterName, name);
600                 }
601
602                 public MemberInfo[] GetMembers()
603                 {
604                         return GetMembers (DefaultBindingFlags);
605                 }
606
607                 public abstract MemberInfo[] GetMembers (BindingFlags bindingAttr);
608
609                 public MethodInfo GetMethod (string name)
610                 {
611                         if (name == null)
612                                 throw new ArgumentNullException ("name");
613                         return GetMethodImpl (name, DefaultBindingFlags, null, CallingConventions.Any, null, null);
614                 }
615
616                 public MethodInfo GetMethod (string name, BindingFlags bindingAttr)
617                 {
618                         if (name == null)
619                                 throw new ArgumentNullException ("name");
620                         
621                         return GetMethodImpl (name, bindingAttr, null, CallingConventions.Any, null, null);
622                 }
623                 
624                 public MethodInfo GetMethod (string name, Type[] types)
625                 {
626                         return GetMethod (name, DefaultBindingFlags, null, CallingConventions.Any, types, null);
627                 }
628
629                 public MethodInfo GetMethod( string name, Type[] types, ParameterModifier[] modifiers)
630                 {
631                         return GetMethod (name, DefaultBindingFlags, null,
632                                           CallingConventions.Any, types, modifiers);
633                 }
634
635                 public MethodInfo GetMethod (string name, BindingFlags bindingAttr, Binder binder,
636                                              Type[] types, ParameterModifier[] modifiers)
637                 {
638                         
639                         return GetMethod (name, bindingAttr, binder,
640                                           CallingConventions.Any, types, modifiers);
641                 }
642
643                 public MethodInfo GetMethod (string name, BindingFlags bindingAttr,
644                                              Binder binder, CallingConventions callConvention,
645                                              Type[] types, ParameterModifier[] modifiers)
646                 {
647                         if (name == null)
648                                 throw new ArgumentNullException ("name");
649                         if (types == null)
650                                 throw new ArgumentNullException ("types");
651
652                         return GetMethodImpl (name, bindingAttr, binder, callConvention, types, modifiers);
653                 }
654
655                 protected abstract MethodInfo GetMethodImpl (string name, BindingFlags bindingAttr,
656                                                              Binder binder,
657                                                              CallingConventions callConvention,
658                                                              Type[] types, ParameterModifier[] modifiers);
659
660                 public MethodInfo[] GetMethods ()
661                 {
662                         return GetMethods (DefaultBindingFlags);
663                 }
664
665                 public abstract MethodInfo[] GetMethods (BindingFlags bindingAttr);
666
667                 public Type GetNestedType (string name)
668                 {
669                         return GetNestedType (name, DefaultBindingFlags);
670                 }
671
672                 public abstract Type GetNestedType (string name, BindingFlags bindingAttr);
673
674                 public Type[] GetNestedTypes ()
675                 {
676                         return GetNestedTypes (DefaultBindingFlags);
677                 }
678
679                 public abstract Type[] GetNestedTypes (BindingFlags bindingAttr);
680
681
682                 public PropertyInfo[] GetProperties ()
683                 {
684                         return GetProperties (DefaultBindingFlags);
685                 }
686
687                 public abstract PropertyInfo[] GetProperties (BindingFlags bindingAttr);
688
689
690                 public PropertyInfo GetProperty (string name)
691                 {
692                         if (name == null)
693                                 throw new ArgumentNullException ("name");
694
695                         return GetPropertyImpl (name, DefaultBindingFlags, null, null, new Type[0], null);
696                 }
697
698                 public PropertyInfo GetProperty (string name, BindingFlags bindingAttr)
699                 {
700                         if (name == null)
701                                 throw new ArgumentNullException ("name");
702                         return GetPropertyImpl (name, bindingAttr, null, null, new Type[0], null);
703                 }
704
705                 public PropertyInfo GetProperty (string name, Type returnType)
706                 {
707                         if (name == null)
708                                 throw new ArgumentNullException ("name");
709                         return GetPropertyImpl (name, DefaultBindingFlags, null, returnType, new Type[0], null);
710                 }
711
712                 public PropertyInfo GetProperty (string name, Type[] types)
713                 {
714                         return GetProperty (name, DefaultBindingFlags, null, null, types, null);
715                 }
716
717                 public PropertyInfo GetProperty (string name, Type returnType, Type[] types)
718                 {
719                         return GetProperty (name, DefaultBindingFlags, null, returnType, types, null);
720                 }
721
722                 public PropertyInfo GetProperty( string name, Type returnType, Type[] types,
723                                                  ParameterModifier[] modifiers)
724                 {
725                         return GetProperty (name, DefaultBindingFlags, null, returnType, types, modifiers);
726                 }
727
728                 public PropertyInfo GetProperty (string name, BindingFlags bindingAttr,
729                                                  Binder binder, Type returnType,
730                                                  Type[] types, ParameterModifier[] modifiers)
731                 {
732                         if (name == null)
733                                 throw new ArgumentNullException ("name");
734                         if (types == null)
735                                 throw new ArgumentNullException ("types");
736
737                         return GetPropertyImpl (name, bindingAttr, binder, returnType, types, modifiers);
738                 }
739
740                 protected abstract PropertyInfo GetPropertyImpl (string name,
741                                                                  BindingFlags bindingAttr,
742                                                                  Binder binder, Type returnType,
743                                                                  Type[] types,
744                                                                  ParameterModifier[] modifiers);
745
746                 protected abstract ConstructorInfo GetConstructorImpl (BindingFlags bindingAttr,
747                                                                        Binder binder,
748                                                                        CallingConventions callConvention,
749                                                                        Type[] types,
750                                                                        ParameterModifier[] modifiers);
751
752                 protected abstract TypeAttributes GetAttributeFlagsImpl ();
753                 protected abstract bool HasElementTypeImpl ();
754                 protected abstract bool IsArrayImpl ();
755                 protected abstract bool IsByRefImpl ();
756                 protected abstract bool IsCOMObjectImpl ();
757                 protected abstract bool IsPointerImpl ();
758                 protected abstract bool IsPrimitiveImpl ();
759                 
760                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
761                 internal static extern bool IsArrayImpl (Type type);
762
763                 protected virtual bool IsValueTypeImpl ()
764                 {
765                         if (this == typeof (Enum) || this == typeof (ValueType))
766                                 return false;
767
768                         return IsSubclassOf (typeof (ValueType));
769                 }
770                 
771                 protected virtual bool IsContextfulImpl ()
772                 {
773                         return typeof (ContextBoundObject).IsAssignableFrom (this);
774                 }
775
776                 protected virtual bool IsMarshalByRefImpl ()
777                 {
778                         return typeof (MarshalByRefObject).IsAssignableFrom (this);
779                 }
780
781                 public ConstructorInfo GetConstructor (Type[] types)
782                 {
783                         return GetConstructorImpl (
784                                 DefaultBindingFlags, null, CallingConventions.Any, types, null);
785                 }
786
787                 public ConstructorInfo GetConstructor (BindingFlags bindingAttr, Binder binder,
788                                                        Type[] types, ParameterModifier[] modifiers)
789                 {
790                         return GetConstructorImpl (
791                                 bindingAttr, binder, CallingConventions.Any, types, modifiers);
792                 }
793
794                 public ConstructorInfo GetConstructor (BindingFlags bindingAttr, Binder binder,
795                                                        CallingConventions callConvention,
796                                                        Type[] types, ParameterModifier[] modifiers)
797                 {
798                         if (types == null)
799                                 throw new ArgumentNullException ("types");
800
801                         return GetConstructorImpl (bindingAttr, binder, callConvention, types, modifiers);
802                 }
803
804                 public ConstructorInfo[] GetConstructors ()
805                 {
806                         return GetConstructors (BindingFlags.Public | BindingFlags.Instance);
807                 }
808                 
809                 public abstract ConstructorInfo[] GetConstructors (BindingFlags bindingAttr);
810
811                 public virtual MemberInfo[] GetDefaultMembers ()
812                 {
813                         object [] att = GetCustomAttributes (typeof (DefaultMemberAttribute), true);
814                         if (att.Length == 0)
815                                 return new MemberInfo [0];
816
817                         MemberInfo [] member = GetMember (((DefaultMemberAttribute) att [0]).MemberName);
818                         return (member != null) ? member : new MemberInfo [0];
819                 }
820
821                 public virtual MemberInfo[] FindMembers (MemberTypes memberType, BindingFlags bindingAttr,
822                                                          MemberFilter filter, object filterCriteria)
823                 {
824                         MemberInfo[] result;
825                         ArrayList l = new ArrayList ();
826
827                         // Console.WriteLine ("FindMembers for {0} (Type: {1}): {2}",
828                         // this.FullName, this.GetType().FullName, this.obj_address());
829
830                         if ((memberType & MemberTypes.Constructor) != 0) {
831                                 ConstructorInfo[] c = GetConstructors (bindingAttr);
832                                 if (filter != null) {
833                                         foreach (MemberInfo m in c) {
834                                                 if (filter (m, filterCriteria))
835                                                         l.Add (m);
836                                         }
837                                 } else {
838                                         l.AddRange (c);
839                                 }
840                         }
841                         if ((memberType & MemberTypes.Event) != 0) {
842                                 EventInfo[] c = GetEvents (bindingAttr);
843                                 if (filter != null) {
844                                         foreach (MemberInfo m in c) {
845                                                 if (filter (m, filterCriteria))
846                                                         l.Add (m);
847                                         }
848                                 } else {
849                                         l.AddRange (c);
850                                 }
851                         }
852                         if ((memberType & MemberTypes.Field) != 0) {
853                                 FieldInfo[] c = GetFields (bindingAttr);
854                                 if (filter != null) {
855                                         foreach (MemberInfo m in c) {
856                                                 if (filter (m, filterCriteria))
857                                                         l.Add (m);
858                                         }
859                                 } else {
860                                         l.AddRange (c);
861                                 }
862                         }
863                         if ((memberType & MemberTypes.Method) != 0) {
864                                 MethodInfo[] c = GetMethods (bindingAttr);
865                                 if (filter != null) {
866                                         foreach (MemberInfo m in c) {
867                                                 if (filter (m, filterCriteria))
868                                                         l.Add (m);
869                                         }
870                                 } else {
871                                         l.AddRange (c);
872                                 }
873                         }
874                         if ((memberType & MemberTypes.Property) != 0) {
875                                 PropertyInfo[] c;
876                                 int count = l.Count;
877                                 Type ptype;
878                                 if (filter != null) {
879                                         ptype = this;
880                                         while ((l.Count == count) && (ptype != null)) {
881                                                 c = ptype.GetProperties (bindingAttr);
882                                                 foreach (MemberInfo m in c) {
883                                                         if (filter (m, filterCriteria))
884                                                                 l.Add (m);
885                                                 }
886                                                 ptype = ptype.BaseType;
887                                         }
888                                 } else {
889                                         c = GetProperties (bindingAttr);
890                                         l.AddRange (c);
891                                 }
892                         }
893                         if ((memberType & MemberTypes.NestedType) != 0) {
894                                 Type[] c = GetNestedTypes (bindingAttr);
895                                 if (filter != null) {
896                                         foreach (MemberInfo m in c) {
897                                                 if (filter (m, filterCriteria)) {
898                                                         l.Add (m);
899                                                 }
900                                         }
901                                 } else {
902                                         l.AddRange (c);
903                                 }
904                         }
905                         result = new MemberInfo [l.Count];
906                         l.CopyTo (result);
907                         return result;
908                 }
909
910                 public object InvokeMember (string name, BindingFlags invokeAttr, Binder binder,
911                                             object target, object[] args)
912                 {
913                         return InvokeMember (name, invokeAttr, binder, target, args, null, null, null);
914                 }
915
916                 public object InvokeMember (string name, BindingFlags invokeAttr, Binder binder,
917                                             object target, object[] args, CultureInfo culture)
918                 {
919                         return InvokeMember (name, invokeAttr, binder, target, args, null, culture, null);
920                 }
921
922                 public abstract object InvokeMember (string name, BindingFlags invokeAttr,
923                                                      Binder binder, object target, object[] args,
924                                                      ParameterModifier[] modifiers,
925                                                      CultureInfo culture, string[] namedParameters);
926
927                 public override string ToString()
928                 {
929                         return FullName;
930                 }
931
932 #if GENERICS
933                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
934                 public extern Type [] GetGenericParameters ();
935
936                 public abstract bool HasGenericParameters {
937                         get;
938                 }
939
940                 public abstract bool HasUnboundGenericParameters {
941                         get;
942                 }
943
944                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
945                 static extern Type GetGenericTypeDefinition (Type t);
946
947                 public virtual Type GetGenericTypeDefinition ()
948                 {
949                         Type res = GetGenericTypeDefinition (this);
950                         if (res == null)
951                                 throw new ArgumentException ();
952                         return res;
953                 }
954
955                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
956                 public extern Type IsGenericTypeDefinition ();
957
958                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
959                 static extern Type BindGenericParameters (Type gt, Type [] types);
960                 
961                 public Type BindGenericParameters (Type [] types)
962                 {
963                         if (types == null)
964                                 throw new ArgumentNullException ("types");
965                         foreach (Type t in types) {
966                                 if (t == null)
967                                         throw new ArgumentNullException ("types");
968                         }
969                         Type res = BindGenericParameters (this, types);
970                         if (res == null)
971                                 throw new TypeLoadException ();
972                         return res;
973                 }
974
975                 public abstract bool IsUnboundGenericParameter {
976                         get;
977                 }
978
979                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
980                 extern int GetGenericParameterPosition ();
981                 
982                 public virtual int GenericParameterPosition {
983                         get {
984                                 int res = GetGenericParameterPosition ();
985                                 if (res < 0)
986                                         throw new ArgumentException ();
987                                 return res;
988                         }
989                 }
990 #endif
991         }
992 }