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