Implicitly typed array cannot have multiple dimensions
[mono.git] / mcs / mcs / import.cs
1 //
2 // import.cs: System.Reflection conversions
3 //
4 // Authors: Marek Safar (marek.safar@gmail.com)
5 //
6 // Dual licensed under the terms of the MIT X11 or GNU GPL
7 //
8 // Copyright 2009, 2010 Novell, Inc
9 //
10
11 using System;
12 using System.Runtime.CompilerServices;
13 using System.Linq;
14 using System.Collections.Generic;
15
16 #if STATIC
17 using MetaType = IKVM.Reflection.Type;
18 using IKVM.Reflection;
19 using IKVM.Reflection.Emit;
20 #else
21 using MetaType = System.Type;
22 using System.Reflection;
23 using System.Reflection.Emit;
24 #endif
25
26 namespace Mono.CSharp
27 {
28         public abstract class MetadataImporter
29         {
30                 //
31                 // Dynamic types reader with additional logic to reconstruct a dynamic
32                 // type using DynamicAttribute values
33                 //
34                 struct DynamicTypeReader
35                 {
36                         static readonly bool[] single_attribute = { true };
37
38                         public int Position;
39                         bool[] flags;
40
41                         // There is no common type for CustomAttributeData and we cannot
42                         // use ICustomAttributeProvider
43                         object provider;
44
45                         //
46                         // A member provider which can be used to get CustomAttributeData
47                         //
48                         public DynamicTypeReader (object provider)
49                         {
50                                 Position = 0;
51                                 flags = null;
52                                 this.provider = provider;
53                         }
54
55                         //
56                         // Returns true when object at local position has dynamic attribute flag
57                         //
58                         public bool IsDynamicObject (MetadataImporter importer)
59                         {
60                                 if (provider != null)
61                                         ReadAttribute (importer);
62
63                                 return flags != null && Position < flags.Length && flags[Position];
64                         }
65
66                         //
67                         // Returns true when DynamicAttribute exists
68                         //
69                         public bool HasDynamicAttribute (MetadataImporter importer)
70                         {
71                                 if (provider != null)
72                                         ReadAttribute (importer);
73
74                                 return flags != null;
75                         }
76
77                         void ReadAttribute (MetadataImporter importer)
78                         {
79                                 IList<CustomAttributeData> cad;
80                                 if (provider is MemberInfo) {
81                                         cad = CustomAttributeData.GetCustomAttributes ((MemberInfo) provider);
82                                 } else if (provider is ParameterInfo) {
83                                         cad = CustomAttributeData.GetCustomAttributes ((ParameterInfo) provider);
84                                 } else {
85                                         provider = null;
86                                         return;
87                                 }
88
89                                 if (cad.Count > 0) {
90                                         string ns, name;
91                                         foreach (var ca in cad) {
92                                                 importer.GetCustomAttributeTypeName (ca, out ns, out name);
93                                                 if (name != "DynamicAttribute" && ns != CompilerServicesNamespace)
94                                                         continue;
95
96                                                 if (ca.ConstructorArguments.Count == 0) {
97                                                         flags = single_attribute;
98                                                         break;
99                                                 }
100
101                                                 var arg_type = ca.ConstructorArguments[0].ArgumentType;
102
103                                                 if (arg_type.IsArray && MetaType.GetTypeCode (arg_type.GetElementType ()) == TypeCode.Boolean) {
104                                                         var carg = (IList<CustomAttributeTypedArgument>) ca.ConstructorArguments[0].Value;
105                                                         flags = new bool[carg.Count];
106                                                         for (int i = 0; i < flags.Length; ++i) {
107                                                                 if (MetaType.GetTypeCode (carg[i].ArgumentType) == TypeCode.Boolean)
108                                                                         flags[i] = (bool) carg[i].Value;
109                                                         }
110
111                                                         break;
112                                                 }
113                                         }
114                                 }
115
116                                 provider = null;
117                         }
118                 }
119
120                 protected readonly Dictionary<MetaType, TypeSpec> import_cache;
121                 protected readonly Dictionary<MetaType, TypeSpec> compiled_types;
122                 protected readonly Dictionary<Assembly, IAssemblyDefinition> assembly_2_definition;
123
124                 public static readonly string CompilerServicesNamespace = "System.Runtime.CompilerServices";
125
126                 protected MetadataImporter ()
127                 {
128                         import_cache = new Dictionary<MetaType, TypeSpec> (1024, ReferenceEquality<MetaType>.Default);
129                         compiled_types = new Dictionary<MetaType, TypeSpec> (40, ReferenceEquality<MetaType>.Default);
130                         assembly_2_definition = new Dictionary<Assembly, IAssemblyDefinition> (ReferenceEquality<Assembly>.Default);
131                         IgnorePrivateMembers = true;
132                 }
133
134                 #region Properties
135
136                 public ICollection<IAssemblyDefinition> Assemblies {
137                         get {
138                                 return assembly_2_definition.Values;
139                         }
140                 }
141
142                 public bool IgnorePrivateMembers { get; set; }
143
144                 #endregion
145
146                 public abstract void AddCompiledType (TypeBuilder builder, TypeSpec spec);
147                 protected abstract MemberKind DetermineKindFromBaseType (MetaType baseType);
148                 protected abstract bool HasVolatileModifier (MetaType[] modifiers);
149                 public abstract void GetCustomAttributeTypeName (CustomAttributeData cad, out string typeNamespace, out string typeName);
150
151                 public FieldSpec CreateField (FieldInfo fi, TypeSpec declaringType)
152                 {
153                         Modifiers mod = 0;
154                         var fa = fi.Attributes;
155                         switch (fa & FieldAttributes.FieldAccessMask) {
156                                 case FieldAttributes.Public:
157                                         mod = Modifiers.PUBLIC;
158                                         break;
159                                 case FieldAttributes.Assembly:
160                                         mod = Modifiers.INTERNAL;
161                                         break;
162                                 case FieldAttributes.Family:
163                                         mod = Modifiers.PROTECTED;
164                                         break;
165                                 case FieldAttributes.FamORAssem:
166                                         mod = Modifiers.PROTECTED | Modifiers.INTERNAL;
167                                         break;
168                                 default:
169                                         // Ignore private fields (even for error reporting) to not require extra dependencies
170                                         if (IgnorePrivateMembers || HasAttribute (CustomAttributeData.GetCustomAttributes (fi), "CompilerGeneratedAttribute", CompilerServicesNamespace))
171                                                 return null;
172
173                                         mod = Modifiers.PRIVATE;
174                                         break;
175                         }
176
177                         TypeSpec field_type;
178
179                         try {
180                                 field_type = ImportType (fi.FieldType, new DynamicTypeReader (fi));
181                         } catch (Exception e) {
182                                 // TODO: I should construct fake TypeSpec based on TypeRef signature
183                                 // but there is no way to do it with System.Reflection
184                                 throw new InternalErrorException (e, "Cannot import field `{0}.{1}' referenced in assembly `{2}'",
185                                         declaringType.GetSignatureForError (), fi.Name, declaringType.MemberDefinition.DeclaringAssembly);
186                         }
187
188                         var definition = new ImportedMemberDefinition (fi, field_type, this);
189
190                         if ((fa & FieldAttributes.Literal) != 0) {
191                                 var c = Constant.CreateConstantFromValue (field_type, fi.GetRawConstantValue (), Location.Null);
192                                 return new ConstSpec (declaringType, definition, field_type, fi, mod, c);
193                         }
194
195                         if ((fa & FieldAttributes.InitOnly) != 0) {
196                                 if (field_type == TypeManager.decimal_type) {
197                                         var dc = ReadDecimalConstant (CustomAttributeData.GetCustomAttributes (fi));
198                                         if (dc != null)
199                                                 return new ConstSpec (declaringType, definition, field_type, fi, mod, dc);
200                                 }
201
202                                 mod |= Modifiers.READONLY;
203                         } else {
204                                 var req_mod = fi.GetRequiredCustomModifiers ();
205                                 if (req_mod.Length > 0 && HasVolatileModifier (req_mod))
206                                         mod |= Modifiers.VOLATILE;
207                         }
208
209                         if ((fa & FieldAttributes.Static) != 0) {
210                                 mod |= Modifiers.STATIC;
211                         } else {
212                                 // Fixed buffers cannot be static
213                                 if (declaringType.IsStruct && field_type.IsStruct && field_type.IsNested &&
214                                         HasAttribute (CustomAttributeData.GetCustomAttributes (fi), "FixedBufferAttribute", CompilerServicesNamespace)) {
215
216                                         // TODO: Sanity check on field_type (only few type are allowed)
217                                         var element_field = CreateField (fi.FieldType.GetField (FixedField.FixedElementName), declaringType);
218                                         return new FixedFieldSpec (declaringType, definition, fi, element_field, mod);
219                                 }
220                         }
221
222                         return new FieldSpec (declaringType, definition, field_type, fi, mod);
223                 }
224
225                 public EventSpec CreateEvent (EventInfo ei, TypeSpec declaringType, MethodSpec add, MethodSpec remove)
226                 {
227                         add.IsAccessor = true;
228                         remove.IsAccessor = true;
229
230                         if (add.Modifiers != remove.Modifiers)
231                                 throw new NotImplementedException ("Different accessor modifiers " + ei.Name);
232
233                         var event_type = ImportType (ei.EventHandlerType, new DynamicTypeReader (ei));
234                         var definition = new ImportedMemberDefinition (ei, event_type,  this);
235                         return new EventSpec (declaringType, definition, event_type, add.Modifiers, add, remove);
236                 }
237
238                 TypeParameterSpec[] CreateGenericParameters (MetaType type, TypeSpec declaringType)
239                 {
240                         var tparams = type.GetGenericArguments ();
241
242                         int parent_owned_count;
243                         if (type.IsNested) {
244                                 parent_owned_count = type.DeclaringType.GetGenericArguments ().Length;
245
246                                 //
247                                 // System.Reflection duplicates parent type parameters for each
248                                 // nested type with slightly modified properties (eg. different owner)
249                                 // This just makes things more complicated (think of cloned constraints)
250                                 // therefore we remap any nested type owned by parent using `type_cache'
251                                 // to the single TypeParameterSpec
252                                 //
253                                 if (declaringType != null && parent_owned_count > 0) {
254                                         int read_count = 0;
255                                         while (read_count != parent_owned_count) {
256                                                 var tparams_count = declaringType.Arity;
257                                                 if (tparams_count != 0) {
258                                                         var parent_tp = declaringType.MemberDefinition.TypeParameters;
259                                                         read_count += tparams_count;
260                                                         for (int i = 0; i < tparams_count; i++) {
261                                                                 import_cache.Add (tparams[parent_owned_count - read_count + i], parent_tp[i]);
262                                                         }
263                                                 }
264
265                                                 declaringType = declaringType.DeclaringType;
266                                         }
267                                 }                       
268                         } else {
269                                 parent_owned_count = 0;
270                         }
271
272                         if (tparams.Length - parent_owned_count == 0)
273                                 return null;
274
275                         return CreateGenericParameters (parent_owned_count, tparams);
276                 }
277
278                 TypeParameterSpec[] CreateGenericParameters (int first, MetaType[] tparams)
279                 {
280                         var tspec = new TypeParameterSpec[tparams.Length - first];
281                         for (int pos = first; pos < tparams.Length; ++pos) {
282                                 var type = tparams[pos];
283                                 int index = pos - first;
284
285                                 tspec [index] = (TypeParameterSpec) CreateType (type, new DynamicTypeReader (), false);
286                         }
287
288                         return tspec;
289                 }
290
291                 TypeSpec[] CreateGenericArguments (int first, MetaType[] tparams, DynamicTypeReader dtype)
292                 {
293                         ++dtype.Position;
294
295                         var tspec = new TypeSpec [tparams.Length - first];
296                         for (int pos = first; pos < tparams.Length; ++pos) {
297                                 var type = tparams[pos];
298                                 int index = pos - first;
299
300                                 TypeSpec spec;
301                                 if (type.HasElementType) {
302                                         var element = type.GetElementType ();
303                                         ++dtype.Position;
304                                         spec = ImportType (element, dtype);
305
306                                         if (!type.IsArray) {
307                                                 throw new NotImplementedException ("Unknown element type " + type.ToString ());
308                                         }
309
310                                         spec = ArrayContainer.MakeType (spec, type.GetArrayRank ());
311                                 } else {
312                                         spec = CreateType (type, dtype, true);
313
314                                         //
315                                         // We treat nested generic types as inflated internally where
316                                         // reflection uses type definition
317                                         //
318                                         // class A<T> {
319                                         //    IFoo<A<T>> foo;   // A<T> is definition in this case
320                                         // }
321                                         //
322                                         // TODO: Is full logic from CreateType needed here as well?
323                                         //
324                                         if (!IsMissingType (type) && type.IsGenericTypeDefinition) {
325                                                 var targs = CreateGenericArguments (0, type.GetGenericArguments (), dtype);
326                                                 spec = spec.MakeGenericType (targs);
327                                         }
328                                 }
329
330                                 ++dtype.Position;
331                                 tspec[index] = spec;
332                         }
333
334                         return tspec;
335                 }
336
337                 public MethodSpec CreateMethod (MethodBase mb, TypeSpec declaringType)
338                 {
339                         Modifiers mod = ReadMethodModifiers (mb, declaringType);
340                         TypeParameterSpec[] tparams;
341
342                         var parameters = CreateParameters (declaringType, mb.GetParameters (), mb);
343
344                         if (mb.IsGenericMethod) {
345                                 if (!mb.IsGenericMethodDefinition)
346                                         throw new NotSupportedException ("assert");
347
348                                 tparams = CreateGenericParameters (0, mb.GetGenericArguments ());
349                         } else {
350                                 tparams = null;
351                         }
352
353                         MemberKind kind;
354                         TypeSpec returnType;
355                         if (mb.MemberType == MemberTypes.Constructor) {
356                                 kind = MemberKind.Constructor;
357                                 returnType = TypeManager.void_type;
358                         } else {
359                                 //
360                                 // Detect operators and destructors
361                                 //
362                                 string name = mb.Name;
363                                 kind = MemberKind.Method;
364                                 if (tparams == null && !mb.DeclaringType.IsInterface && name.Length > 6) {
365                                         if ((mod & (Modifiers.STATIC | Modifiers.PUBLIC)) == (Modifiers.STATIC | Modifiers.PUBLIC)) {
366                                                 if (name[2] == '_' && name[1] == 'p' && name[0] == 'o') {
367                                                         var op_type = Operator.GetType (name);
368                                                         if (op_type.HasValue && parameters.Count > 0 && parameters.Count < 3) {
369                                                                 kind = MemberKind.Operator;
370                                                         }
371                                                 }
372                                         } else if (parameters.IsEmpty && name == Destructor.MetadataName) {
373                                                 kind = MemberKind.Destructor;
374                                                 if (declaringType == TypeManager.object_type) {
375                                                         mod &= ~Modifiers.OVERRIDE;
376                                                         mod |= Modifiers.VIRTUAL;
377                                                 }
378                                         }
379                                 }
380
381                                 var mi = (MethodInfo) mb;
382                                 returnType = ImportType (mi.ReturnType, new DynamicTypeReader (mi.ReturnParameter));
383
384                                 // Cannot set to OVERRIDE without full hierarchy checks
385                                 // this flag indicates that the method could be override
386                                 // but further validation is needed
387                                 if ((mod & Modifiers.OVERRIDE) != 0 && kind == MemberKind.Method && declaringType.BaseType != null) {
388                                         var filter = MemberFilter.Method (name, tparams != null ? tparams.Length : 0, parameters, null);
389                                         var candidate = MemberCache.FindMember (declaringType.BaseType, filter, BindingRestriction.None);
390
391                                         //
392                                         // For imported class method do additional validation to be sure that metadata
393                                         // override flag was correct
394                                         // 
395                                         // Difference between protected internal and protected is ok
396                                         //
397                                         const Modifiers conflict_mask = Modifiers.AccessibilityMask & ~Modifiers.INTERNAL;
398                                         if (candidate == null || (candidate.Modifiers & conflict_mask) != (mod & conflict_mask) || candidate.IsStatic) {
399                                                 mod &= ~Modifiers.OVERRIDE;
400                                         }
401                                 }
402                         }
403
404                         IMemberDefinition definition;
405                         if (tparams != null) {
406                                 definition = new ImportedGenericMethodDefinition ((MethodInfo) mb, returnType, parameters, tparams, this);
407                         } else {
408                                 definition = new ImportedParameterMemberDefinition (mb, returnType, parameters, this);
409                         }
410
411                         MethodSpec ms = new MethodSpec (kind, declaringType, definition, returnType, mb, parameters, mod);
412                         if (tparams != null)
413                                 ms.IsGeneric = true;
414
415                         return ms;
416                 }
417
418                 //
419                 // Imports System.Reflection parameters
420                 //
421                 AParametersCollection CreateParameters (TypeSpec parent, ParameterInfo[] pi, MethodBase method)
422                 {
423                         int varargs = method != null && (method.CallingConvention & CallingConventions.VarArgs) != 0 ? 1 : 0;
424
425                         if (pi.Length == 0 && varargs == 0)
426                                 return ParametersCompiled.EmptyReadOnlyParameters;
427
428                         TypeSpec[] types = new TypeSpec[pi.Length + varargs];
429                         IParameterData[] par = new IParameterData[pi.Length + varargs];
430                         bool is_params = false;
431                         for (int i = 0; i < pi.Length; i++) {
432                                 ParameterInfo p = pi[i];
433                                 Parameter.Modifier mod = 0;
434                                 Expression default_value = null;
435                                 if (p.ParameterType.IsByRef) {
436                                         if ((p.Attributes & (ParameterAttributes.Out | ParameterAttributes.In)) == ParameterAttributes.Out)
437                                                 mod = Parameter.Modifier.OUT;
438                                         else
439                                                 mod = Parameter.Modifier.REF;
440
441                                         //
442                                         // Strip reference wrapping
443                                         //
444                                         var el = p.ParameterType.GetElementType ();
445                                         types[i] = ImportType (el, new DynamicTypeReader (p));  // TODO: 1-based positio to be csc compatible
446                                 } else if (i == 0 && method.IsStatic && parent.IsStatic && parent.MemberDefinition.DeclaringAssembly.HasExtensionMethod &&
447                                         HasAttribute (CustomAttributeData.GetCustomAttributes (method), "ExtensionAttribute", CompilerServicesNamespace)) {
448                                         mod = Parameter.Modifier.This;
449                                         types[i] = ImportType (p.ParameterType);
450                                 } else {
451                                         types[i] = ImportType (p.ParameterType, new DynamicTypeReader (p));
452
453                                         if (i >= pi.Length - 2 && types[i] is ArrayContainer) {
454                                                 if (HasAttribute (CustomAttributeData.GetCustomAttributes (p), "ParamArrayAttribute", "System")) {
455                                                         mod = Parameter.Modifier.PARAMS;
456                                                         is_params = true;
457                                                 }
458                                         }
459
460                                         if (!is_params && p.IsOptional) {
461                                                 object value = p.RawDefaultValue;
462                                                 var ptype = types[i];
463                                                 if ((p.Attributes & ParameterAttributes.HasDefault) != 0 && ptype.Kind != MemberKind.TypeParameter && (value != null || TypeManager.IsReferenceType (ptype))) {
464                                                         if (value == null) {
465                                                                 default_value = Constant.CreateConstant (null, ptype, null, Location.Null);
466                                                         } else {
467                                                                 default_value = ImportParameterConstant (value).Resolve (null);
468
469                                                                 if (ptype.IsEnum) {
470                                                                         default_value = new EnumConstant ((Constant) default_value, ptype).Resolve (null);
471                                                                 }
472                                                         }
473                                                 } else if (value == Missing.Value) {
474                                                         default_value = EmptyExpression.MissingValue;
475                                                 } else if (value == null) {
476                                                         default_value = new DefaultValueExpression (new TypeExpression (ptype, Location.Null), Location.Null);
477                                                 } else if (ptype == TypeManager.decimal_type) {
478                                                         default_value = ImportParameterConstant (value).Resolve (null);
479                                                 }
480                                         }
481                                 }
482
483                                 par[i] = new ParameterData (p.Name, mod, default_value);
484                         }
485
486                         if (varargs != 0) {
487                                 par[par.Length - 1] = new ArglistParameter (Location.Null);
488                                 types[types.Length - 1] = InternalType.Arglist;
489                         }
490
491                         return method != null ?
492                                 new ParametersImported (par, types, varargs != 0, is_params) :
493                                 new ParametersImported (par, types, is_params);
494                 }
495
496                 //
497                 // Returns null when the property is not valid C# property
498                 //
499                 public PropertySpec CreateProperty (PropertyInfo pi, TypeSpec declaringType, MethodSpec get, MethodSpec set)
500                 {
501                         Modifiers mod = 0;
502                         AParametersCollection param = null;
503                         TypeSpec type = null;
504                         if (get != null) {
505                                 mod = get.Modifiers;
506                                 param = get.Parameters;
507                                 type = get.ReturnType;
508                         }
509
510                         bool is_valid_property = true;
511                         if (set != null) {
512                                 if (set.ReturnType != TypeManager.void_type)
513                                         is_valid_property = false;
514
515                                 var set_param_count = set.Parameters.Count - 1;
516
517                                 if (set_param_count < 0) {
518                                         set_param_count = 0;
519                                         is_valid_property = false;
520                                 }
521
522                                 var set_type = set.Parameters.Types[set_param_count];
523
524                                 if (mod == 0) {
525                                         AParametersCollection set_based_param;
526
527                                         if (set_param_count == 0) {
528                                                 set_based_param = ParametersCompiled.EmptyReadOnlyParameters;
529                                         } else {
530                                                 //
531                                                 // Create indexer parameters based on setter method parameters (the last parameter has to be removed)
532                                                 //
533                                                 var data = new IParameterData[set_param_count];
534                                                 var types = new TypeSpec[set_param_count];
535                                                 Array.Copy (set.Parameters.FixedParameters, data, set_param_count);
536                                                 Array.Copy (set.Parameters.Types, types, set_param_count);
537                                                 set_based_param = new ParametersImported (data, types, set.Parameters.HasParams);
538                                         }
539
540                                         mod = set.Modifiers;
541                                         param = set_based_param;
542                                         type = set_type;
543                                 } else {
544                                         if (set_param_count != get.Parameters.Count)
545                                                 is_valid_property = false;
546
547                                         if (get.ReturnType != set_type)
548                                                 is_valid_property = false;
549
550                                         // Possible custom accessor modifiers
551                                         if ((mod & Modifiers.AccessibilityMask) != (set.Modifiers & Modifiers.AccessibilityMask)) {
552                                                 var get_acc = mod & Modifiers.AccessibilityMask;
553                                                 if (get_acc != Modifiers.PUBLIC) {
554                                                         var set_acc = set.Modifiers & Modifiers.AccessibilityMask;
555                                                         // If the accessor modifiers are not same, do extra restriction checks
556                                                         if (get_acc != set_acc) {
557                                                                 var get_restr = ModifiersExtensions.IsRestrictedModifier (get_acc, set_acc);
558                                                                 var set_restr = ModifiersExtensions.IsRestrictedModifier (set_acc, get_acc);
559                                                                 if (get_restr && set_restr) {
560                                                                         is_valid_property = false; // Neither is more restrictive
561                                                                 }
562
563                                                                 if (get_restr) {
564                                                                         mod &= ~Modifiers.AccessibilityMask;
565                                                                         mod |= set_acc;
566                                                                 }
567                                                         }
568                                                 }
569                                         }
570                                 }
571                         }
572
573                         PropertySpec spec = null;
574                         if (!param.IsEmpty) {
575                                 var index_name = declaringType.MemberDefinition.GetAttributeDefaultMember ();
576                                 if (index_name == null) {
577                                         is_valid_property = false;
578                                 } else {
579                                         if (get != null) {
580                                                 if (get.IsStatic)
581                                                         is_valid_property = false;
582                                                 if (get.Name.IndexOf (index_name, StringComparison.Ordinal) != 4)
583                                                         is_valid_property = false;
584                                         }
585                                         if (set != null) {
586                                                 if (set.IsStatic)
587                                                         is_valid_property = false;
588                                                 if (set.Name.IndexOf (index_name, StringComparison.Ordinal) != 4)
589                                                         is_valid_property = false;
590                                         }
591                                 }
592
593                                 if (is_valid_property)
594                                         spec = new IndexerSpec (declaringType, new ImportedParameterMemberDefinition (pi, type, param, this), type, param, pi, mod);
595                         }
596
597                         if (spec == null)
598                                 spec = new PropertySpec (MemberKind.Property, declaringType, new ImportedMemberDefinition (pi, type, this), type, pi, mod);
599
600                         if (!is_valid_property) {
601                                 spec.IsNotRealProperty = true;
602                                 return spec;
603                         }
604
605                         if (set != null)
606                                 spec.Set = set;
607                         if (get != null)
608                                 spec.Get = get;
609
610                         return spec;
611                 }
612
613                 public TypeSpec CreateType (MetaType type)
614                 {
615                         return CreateType (type, new DynamicTypeReader (), true);
616                 }
617
618                 public TypeSpec CreateNestedType (MetaType type, TypeSpec declaringType)
619                 {
620                         return CreateType (type, declaringType, new DynamicTypeReader (type), false);
621                 }
622
623                 TypeSpec CreateType (MetaType type, DynamicTypeReader dtype, bool canImportBaseType)
624                 {
625                         TypeSpec declaring_type;
626                         if (type.IsNested && !type.IsGenericParameter)
627                                 declaring_type = CreateType (type.DeclaringType, new DynamicTypeReader (type.DeclaringType), true);
628                         else
629                                 declaring_type = null;
630
631                         return CreateType (type, declaring_type, dtype, canImportBaseType);
632                 }
633
634                 TypeSpec CreateType (MetaType type, TypeSpec declaringType, DynamicTypeReader dtype, bool canImportBaseType)
635                 {
636                         TypeSpec spec;
637                         if (import_cache.TryGetValue (type, out spec)) {
638                                 if (spec == TypeManager.object_type) {
639                                         if (dtype.IsDynamicObject (this))
640                                                 return InternalType.Dynamic;
641
642                                         return spec;
643                                 }
644
645                                 if (!spec.IsGeneric || type.IsGenericTypeDefinition)
646                                         return spec;
647
648                                 if (!dtype.HasDynamicAttribute (this))
649                                         return spec;
650
651                                 // We've found same object in the cache but this one has a dynamic custom attribute
652                                 // and it's most likely dynamic version of same type IFoo<object> agains IFoo<dynamic>
653                                 // Do type resolve process again in that case
654
655                                 // TODO: Handle cases where they still unify
656                         }
657
658                         if (IsMissingType (type)) {
659                                 spec = new TypeSpec (MemberKind.MissingType, declaringType, new ImportedTypeDefinition (type, this), type, Modifiers.PUBLIC);
660                                 spec.MemberCache = MemberCache.Empty;
661                                 import_cache.Add (type, spec);
662                                 return spec;
663                         }
664
665                         if (type.IsGenericType && !type.IsGenericTypeDefinition) {
666                                 var type_def = type.GetGenericTypeDefinition ();
667                                 var targs = CreateGenericArguments (0, type.GetGenericArguments (), dtype);
668                                 if (declaringType == null) {
669                                         // Simple case, no nesting
670                                         spec = CreateType (type_def, null, new DynamicTypeReader (), canImportBaseType);
671                                         spec = spec.MakeGenericType (targs);
672                                 } else {
673                                         //
674                                         // Nested type case, converting .NET types like
675                                         // A`1.B`1.C`1<int, long, string> to typespec like
676                                         // A<int>.B<long>.C<string>
677                                         //
678                                         var nested_hierarchy = new List<TypeSpec> ();
679                                         while (declaringType.IsNested) {
680                                                 nested_hierarchy.Add (declaringType);
681                                                 declaringType = declaringType.DeclaringType;
682                                         }
683
684                                         int targs_pos = 0;
685                                         if (declaringType.Arity > 0) {
686                                                 spec = declaringType.MakeGenericType (targs.Skip (targs_pos).Take (declaringType.Arity).ToArray ());
687                                                 targs_pos = spec.Arity;
688                                         } else {
689                                                 spec = declaringType;
690                                         }
691
692                                         for (int i = nested_hierarchy.Count; i != 0; --i) {
693                                                 var t = nested_hierarchy [i - 1];
694                                                 spec = MemberCache.FindNestedType (spec, t.Name, t.Arity);
695                                                 if (t.Arity > 0) {
696                                                         spec = spec.MakeGenericType (targs.Skip (targs_pos).Take (spec.Arity).ToArray ());
697                                                         targs_pos += t.Arity;
698                                                 }
699                                         }
700
701                                         string name = type.Name;
702                                         int index = name.IndexOf ('`');
703                                         if (index > 0)
704                                                 name = name.Substring (0, index);
705
706                                         spec = MemberCache.FindNestedType (spec, name, targs.Length - targs_pos);
707                                         if (spec.Arity > 0) {
708                                                 spec = spec.MakeGenericType (targs.Skip (targs_pos).ToArray ());
709                                         }
710                                 }
711
712                                 // Don't add generic type with dynamic arguments, they can interfere with same type
713                                 // using object type arguments
714                                 if (!spec.HasDynamicElement) {
715
716                                         // Add to reading cache to speed up reading
717                                         if (!import_cache.ContainsKey (type))
718                                                 import_cache.Add (type, spec);
719                                 }
720
721                                 return spec;
722                         }
723
724                         Modifiers mod;
725                         MemberKind kind;
726
727                         var ma = type.Attributes;
728                         switch (ma & TypeAttributes.VisibilityMask) {
729                         case TypeAttributes.Public:
730                         case TypeAttributes.NestedPublic:
731                                 mod = Modifiers.PUBLIC;
732                                 break;
733                         case TypeAttributes.NestedPrivate:
734                                 mod = Modifiers.PRIVATE;
735                                 break;
736                         case TypeAttributes.NestedFamily:
737                                 mod = Modifiers.PROTECTED;
738                                 break;
739                         case TypeAttributes.NestedFamORAssem:
740                                 mod = Modifiers.PROTECTED | Modifiers.INTERNAL;
741                                 break;
742                         default:
743                                 mod = Modifiers.INTERNAL;
744                                 break;
745                         }
746
747                         if ((ma & TypeAttributes.Interface) != 0) {
748                                 kind = MemberKind.Interface;
749                         } else if (type.IsGenericParameter) {
750                                 kind = MemberKind.TypeParameter;
751                         } else {
752                                 var base_type = type.BaseType;
753                                 if (base_type == null || (ma & TypeAttributes.Abstract) != 0) {
754                                         kind = MemberKind.Class;
755                                 } else {
756                                         kind = DetermineKindFromBaseType (base_type);
757                                         if (kind == MemberKind.Struct || kind == MemberKind.Delegate) {
758                                                 mod |= Modifiers.SEALED;
759                                         }
760                                 }
761
762                                 if (kind == MemberKind.Class) {
763                                         if ((ma & TypeAttributes.Sealed) != 0) {
764                                                 mod |= Modifiers.SEALED;
765                                                 if ((ma & TypeAttributes.Abstract) != 0)
766                                                         mod |= Modifiers.STATIC;
767                                         } else if ((ma & TypeAttributes.Abstract) != 0) {
768                                                 mod |= Modifiers.ABSTRACT;
769                                         }
770                                 }
771                         }
772
773                         var definition = new ImportedTypeDefinition (type, this);
774                         TypeSpec pt;
775
776                         if (kind == MemberKind.Enum) {
777                                 const BindingFlags underlying_member = BindingFlags.DeclaredOnly |
778                                         BindingFlags.Instance |
779                                         BindingFlags.Public | BindingFlags.NonPublic;
780
781                                 var type_members = type.GetFields (underlying_member);
782                                 foreach (var type_member in type_members) {
783                                         spec = new EnumSpec (declaringType, definition, CreateType (type_member.FieldType), type, mod);
784                                         break;
785                                 }
786
787                                 if (spec == null)
788                                         kind = MemberKind.Class;
789
790                         } else if (kind == MemberKind.TypeParameter) {
791                                 // Return as type_cache was updated
792                                 return CreateTypeParameter (type, declaringType);
793                         } else if (type.IsGenericTypeDefinition) {
794                                 definition.TypeParameters = CreateGenericParameters (type, declaringType);
795
796                                 // Constraints are not loaded on demand and can reference this type
797                                 if (import_cache.TryGetValue (type, out spec))
798                                         return spec;
799
800                         } else if (compiled_types.TryGetValue (type, out pt)) {
801                                 //
802                                 // Same type was found in inside compiled types. It's
803                                 // either build-in type or forward referenced typed
804                                 // which point into just compiled assembly.
805                                 //
806                                 spec = pt;
807                                 BuildinTypeSpec bts = pt as BuildinTypeSpec;
808                                 if (bts != null)
809                                         bts.SetDefinition (definition, type, mod);
810                         }
811
812                         if (spec == null)
813                                 spec = new TypeSpec (kind, declaringType, definition, type, mod);
814
815                         import_cache.Add (type, spec);
816
817                         //
818                         // Two stage setup as the base type can be inflated declaring type or
819                         // another nested type inside same declaring type which has not been
820                         // loaded, therefore we can import a base type of nested types once
821                         // the types have been imported
822                         //
823                         if (canImportBaseType)
824                                 ImportTypeBase (spec, type);
825
826                         return spec;
827                 }
828
829                 public IAssemblyDefinition GetAssemblyDefinition (Assembly assembly)
830                 {
831                         IAssemblyDefinition found;
832                         if (!assembly_2_definition.TryGetValue (assembly, out found)) {
833
834                                 // This can happen in dynamic context only
835                                 var def = new ImportedAssemblyDefinition (assembly, this);
836                                 assembly_2_definition.Add (assembly, def);
837                                 def.ReadAttributes ();
838                                 found = def;
839                         }
840
841                         return found;
842                 }
843
844                 public void ImportTypeBase (MetaType type)
845                 {
846                         TypeSpec spec = import_cache[type];
847                         if (spec != null)
848                                 ImportTypeBase (spec, type);
849                 }
850
851                 TypeParameterSpec CreateTypeParameter (MetaType type, TypeSpec declaringType)
852                 {
853                         Variance variance;
854                         switch (type.GenericParameterAttributes & GenericParameterAttributes.VarianceMask) {
855                         case GenericParameterAttributes.Covariant:
856                                 variance = Variance.Covariant;
857                                 break;
858                         case GenericParameterAttributes.Contravariant:
859                                 variance = Variance.Contravariant;
860                                 break;
861                         default:
862                                 variance = Variance.None;
863                                 break;
864                         }
865
866                         SpecialConstraint special = SpecialConstraint.None;
867                         var import_special = type.GenericParameterAttributes & GenericParameterAttributes.SpecialConstraintMask;
868
869                         if ((import_special & GenericParameterAttributes.NotNullableValueTypeConstraint) != 0) {
870                                 special |= SpecialConstraint.Struct;
871                         } else if ((import_special & GenericParameterAttributes.DefaultConstructorConstraint) != 0) {
872                                 special = SpecialConstraint.Constructor;
873                         }
874
875                         if ((import_special & GenericParameterAttributes.ReferenceTypeConstraint) != 0) {
876                                 special |= SpecialConstraint.Class;
877                         }
878
879                         TypeParameterSpec spec;
880                         var def = new ImportedTypeParameterDefinition (type, this);
881                         if (type.DeclaringMethod != null)
882                                 spec = new TypeParameterSpec (type.GenericParameterPosition, def, special, variance, type);
883                         else
884                                 spec = new TypeParameterSpec (declaringType, type.GenericParameterPosition, def, special, variance, type);
885
886                         // Add it now, so any constraint can reference it and get same instance
887                         import_cache.Add (type, spec);
888
889                         var constraints = type.GetGenericParameterConstraints ();
890                         List<TypeSpec> tparams = null;
891                         foreach (var ct in constraints) {
892                                 if (ct.IsGenericParameter) {
893                                         if (tparams == null)
894                                                 tparams = new List<TypeSpec> ();
895
896                                         tparams.Add (CreateType (ct));
897                                         continue;
898                                 }
899
900                                 if (!IsMissingType (ct) && ct.IsClass) {
901                                         spec.BaseType = CreateType (ct);
902                                         continue;
903                                 }
904
905                                 spec.AddInterface (CreateType (ct));
906                         }
907
908                         if (spec.BaseType == null)
909                                 spec.BaseType = TypeManager.object_type;
910
911                         if (tparams != null)
912                                 spec.TypeArguments = tparams.ToArray ();
913
914                         return spec;
915                 }
916
917                 //
918                 // Test for a custom attribute type match. Custom attributes are not really predefined globaly 
919                 // they can be assembly specific therefore we do check based on names only
920                 //
921                 public bool HasAttribute (IList<CustomAttributeData> attributesData, string attrName, string attrNamespace)
922                 {
923                         if (attributesData.Count == 0)
924                                 return false;
925
926                         string ns, name;
927                         foreach (var attr in attributesData) {
928                                 GetCustomAttributeTypeName (attr, out ns, out name);
929                                 if (name == attrName && ns == attrNamespace)
930                                         return true;
931                         }
932
933                         return false;
934                 }
935
936                 void ImportTypeBase (TypeSpec spec, MetaType type)
937                 {
938                         if (spec.Kind == MemberKind.Interface)
939                                 spec.BaseType = TypeManager.object_type;
940                         else if (type.BaseType != null) {
941                                 TypeSpec base_type;
942                                 if (!IsMissingType (type.BaseType) && type.BaseType.IsGenericType)
943                                         base_type = CreateType (type.BaseType, new DynamicTypeReader (type), true);
944                                 else
945                                         base_type = CreateType (type.BaseType);
946
947                                 spec.BaseType = base_type;
948                         }
949
950                         MetaType[] ifaces;
951 #if STATIC
952                         ifaces = type.__GetDeclaredInterfaces ();
953                         if (ifaces.Length != 0) {
954                                 foreach (var iface in ifaces)
955                                         spec.AddInterface (CreateType (iface));
956                         }
957
958                         if (spec.BaseType != null) {
959                                 var bifaces = spec.BaseType.Interfaces;
960                                 if (bifaces != null) {
961                                         foreach (var iface in bifaces)
962                                                 spec.AddInterface (iface);
963                                 }
964                         }
965 #else
966                         ifaces = type.GetInterfaces ();
967
968                         if (ifaces.Length > 0) {
969                                 foreach (var iface in ifaces) {
970                                         spec.AddInterface (CreateType (iface));
971                                 }
972                         }
973 #endif
974                 }
975
976                 protected void ImportTypes (MetaType[] types, Namespace targetNamespace, bool hasExtensionTypes)
977                 {
978                         Namespace ns = targetNamespace;
979                         string prev_namespace = null;
980                         foreach (var t in types) {
981                                 if (t == null)
982                                         continue;
983
984                                 // Be careful not to trigger full parent type loading
985                                 if (t.MemberType == MemberTypes.NestedType)
986                                         continue;
987
988                                 if (t.Name[0] == '<')
989                                         continue;
990
991                                 var it = CreateType (t, null, new DynamicTypeReader (t), true);
992                                 if (it == null)
993                                         continue;
994
995                                 if (prev_namespace != t.Namespace) {
996                                         ns = t.Namespace == null ? targetNamespace : targetNamespace.GetNamespace (t.Namespace, true);
997                                         prev_namespace = t.Namespace;
998                                 }
999
1000                                 ns.AddType (it);
1001
1002                                 if (it.IsStatic && hasExtensionTypes &&
1003                                         HasAttribute (CustomAttributeData.GetCustomAttributes (t), "ExtensionAttribute", CompilerServicesNamespace)) {
1004                                         it.SetExtensionMethodContainer ();
1005                                 }
1006                         }
1007                 }
1008
1009                 static Constant ImportParameterConstant (object value)
1010                 {
1011                         //
1012                         // Get type of underlying value as int constant can be used for object
1013                         // parameter type. This is not allowed in C# but other languages can do that
1014                         //
1015                         switch (System.Type.GetTypeCode (value.GetType ())) {
1016                         case TypeCode.Boolean:
1017                                 return new BoolConstant ((bool) value, Location.Null);
1018                         case TypeCode.Byte:
1019                                 return new ByteConstant ((byte) value, Location.Null);
1020                         case TypeCode.Char:
1021                                 return new CharConstant ((char) value, Location.Null);
1022                         case TypeCode.Decimal:
1023                                 return new DecimalConstant ((decimal) value, Location.Null);
1024                         case TypeCode.Double:
1025                                 return new DoubleConstant ((double) value, Location.Null);
1026                         case TypeCode.Int16:
1027                                 return new ShortConstant ((short) value, Location.Null);
1028                         case TypeCode.Int32:
1029                                 return new IntConstant ((int) value, Location.Null);
1030                         case TypeCode.Int64:
1031                                 return new LongConstant ((long) value, Location.Null);
1032                         case TypeCode.SByte:
1033                                 return new SByteConstant ((sbyte) value, Location.Null);
1034                         case TypeCode.Single:
1035                                 return new FloatConstant ((float) value, Location.Null);
1036                         case TypeCode.String:
1037                                 return new StringConstant ((string) value, Location.Null);
1038                         case TypeCode.UInt16:
1039                                 return new UShortConstant ((ushort) value, Location.Null);
1040                         case TypeCode.UInt32:
1041                                 return new UIntConstant ((uint) value, Location.Null);
1042                         case TypeCode.UInt64:
1043                                 return new ULongConstant ((ulong) value, Location.Null);
1044                         }
1045
1046                         throw new NotImplementedException (value.GetType ().ToString ());
1047                 }
1048
1049                 public TypeSpec ImportType (MetaType type)
1050                 {
1051                         return ImportType (type, new DynamicTypeReader (type));
1052                 }
1053
1054                 TypeSpec ImportType (MetaType type, DynamicTypeReader dtype)
1055                 {
1056                         if (type.HasElementType) {
1057                                 var element = type.GetElementType ();
1058                                 ++dtype.Position;
1059                                 var spec = ImportType (element, dtype);
1060
1061                                 if (type.IsArray)
1062                                         return ArrayContainer.MakeType (spec, type.GetArrayRank ());
1063                                 if (type.IsByRef)
1064                                         return ReferenceContainer.MakeType (spec);
1065                                 if (type.IsPointer)
1066                                         return PointerContainer.MakeType (spec);
1067
1068                                 throw new NotImplementedException ("Unknown element type " + type.ToString ());
1069                         }
1070
1071                         return CreateType (type, dtype, true);
1072                 }
1073
1074                 static bool IsMissingType (MetaType type)
1075                 {
1076 #if STATIC
1077                         return type.__IsMissing;
1078 #else
1079                         return false;
1080 #endif
1081                 }
1082
1083                 //
1084                 // Decimal constants cannot be encoded in the constant blob, and thus are marked
1085                 // as IsInitOnly ('readonly' in C# parlance).  We get its value from the 
1086                 // DecimalConstantAttribute metadata.
1087                 //
1088                 Constant ReadDecimalConstant (IList<CustomAttributeData> attrs)
1089                 {
1090                         if (attrs.Count == 0)
1091                                 return null;
1092
1093                         string name, ns;
1094                         foreach (var ca in attrs) {
1095                                 GetCustomAttributeTypeName (ca, out ns, out name);
1096                                 if (name != "DecimalConstantAttribute" || ns != CompilerServicesNamespace)
1097                                         continue;
1098
1099                                 var value = new decimal (
1100                                         (int) (uint) ca.ConstructorArguments[4].Value,
1101                                         (int) (uint) ca.ConstructorArguments[3].Value,
1102                                         (int) (uint) ca.ConstructorArguments[2].Value,
1103                                         (byte) ca.ConstructorArguments[1].Value != 0,
1104                                         (byte) ca.ConstructorArguments[0].Value);
1105
1106                                 return new DecimalConstant (value, Location.Null).Resolve (null);
1107                         }
1108
1109                         return null;
1110                 }
1111
1112                 static Modifiers ReadMethodModifiers (MethodBase mb, TypeSpec declaringType)
1113                 {
1114                         Modifiers mod;
1115                         var ma = mb.Attributes;
1116                         switch (ma & MethodAttributes.MemberAccessMask) {
1117                         case MethodAttributes.Public:
1118                                 mod = Modifiers.PUBLIC;
1119                                 break;
1120                         case MethodAttributes.Assembly:
1121                                 mod = Modifiers.INTERNAL;
1122                                 break;
1123                         case MethodAttributes.Family:
1124                                 mod = Modifiers.PROTECTED;
1125                                 break;
1126                         case MethodAttributes.FamORAssem:
1127                                 mod = Modifiers.PROTECTED | Modifiers.INTERNAL;
1128                                 break;
1129                         default:
1130                                 mod = Modifiers.PRIVATE;
1131                                 break;
1132                         }
1133
1134                         if ((ma & MethodAttributes.Static) != 0) {
1135                                 mod |= Modifiers.STATIC;
1136                                 return mod;
1137                         }
1138                         if ((ma & MethodAttributes.Abstract) != 0 && declaringType.IsClass) {
1139                                 mod |= Modifiers.ABSTRACT;
1140                                 return mod;
1141                         }
1142
1143                         if ((ma & MethodAttributes.Final) != 0)
1144                                 mod |= Modifiers.SEALED;
1145
1146                         // It can be sealed and override
1147                         if ((ma & MethodAttributes.Virtual) != 0) {
1148                                 if ((ma & MethodAttributes.NewSlot) != 0 || !declaringType.IsClass) {
1149                                         // No private virtual or sealed virtual
1150                                         if ((mod & (Modifiers.PRIVATE | Modifiers.SEALED)) == 0)
1151                                                 mod |= Modifiers.VIRTUAL;
1152                                 } else {
1153                                         mod |= Modifiers.OVERRIDE;
1154                                 }
1155                         }
1156
1157                         return mod;
1158                 }
1159         }
1160
1161         abstract class ImportedDefinition : IMemberDefinition
1162         {
1163                 protected class AttributesBag
1164                 {
1165                         public static readonly AttributesBag Default = new AttributesBag ();
1166
1167                         public AttributeUsageAttribute AttributeUsage;
1168                         public ObsoleteAttribute Obsolete;
1169                         public string[] Conditionals;
1170                         public string DefaultIndexerName;
1171                         public bool IsNotCLSCompliant;
1172                         public TypeSpec CoClass;
1173                         
1174                         public static AttributesBag Read (MemberInfo mi, MetadataImporter importer)
1175                         {
1176                                 AttributesBag bag = null;
1177                                 List<string> conditionals = null;
1178
1179                                 // It should not throw any loading exception
1180                                 IList<CustomAttributeData> attrs = CustomAttributeData.GetCustomAttributes (mi);
1181
1182                                 string ns, name;
1183                                 foreach (var a in attrs) {
1184                                         importer.GetCustomAttributeTypeName (a, out ns, out name);
1185                                         if (name == "ObsoleteAttribute") {
1186                                                 if (ns != "System")
1187                                                         continue;
1188
1189                                                 if (bag == null)
1190                                                         bag = new AttributesBag ();
1191
1192                                                 var args = a.ConstructorArguments;
1193
1194                                                 if (args.Count == 1) {
1195                                                         bag.Obsolete = new ObsoleteAttribute ((string) args[0].Value);
1196                                                 } else if (args.Count == 2) {
1197                                                         bag.Obsolete = new ObsoleteAttribute ((string) args[0].Value, (bool) args[1].Value);
1198                                                 } else {
1199                                                         bag.Obsolete = new ObsoleteAttribute ();
1200                                                 }
1201
1202                                                 continue;
1203                                         }
1204
1205                                         if (name == "ConditionalAttribute") {
1206                                                 if (ns != "System.Diagnostics")
1207                                                         continue;
1208
1209                                                 if (bag == null)
1210                                                         bag = new AttributesBag ();
1211
1212                                                 if (conditionals == null)
1213                                                         conditionals = new List<string> (2);
1214
1215                                                 conditionals.Add ((string) a.ConstructorArguments[0].Value);
1216                                                 continue;
1217                                         }
1218
1219                                         if (name == "CLSCompliantAttribute") {
1220                                                 if (ns != "System")
1221                                                         continue;
1222
1223                                                 if (bag == null)
1224                                                         bag = new AttributesBag ();
1225
1226                                                 bag.IsNotCLSCompliant = !(bool) a.ConstructorArguments[0].Value;
1227                                                 continue;
1228                                         }
1229
1230                                         // Type only attributes
1231                                         if (mi.MemberType == MemberTypes.TypeInfo || mi.MemberType == MemberTypes.NestedType) {
1232                                                 if (name == "DefaultMemberAttribute") {
1233                                                         if (ns != "System.Reflection")
1234                                                                 continue;
1235
1236                                                         if (bag == null)
1237                                                                 bag = new AttributesBag ();
1238
1239                                                         bag.DefaultIndexerName = (string) a.ConstructorArguments[0].Value;
1240                                                         continue;
1241                                                 }
1242
1243                                                 if (name == "AttributeUsageAttribute") {
1244                                                         if (ns != "System")
1245                                                                 continue;
1246
1247                                                         if (bag == null)
1248                                                                 bag = new AttributesBag ();
1249
1250                                                         bag.AttributeUsage = new AttributeUsageAttribute ((AttributeTargets) a.ConstructorArguments[0].Value);
1251                                                         foreach (var named in a.NamedArguments) {
1252                                                                 if (named.MemberInfo.Name == "AllowMultiple")
1253                                                                         bag.AttributeUsage.AllowMultiple = (bool) named.TypedValue.Value;
1254                                                                 else if (named.MemberInfo.Name == "Inherited")
1255                                                                         bag.AttributeUsage.Inherited = (bool) named.TypedValue.Value;
1256                                                         }
1257                                                         continue;
1258                                                 }
1259
1260                                                 // Interface only attribute
1261                                                 if (name == "CoClassAttribute") {
1262                                                         if (ns != "System.Runtime.InteropServices")
1263                                                                 continue;
1264
1265                                                         if (bag == null)
1266                                                                 bag = new AttributesBag ();
1267
1268                                                         bag.CoClass = importer.ImportType ((MetaType) a.ConstructorArguments[0].Value);
1269                                                         continue;
1270                                                 }
1271                                         }
1272                                 }
1273
1274                                 if (bag == null)
1275                                         return Default;
1276
1277                                 if (conditionals != null)
1278                                         bag.Conditionals = conditionals.ToArray ();
1279                                 
1280                                 return bag;
1281                         }
1282                 }
1283
1284                 protected readonly MemberInfo provider;
1285                 protected AttributesBag cattrs;
1286                 protected readonly MetadataImporter importer;
1287
1288                 public ImportedDefinition (MemberInfo provider, MetadataImporter importer)
1289                 {
1290                         this.provider = provider;
1291                         this.importer = importer;
1292                 }
1293
1294                 #region Properties
1295
1296                 public bool IsImported {
1297                         get {
1298                                 return true;
1299                         }
1300                 }
1301
1302                 public virtual string Name {
1303                         get {
1304                                 return provider.Name;
1305                         }
1306                 }
1307
1308                 #endregion
1309
1310                 public string[] ConditionalConditions ()
1311                 {
1312                         if (cattrs == null)
1313                                 ReadAttributes ();
1314
1315                         return cattrs.Conditionals;
1316                 }
1317
1318                 public ObsoleteAttribute GetAttributeObsolete ()
1319                 {
1320                         if (cattrs == null)
1321                                 ReadAttributes ();
1322
1323                         return cattrs.Obsolete;
1324                 }
1325
1326                 public bool IsNotCLSCompliant ()
1327                 {
1328                         if (cattrs == null)
1329                                 ReadAttributes ();
1330
1331                         return cattrs.IsNotCLSCompliant;
1332                 }
1333
1334                 protected void ReadAttributes ()
1335                 {
1336                         cattrs = AttributesBag.Read (provider, importer);
1337                 }
1338
1339                 public void SetIsAssigned ()
1340                 {
1341                         // Unused for imported members
1342                 }
1343
1344                 public void SetIsUsed ()
1345                 {
1346                         // Unused for imported members
1347                 }
1348         }
1349
1350         public class ImportedModuleDefinition
1351         {
1352                 readonly Module module;
1353                 bool cls_compliant;
1354                 readonly MetadataImporter importer;
1355                 
1356                 public ImportedModuleDefinition (Module module, MetadataImporter importer)
1357                 {
1358                         this.module = module;
1359                         this.importer = importer;
1360                 }
1361
1362                 #region Properties
1363
1364                 public bool IsCLSCompliant {
1365                         get {
1366                                 return cls_compliant;
1367                         }
1368                 }
1369
1370                 public string Name {
1371                         get {
1372                                 return module.Name;
1373                         }
1374                 }
1375
1376                 #endregion
1377
1378                 public void ReadAttributes ()
1379                 {
1380                         IList<CustomAttributeData> attrs = CustomAttributeData.GetCustomAttributes (module);
1381
1382                         string ns, name;
1383                         foreach (var a in attrs) {
1384                                 importer.GetCustomAttributeTypeName (a, out ns, out name);
1385                                 if (name == "CLSCompliantAttribute") {
1386                                         if (ns != "System")
1387                                                 continue;
1388
1389                                         cls_compliant = (bool) a.ConstructorArguments[0].Value;
1390                                         continue;
1391                                 }
1392                         }
1393                 }
1394
1395                 //
1396                 // Reads assembly attributes which where attached to a special type because
1397                 // module does have assembly manifest
1398                 //
1399                 public List<Attribute> ReadAssemblyAttributes ()
1400                 {
1401                         var t = module.GetType (AssemblyAttributesPlaceholder.GetGeneratedName (Name));
1402                         if (t == null)
1403                                 return null;
1404
1405                         var field = t.GetField (AssemblyAttributesPlaceholder.AssemblyFieldName, BindingFlags.NonPublic | BindingFlags.Static);
1406                         if (field == null)
1407                                 return null;
1408
1409                         // TODO: implement, the idea is to fabricate specil Attribute class and
1410                         // add it to OptAttributes before resolving the source code attributes
1411                         // Need to build module location as well for correct error reporting
1412
1413                         //var assembly_attributes = CustomAttributeData.GetCustomAttributes (field);
1414                         //var attrs = new List<Attribute> (assembly_attributes.Count);
1415                         //foreach (var a in assembly_attributes)
1416                         //{
1417                         //    var type = metaImporter.ImportType (a.Constructor.DeclaringType);
1418                         //    var ctor = metaImporter.CreateMethod (a.Constructor, type);
1419
1420                         //    foreach (var carg in a.ConstructorArguments) {
1421                         //        carg.Value
1422                         //    }
1423
1424                         //    attrs.Add (new Attribute ("assembly", ctor, null, Location.Null, true));
1425                         //}
1426
1427                         return null;
1428                 }
1429         }
1430
1431         public class ImportedAssemblyDefinition : IAssemblyDefinition
1432         {
1433                 readonly Assembly assembly;
1434                 readonly AssemblyName aname;
1435                 readonly MetadataImporter importer;
1436                 bool cls_compliant;
1437                 bool contains_extension_methods;
1438
1439                 List<AssemblyName> internals_visible_to;
1440                 Dictionary<IAssemblyDefinition, AssemblyName> internals_visible_to_cache;
1441
1442                 public ImportedAssemblyDefinition (Assembly assembly, MetadataImporter importer)
1443                 {
1444                         this.assembly = assembly;
1445                         this.aname = assembly.GetName ();
1446                         this.importer = importer;
1447                 }
1448
1449                 #region Properties
1450
1451                 public Assembly Assembly {
1452                         get {
1453                                 return assembly;
1454                         }
1455                 }
1456
1457                 public string FullName {
1458                         get {
1459                                 return aname.FullName;
1460                         }
1461                 }
1462
1463                 public bool HasExtensionMethod {
1464                         get {
1465                                 return contains_extension_methods;
1466                         }
1467                 }
1468
1469                 public bool HasStrongName {
1470                         get {
1471                                 return aname.GetPublicKey ().Length != 0;
1472                         }
1473                 }
1474
1475                 public bool IsMissing {
1476                         get {
1477 #if STATIC
1478                                 return assembly.__IsMissing;
1479 #else
1480                                 return false;
1481 #endif
1482                         }
1483                 }
1484
1485                 public bool IsCLSCompliant {
1486                         get {
1487                                 return cls_compliant;
1488                         }
1489                 }
1490
1491                 public string Location {
1492                         get {
1493                                 return assembly.Location;
1494                         }
1495                 }
1496
1497                 public string Name {
1498                         get {
1499                                 return aname.Name;
1500                         }
1501                 }
1502
1503                 #endregion
1504
1505                 public byte[] GetPublicKeyToken ()
1506                 {
1507                         return aname.GetPublicKeyToken ();
1508                 }
1509
1510                 public AssemblyName GetAssemblyVisibleToName (IAssemblyDefinition assembly)
1511                 {
1512                         return internals_visible_to_cache [assembly];
1513                 }
1514
1515                 public bool IsFriendAssemblyTo (IAssemblyDefinition assembly)
1516                 {
1517                         if (internals_visible_to == null)
1518                                 return false;
1519
1520                         AssemblyName is_visible = null;
1521                         if (internals_visible_to_cache == null) {
1522                                 internals_visible_to_cache = new Dictionary<IAssemblyDefinition, AssemblyName> ();
1523                         } else {
1524                                 if (internals_visible_to_cache.TryGetValue (assembly, out is_visible))
1525                                         return is_visible != null;
1526                         }
1527
1528                         var token = assembly.GetPublicKeyToken ();
1529                         if (token != null && token.Length == 0)
1530                                 token = null;
1531
1532                         foreach (var internals in internals_visible_to) {
1533                                 if (internals.Name != assembly.Name)
1534                                         continue;
1535
1536                                 if (token == null && assembly is AssemblyDefinition) {
1537                                         is_visible = internals;
1538                                         break;
1539                                 }
1540
1541                                 if (!ArrayComparer.IsEqual (token, internals.GetPublicKeyToken ()))
1542                                         continue;
1543
1544                                 is_visible = internals;
1545                                 break;
1546                         }
1547
1548                         internals_visible_to_cache.Add (assembly, is_visible);
1549                         return is_visible != null;
1550                 }
1551
1552                 public void ReadAttributes ()
1553                 {
1554 #if STATIC
1555                         if (assembly.__IsMissing)
1556                                 return;
1557 #endif
1558
1559                         IList<CustomAttributeData> attrs = CustomAttributeData.GetCustomAttributes (assembly);
1560
1561                         string ns, name;
1562                         foreach (var a in attrs) {
1563                                 importer.GetCustomAttributeTypeName (a, out ns, out name);
1564
1565                                 if (name == "CLSCompliantAttribute") {
1566                                         if (ns == "System") {
1567                                                 try {
1568                                                         cls_compliant = (bool) a.ConstructorArguments[0].Value;
1569                                                 } catch {
1570                                                 }
1571                                         }
1572                                         continue;
1573                                 }
1574
1575                                 if (name == "InternalsVisibleToAttribute") {
1576                                         if (ns != MetadataImporter.CompilerServicesNamespace)
1577                                                 continue;
1578
1579                                         string s;
1580                                         try {
1581                                                 s = a.ConstructorArguments[0].Value as string;
1582                                         } catch {
1583                                                 s = null;
1584                                         }
1585
1586                                         if (s == null)
1587                                                 continue;
1588
1589                                         var an = new AssemblyName (s);
1590                                         if (internals_visible_to == null)
1591                                                 internals_visible_to = new List<AssemblyName> ();
1592
1593                                         internals_visible_to.Add (an);
1594                                         continue;
1595                                 }
1596
1597                                 if (name == "ExtensionAttribute") {
1598                                         if (ns == MetadataImporter.CompilerServicesNamespace)
1599                                                 contains_extension_methods = true;
1600
1601                                         continue;
1602                                 }
1603                         }
1604                 }
1605
1606                 public override string ToString ()
1607                 {
1608                         return FullName;
1609                 }
1610         }
1611
1612         class ImportedMemberDefinition : ImportedDefinition
1613         {
1614                 readonly TypeSpec type;
1615
1616                 public ImportedMemberDefinition (MemberInfo member, TypeSpec type, MetadataImporter importer)
1617                         : base (member, importer)
1618                 {
1619                         this.type = type;
1620                 }
1621
1622                 #region Properties
1623
1624                 public TypeSpec MemberType {
1625                         get {
1626                                 return type;
1627                         }
1628                 }
1629
1630                 #endregion
1631         }
1632
1633         class ImportedParameterMemberDefinition : ImportedMemberDefinition, IParametersMember
1634         {
1635                 readonly AParametersCollection parameters;
1636
1637                 public ImportedParameterMemberDefinition (MethodBase provider, TypeSpec type, AParametersCollection parameters, MetadataImporter importer)
1638                         : base (provider, type, importer)
1639                 {
1640                         this.parameters = parameters;
1641                 }
1642
1643                 public ImportedParameterMemberDefinition (PropertyInfo provider, TypeSpec type, AParametersCollection parameters, MetadataImporter importer)
1644                         : base (provider, type, importer)
1645                 {
1646                         this.parameters = parameters;
1647                 }
1648
1649                 #region Properties
1650
1651                 public AParametersCollection Parameters {
1652                         get {
1653                                 return parameters;
1654                         }
1655                 }
1656
1657                 #endregion
1658         }
1659
1660         class ImportedGenericMethodDefinition : ImportedParameterMemberDefinition, IGenericMethodDefinition
1661         {
1662                 readonly TypeParameterSpec[] tparams;
1663
1664                 public ImportedGenericMethodDefinition (MethodInfo provider, TypeSpec type, AParametersCollection parameters, TypeParameterSpec[] tparams, MetadataImporter importer)
1665                         : base (provider, type, parameters, importer)
1666                 {
1667                         this.tparams = tparams;
1668                 }
1669
1670                 #region Properties
1671
1672                 public TypeParameterSpec[] TypeParameters {
1673                         get {
1674                                 return tparams;
1675                         }
1676                 }
1677
1678                 public int TypeParametersCount {
1679                         get {
1680                                 return tparams.Length;
1681                         }
1682                 }
1683
1684                 #endregion
1685         }
1686
1687         class ImportedTypeDefinition : ImportedDefinition, ITypeDefinition
1688         {
1689                 TypeParameterSpec[] tparams;
1690                 string name;
1691
1692                 public ImportedTypeDefinition (MetaType type, MetadataImporter importer)
1693                         : base (type, importer)
1694                 {
1695                 }
1696
1697                 #region Properties
1698
1699                 public IAssemblyDefinition DeclaringAssembly {
1700                         get {
1701                                 return importer.GetAssemblyDefinition (provider.Module.Assembly);
1702                         }
1703                 }
1704
1705                 public override string Name {
1706                         get {
1707                                 if (name == null) {
1708                                         name = base.Name;
1709                                         if (tparams != null) {
1710                                                 int arity_start = name.IndexOf ('`');
1711                                                 if (arity_start > 0)
1712                                                         name = name.Substring (0, arity_start);
1713                                         }
1714                                 }
1715
1716                                 return name;
1717                         }
1718                 }
1719
1720                 public string Namespace {
1721                         get {
1722                                 return ((MetaType) provider).Namespace;
1723                         }
1724                 }
1725
1726                 public int TypeParametersCount {
1727                         get {
1728                                 return tparams == null ? 0 : tparams.Length;
1729                         }
1730                 }
1731
1732                 public TypeParameterSpec[] TypeParameters {
1733                         get {
1734                                 return tparams;
1735                         }
1736                         set {
1737                                 tparams = value;
1738                         }
1739                 }
1740
1741                 #endregion
1742
1743                 public static void Error_MissingDependency (IMemberContext ctx, List<TypeSpec> types, Location loc)
1744                 {
1745                         // 
1746                         // Report details about missing type and most likely cause of the problem.
1747                         // csc reports 1683, 1684 as warnings but we report them only when used
1748                         // or referenced from the user core in which case compilation error has to
1749                         // be reported because compiler cannot continue anyway
1750                         //
1751                         foreach (var t in types) {
1752                                 string name = t.GetSignatureForError ();
1753
1754                                 if (t.MemberDefinition.DeclaringAssembly == ctx.Module.DeclaringAssembly) {
1755                                         ctx.Compiler.Report.Error (1683, loc,
1756                                                 "Reference to type `{0}' claims it is defined in this assembly, but it is not defined in source or any added modules",
1757                                                 name);
1758                                 } else if (t.MemberDefinition.DeclaringAssembly.IsMissing) {
1759                                         ctx.Compiler.Report.Error (12, loc,
1760                                                 "The type `{0}' is defined in an assembly that is not referenced. Consider adding a reference to assembly `{1}'",
1761                                                 name, t.MemberDefinition.DeclaringAssembly.FullName);
1762                                 } else {
1763                                         ctx.Compiler.Report.Error (1684, loc,
1764                                                 "Reference to type `{0}' claims it is defined assembly `{1}', but it could not be found",
1765                                                 name, t.MemberDefinition.DeclaringAssembly.FullName);
1766                                 }
1767                         }
1768                 }
1769
1770                 public TypeSpec GetAttributeCoClass ()
1771                 {
1772                         if (cattrs == null)
1773                                 ReadAttributes ();
1774
1775                         return cattrs.CoClass;
1776                 }
1777
1778                 public string GetAttributeDefaultMember ()
1779                 {
1780                         if (cattrs == null)
1781                                 ReadAttributes ();
1782
1783                         return cattrs.DefaultIndexerName;
1784                 }
1785
1786                 public AttributeUsageAttribute GetAttributeUsage (PredefinedAttribute pa)
1787                 {
1788                         if (cattrs == null)
1789                                 ReadAttributes ();
1790
1791                         return cattrs.AttributeUsage;
1792                 }
1793
1794                 bool ITypeDefinition.IsInternalAsPublic (IAssemblyDefinition assembly)
1795                 {
1796                         var a = importer.GetAssemblyDefinition (provider.Module.Assembly);
1797                         return a == assembly || a.IsFriendAssemblyTo (assembly);
1798                 }
1799
1800                 public void LoadMembers (TypeSpec declaringType, bool onlyTypes, ref MemberCache cache)
1801                 {
1802                         //
1803                         // Not interested in members of nested private types unless the importer needs them
1804                         //
1805                         if (declaringType.IsPrivate && importer.IgnorePrivateMembers) {
1806                                 cache = MemberCache.Empty;
1807                                 return;
1808                         }
1809
1810                         var loading_type = (MetaType) provider;
1811                         const BindingFlags all_members = BindingFlags.DeclaredOnly |
1812                                 BindingFlags.Static | BindingFlags.Instance |
1813                                 BindingFlags.Public | BindingFlags.NonPublic;
1814
1815                         const MethodAttributes explicit_impl = MethodAttributes.NewSlot |
1816                                         MethodAttributes.Virtual | MethodAttributes.HideBySig |
1817                                         MethodAttributes.Final;
1818
1819                         Dictionary<MethodBase, MethodSpec> possible_accessors = null;
1820                         List<EventSpec> imported_events = null;
1821                         EventSpec event_spec;
1822                         MemberSpec imported;
1823                         MethodInfo m;
1824                         MemberInfo[] all;
1825                         try {
1826                                 all = loading_type.GetMembers (all_members);
1827                         } catch (Exception e) {
1828                                 throw new InternalErrorException (e, "Could not import type `{0}' from `{1}'",
1829                                         declaringType.GetSignatureForError (), declaringType.MemberDefinition.DeclaringAssembly.FullName);
1830                         }
1831
1832                         if (cache == null) {
1833                                 cache = new MemberCache (all.Length);
1834
1835                                 //
1836                                 // Do the types first as they can be referenced by the members before
1837                                 // they are found or inflated
1838                                 //
1839                                 foreach (var member in all) {
1840                                         if (member.MemberType != MemberTypes.NestedType)
1841                                                 continue;
1842
1843                                         var t = (MetaType) member;
1844
1845                                         // Ignore compiler generated types, mostly lambda containers
1846                                         if ((t.Attributes & TypeAttributes.VisibilityMask) == TypeAttributes.NestedPrivate)
1847                                                 continue;
1848
1849                                         imported = importer.CreateNestedType (t, declaringType);
1850                                         cache.AddMemberImported (imported);
1851                                 }
1852
1853                                 foreach (var member in all) {
1854                                         if (member.MemberType != MemberTypes.NestedType)
1855                                                 continue;
1856
1857                                         var t = (MetaType) member;
1858
1859                                         if ((t.Attributes & TypeAttributes.VisibilityMask) == TypeAttributes.NestedPrivate)
1860                                                 continue;
1861
1862                                         importer.ImportTypeBase (t);
1863                                 }
1864                         }
1865
1866                         if (!onlyTypes) {
1867                                 //
1868                                 // The logic here requires methods to be returned first which seems to work for both Mono and .NET
1869                                 //
1870                                 foreach (var member in all) {
1871                                         switch (member.MemberType) {
1872                                         case MemberTypes.Constructor:
1873                                         case MemberTypes.Method:
1874                                                 MethodBase mb = (MethodBase) member;
1875                                                 var attrs = mb.Attributes;
1876
1877                                                 if ((attrs & MethodAttributes.MemberAccessMask) == MethodAttributes.Private) {
1878                                                         if (importer.IgnorePrivateMembers)
1879                                                                 continue;
1880
1881                                                         // Ignore explicitly implemented members
1882                                                         if ((attrs & explicit_impl) == explicit_impl)
1883                                                                 continue;
1884
1885                                                         // Ignore compiler generated methods
1886                                                         if (importer.HasAttribute (CustomAttributeData.GetCustomAttributes (mb), "CompilerGeneratedAttribute", MetadataImporter.CompilerServicesNamespace))
1887                                                                 continue;
1888                                                 }
1889
1890                                                 imported = importer.CreateMethod (mb, declaringType);
1891                                                 if (imported.Kind == MemberKind.Method && !imported.IsGeneric) {
1892                                                         if (possible_accessors == null)
1893                                                                 possible_accessors = new Dictionary<MethodBase, MethodSpec> (ReferenceEquality<MethodBase>.Default);
1894
1895                                                         // There are no metadata rules for accessors, we have to consider any method as possible candidate
1896                                                         possible_accessors.Add (mb, (MethodSpec) imported);
1897                                                 }
1898
1899                                                 break;
1900                                         case MemberTypes.Property:
1901                                                 if (possible_accessors == null)
1902                                                         continue;
1903
1904                                                 var p = (PropertyInfo) member;
1905                                                 //
1906                                                 // Links possible accessors with property
1907                                                 //
1908                                                 MethodSpec get, set;
1909                                                 m = p.GetGetMethod (true);
1910                                                 if (m == null || !possible_accessors.TryGetValue (m, out get))
1911                                                         get = null;
1912
1913                                                 m = p.GetSetMethod (true);
1914                                                 if (m == null || !possible_accessors.TryGetValue (m, out set))
1915                                                         set = null;
1916
1917                                                 // No accessors registered (e.g. explicit implementation)
1918                                                 if (get == null && set == null)
1919                                                         continue;
1920
1921                                                 imported = importer.CreateProperty (p, declaringType, get, set);
1922                                                 if (imported == null)
1923                                                         continue;
1924
1925                                                 break;
1926                                         case MemberTypes.Event:
1927                                                 if (possible_accessors == null)
1928                                                         continue;
1929
1930                                                 var e = (EventInfo) member;
1931                                                 //
1932                                                 // Links accessors with event
1933                                                 //
1934                                                 MethodSpec add, remove;
1935                                                 m = e.GetAddMethod (true);
1936                                                 if (m == null || !possible_accessors.TryGetValue (m, out add))
1937                                                         add = null;
1938
1939                                                 m = e.GetRemoveMethod (true);
1940                                                 if (m == null || !possible_accessors.TryGetValue (m, out remove))
1941                                                         remove = null;
1942
1943                                                 // Both accessors are required
1944                                                 if (add == null || remove == null)
1945                                                         continue;
1946
1947                                                 event_spec = importer.CreateEvent (e, declaringType, add, remove);
1948                                                 if (!importer.IgnorePrivateMembers) {
1949                                                         if (imported_events == null)
1950                                                                 imported_events = new List<EventSpec> ();
1951
1952                                                         imported_events.Add (event_spec);
1953                                                 }
1954
1955                                                 imported = event_spec;
1956                                                 break;
1957                                         case MemberTypes.Field:
1958                                                 var fi = (FieldInfo) member;
1959
1960                                                 imported = importer.CreateField (fi, declaringType);
1961                                                 if (imported == null)
1962                                                         continue;
1963
1964                                                 //
1965                                                 // For dynamic binder event has to be fully restored to allow operations
1966                                                 // within the type container to work correctly
1967                                                 //
1968                                                 if (imported_events != null) {
1969                                                         // The backing event field should be private but it may not
1970                                                         int index = imported_events.FindIndex (l => l.Name == fi.Name);
1971                                                         if (index >= 0) {
1972                                                                 event_spec = imported_events[index];
1973                                                                 event_spec.BackingField = (FieldSpec) imported;
1974                                                                 imported_events.RemoveAt (index);
1975                                                                 continue;
1976                                                         }
1977                                                 }
1978
1979                                                 break;
1980                                         case MemberTypes.NestedType:
1981                                                 // Already in the cache from the first pass
1982                                                 continue;
1983                                         default:
1984                                                 throw new NotImplementedException (member.ToString ());
1985                                         }
1986
1987                                         cache.AddMemberImported (imported);
1988                                 }
1989                         }
1990
1991                         if (declaringType.IsInterface && declaringType.Interfaces != null) {
1992                                 foreach (var iface in declaringType.Interfaces) {
1993                                         cache.AddInterface (iface);
1994                                 }
1995                         }
1996                 }
1997         }
1998
1999         class ImportedTypeParameterDefinition : ImportedDefinition, ITypeDefinition
2000         {
2001                 public ImportedTypeParameterDefinition (MetaType type, MetadataImporter importer)
2002                         : base (type, importer)
2003                 {
2004                 }
2005
2006                 #region Properties
2007
2008                 public IAssemblyDefinition DeclaringAssembly {
2009                         get {
2010                                 throw new NotImplementedException ();
2011                         }
2012                 }
2013
2014                 public string Namespace {
2015                         get {
2016                                 return null;
2017                         }
2018                 }
2019
2020                 public int TypeParametersCount {
2021                         get {
2022                                 return 0;
2023                         }
2024                 }
2025
2026                 public TypeParameterSpec[] TypeParameters {
2027                         get {
2028                                 return null;
2029                         }
2030                 }
2031
2032                 #endregion
2033
2034                 public TypeSpec GetAttributeCoClass ()
2035                 {
2036                         return null;
2037                 }
2038
2039                 public string GetAttributeDefaultMember ()
2040                 {
2041                         throw new NotSupportedException ();
2042                 }
2043
2044                 public AttributeUsageAttribute GetAttributeUsage (PredefinedAttribute pa)
2045                 {
2046                         throw new NotSupportedException ();
2047                 }
2048
2049                 bool ITypeDefinition.IsInternalAsPublic (IAssemblyDefinition assembly)
2050                 {
2051                         throw new NotImplementedException ();
2052                 }
2053
2054                 public void LoadMembers (TypeSpec declaringType, bool onlyTypes, ref MemberCache cache)
2055                 {
2056                         throw new NotImplementedException ();
2057                 }
2058         }
2059 }