~ubuntu-branches/ubuntu/oneiric/monodevelop/oneiric

« back to all changes in this revision

Viewing changes to contrib/Mono.Cecil/Mono.Cecil/Mono.Cecil/Import.cs

  • Committer: Bazaar Package Importer
  • Author(s): Jo Shields
  • Date: 2011-06-27 17:03:13 UTC
  • mto: (1.8.1 upstream)
  • mto: This revision was merged to the branch mainline in revision 54.
  • Revision ID: james.westby@ubuntu.com-20110627170313-6cvz3s19x6e9hqe9
ImportĀ upstreamĀ versionĀ 2.5.92+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//
 
2
// Import.cs
 
3
//
 
4
// Author:
 
5
//   Jb Evain (jbevain@gmail.com)
 
6
//
 
7
// Copyright (c) 2008 - 2010 Jb Evain
 
8
//
 
9
// Permission is hereby granted, free of charge, to any person obtaining
 
10
// a copy of this software and associated documentation files (the
 
11
// "Software"), to deal in the Software without restriction, including
 
12
// without limitation the rights to use, copy, modify, merge, publish,
 
13
// distribute, sublicense, and/or sell copies of the Software, and to
 
14
// permit persons to whom the Software is furnished to do so, subject to
 
15
// the following conditions:
 
16
//
 
17
// The above copyright notice and this permission notice shall be
 
18
// included in all copies or substantial portions of the Software.
 
19
//
 
20
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 
21
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 
22
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 
23
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
 
24
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
 
25
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 
26
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 
27
//
 
28
 
 
29
using System;
 
30
using System.Collections.Generic;
 
31
using SR = System.Reflection;
 
32
 
 
33
using Mono.Cecil.Metadata;
 
34
 
 
35
namespace Mono.Cecil {
 
36
 
 
37
        enum ImportGenericKind {
 
38
                Definition,
 
39
                Open,
 
40
        }
 
41
 
 
42
        class MetadataImporter {
 
43
 
 
44
                readonly ModuleDefinition module;
 
45
 
 
46
                public MetadataImporter (ModuleDefinition module)
 
47
                {
 
48
                        this.module = module;
 
49
                }
 
50
 
 
51
#if !CF
 
52
                static readonly Dictionary<Type, ElementType> type_etype_mapping = new Dictionary<Type, ElementType> (18) {
 
53
                        { typeof (void), ElementType.Void },
 
54
                        { typeof (bool), ElementType.Boolean },
 
55
                        { typeof (char), ElementType.Char },
 
56
                        { typeof (sbyte), ElementType.I1 },
 
57
                        { typeof (byte), ElementType.U1 },
 
58
                        { typeof (short), ElementType.I2 },
 
59
                        { typeof (ushort), ElementType.U2 },
 
60
                        { typeof (int), ElementType.I4 },
 
61
                        { typeof (uint), ElementType.U4 },
 
62
                        { typeof (long), ElementType.I8 },
 
63
                        { typeof (ulong), ElementType.U8 },
 
64
                        { typeof (float), ElementType.R4 },
 
65
                        { typeof (double), ElementType.R8 },
 
66
                        { typeof (string), ElementType.String },
 
67
                        { typeof (TypedReference), ElementType.TypedByRef },
 
68
                        { typeof (IntPtr), ElementType.I },
 
69
                        { typeof (UIntPtr), ElementType.U },
 
70
                        { typeof (object), ElementType.Object },
 
71
                };
 
72
 
 
73
                public TypeReference ImportType (Type type, IGenericContext context)
 
74
                {
 
75
                        return ImportType (type, context, ImportGenericKind.Open);
 
76
                }
 
77
 
 
78
                public TypeReference ImportType (Type type, IGenericContext context, ImportGenericKind import_kind)
 
79
                {
 
80
                        if (IsTypeSpecification (type) || ImportOpenGenericType (type, import_kind))
 
81
                                return ImportTypeSpecification (type, context);
 
82
 
 
83
                        var reference = new TypeReference (
 
84
                                string.Empty,
 
85
                                type.Name,
 
86
                                module,
 
87
                                ImportScope (type.Assembly),
 
88
                                type.IsValueType);
 
89
 
 
90
                        reference.etype = ImportElementType (type);
 
91
 
 
92
                        if (IsNestedType (type))
 
93
                                reference.DeclaringType = ImportType (type.DeclaringType, context, import_kind);
 
94
                        else
 
95
                                reference.Namespace = type.Namespace;
 
96
 
 
97
                        if (type.IsGenericType)
 
98
                                ImportGenericParameters (reference, type.GetGenericArguments ());
 
99
 
 
100
                        return reference;
 
101
                }
 
102
 
 
103
                static bool ImportOpenGenericType (Type type, ImportGenericKind import_kind)
 
104
                {
 
105
                        return type.IsGenericType && type.IsGenericTypeDefinition && import_kind == ImportGenericKind.Open;
 
106
                }
 
107
 
 
108
                static bool ImportOpenGenericMethod (SR.MethodBase method, ImportGenericKind import_kind)
 
109
                {
 
110
                        return method.IsGenericMethod && method.IsGenericMethodDefinition && import_kind == ImportGenericKind.Open;
 
111
                }
 
112
 
 
113
                static bool IsNestedType (Type type)
 
114
                {
 
115
#if !SILVERLIGHT
 
116
                        return type.IsNested;
 
117
#else
 
118
                        return type.DeclaringType != null;
 
119
#endif
 
120
                }
 
121
 
 
122
                TypeReference ImportTypeSpecification (Type type, IGenericContext context)
 
123
                {
 
124
                        if (type.IsByRef)
 
125
                                return new ByReferenceType (ImportType (type.GetElementType (), context));
 
126
 
 
127
                        if (type.IsPointer)
 
128
                                return new PointerType (ImportType (type.GetElementType (), context));
 
129
 
 
130
                        if (type.IsArray)
 
131
                                return new ArrayType (ImportType (type.GetElementType (), context), type.GetArrayRank ());
 
132
 
 
133
                        if (type.IsGenericType)
 
134
                                return ImportGenericInstance (type, context);
 
135
 
 
136
                        if (type.IsGenericParameter)
 
137
                                return ImportGenericParameter (type, context);
 
138
 
 
139
                        throw new NotSupportedException (type.FullName);
 
140
                }
 
141
 
 
142
                static TypeReference ImportGenericParameter (Type type, IGenericContext context)
 
143
                {
 
144
                        if (context == null)
 
145
                                throw new InvalidOperationException ();
 
146
 
 
147
                        var owner = type.DeclaringMethod != null
 
148
                                ? context.Method
 
149
                                : context.Type;
 
150
 
 
151
                        if (owner == null)
 
152
                                throw new InvalidOperationException ();
 
153
 
 
154
                        return owner.GenericParameters [type.GenericParameterPosition];
 
155
                }
 
156
 
 
157
                TypeReference ImportGenericInstance (Type type, IGenericContext context)
 
158
                {
 
159
                        var element_type = ImportType (type.GetGenericTypeDefinition (), context, ImportGenericKind.Definition);
 
160
                        var instance = new GenericInstanceType (element_type);
 
161
                        var arguments = type.GetGenericArguments ();
 
162
                        var instance_arguments = instance.GenericArguments;
 
163
 
 
164
                        for (int i = 0; i < arguments.Length; i++)
 
165
                                instance_arguments.Add (ImportType (arguments [i], context ?? element_type));
 
166
 
 
167
                        return instance;
 
168
                }
 
169
 
 
170
                static bool IsTypeSpecification (Type type)
 
171
                {
 
172
                        return type.HasElementType
 
173
                                || IsGenericInstance (type)
 
174
                                || type.IsGenericParameter;
 
175
                }
 
176
 
 
177
                static bool IsGenericInstance (Type type)
 
178
                {
 
179
                        return type.IsGenericType && !type.IsGenericTypeDefinition;
 
180
                }
 
181
 
 
182
                static ElementType ImportElementType (Type type)
 
183
                {
 
184
                        ElementType etype;
 
185
                        if (!type_etype_mapping.TryGetValue (type, out etype))
 
186
                                return ElementType.None;
 
187
 
 
188
                        return etype;
 
189
                }
 
190
 
 
191
                AssemblyNameReference ImportScope (SR.Assembly assembly)
 
192
                {
 
193
                        AssemblyNameReference scope;
 
194
#if !SILVERLIGHT
 
195
                        var name = assembly.GetName ();
 
196
 
 
197
                        if (TryGetAssemblyNameReference (name, out scope))
 
198
                                return scope;
 
199
 
 
200
                        scope = new AssemblyNameReference (name.Name, name.Version) {
 
201
                                Culture = name.CultureInfo.Name,
 
202
                                PublicKeyToken = name.GetPublicKeyToken (),
 
203
                                HashAlgorithm = (AssemblyHashAlgorithm) name.HashAlgorithm,
 
204
                        };
 
205
 
 
206
                        module.AssemblyReferences.Add (scope);
 
207
 
 
208
                        return scope;
 
209
#else
 
210
                        var name = AssemblyNameReference.Parse (assembly.FullName);
 
211
 
 
212
                        if (TryGetAssemblyNameReference (name, out scope))
 
213
                                return scope;
 
214
 
 
215
                        module.AssemblyReferences.Add (name);
 
216
 
 
217
                        return name;
 
218
#endif
 
219
                }
 
220
 
 
221
#if !SILVERLIGHT
 
222
                bool TryGetAssemblyNameReference (SR.AssemblyName name, out AssemblyNameReference assembly_reference)
 
223
                {
 
224
                        var references = module.AssemblyReferences;
 
225
 
 
226
                        for (int i = 0; i < references.Count; i++) {
 
227
                                var reference = references [i];
 
228
                                if (name.FullName != reference.FullName) // TODO compare field by field
 
229
                                        continue;
 
230
 
 
231
                                assembly_reference = reference;
 
232
                                return true;
 
233
                        }
 
234
 
 
235
                        assembly_reference = null;
 
236
                        return false;
 
237
                }
 
238
#endif
 
239
 
 
240
                public FieldReference ImportField (SR.FieldInfo field, IGenericContext context)
 
241
                {
 
242
                        var declaring_type = ImportType (field.DeclaringType, context);
 
243
 
 
244
                        if (IsGenericInstance (field.DeclaringType))
 
245
                                field = ResolveFieldDefinition (field);
 
246
 
 
247
                        return new FieldReference {
 
248
                                Name = field.Name,
 
249
                                DeclaringType = declaring_type,
 
250
                                FieldType = ImportType (field.FieldType, context ?? declaring_type),
 
251
                        };
 
252
                }
 
253
 
 
254
                static SR.FieldInfo ResolveFieldDefinition (SR.FieldInfo field)
 
255
                {
 
256
#if !SILVERLIGHT
 
257
                        return field.Module.ResolveField (field.MetadataToken);
 
258
#else
 
259
                        return field.DeclaringType.GetGenericTypeDefinition ().GetField (field.Name,
 
260
                                SR.BindingFlags.Public
 
261
                                | SR.BindingFlags.NonPublic
 
262
                                | (field.IsStatic ? SR.BindingFlags.Static : SR.BindingFlags.Instance));
 
263
#endif
 
264
                }
 
265
 
 
266
                public MethodReference ImportMethod (SR.MethodBase method, IGenericContext context, ImportGenericKind import_kind)
 
267
                {
 
268
                        if (IsMethodSpecification (method) || ImportOpenGenericMethod (method, import_kind))
 
269
                                return ImportMethodSpecification (method, context);
 
270
 
 
271
                        var declaring_type = ImportType (method.DeclaringType, context);
 
272
 
 
273
                        if (IsGenericInstance (method.DeclaringType))
 
274
                                method = method.Module.ResolveMethod (method.MetadataToken);
 
275
 
 
276
                        var reference = new MethodReference {
 
277
                                Name = method.Name,
 
278
                                HasThis = HasCallingConvention (method, SR.CallingConventions.HasThis),
 
279
                                ExplicitThis = HasCallingConvention (method, SR.CallingConventions.ExplicitThis),
 
280
                                DeclaringType = ImportType (method.DeclaringType, context, ImportGenericKind.Definition),
 
281
                        };
 
282
 
 
283
                        if (HasCallingConvention (method, SR.CallingConventions.VarArgs))
 
284
                                reference.CallingConvention &= MethodCallingConvention.VarArg;
 
285
 
 
286
                        if (method.IsGenericMethod)
 
287
                                ImportGenericParameters (reference, method.GetGenericArguments ());
 
288
 
 
289
                        var method_info = method as SR.MethodInfo;
 
290
                        reference.ReturnType = method_info != null
 
291
                                ? ImportType (method_info.ReturnType, context ?? reference)
 
292
                                : ImportType (typeof (void), null);
 
293
 
 
294
                        var parameters = method.GetParameters ();
 
295
                        var reference_parameters = reference.Parameters;
 
296
 
 
297
                        for (int i = 0; i < parameters.Length; i++)
 
298
                                reference_parameters.Add (
 
299
                                        new ParameterDefinition (ImportType (parameters [i].ParameterType, context ?? reference)));
 
300
 
 
301
                        reference.DeclaringType = declaring_type;
 
302
 
 
303
                        return reference;
 
304
                }
 
305
 
 
306
                static void ImportGenericParameters (IGenericParameterProvider provider, Type [] arguments)
 
307
                {
 
308
                        var provider_parameters = provider.GenericParameters;
 
309
 
 
310
                        for (int i = 0; i < arguments.Length; i++)
 
311
                                provider_parameters.Add (new GenericParameter (arguments [i].Name, provider));
 
312
                }
 
313
 
 
314
                static bool IsMethodSpecification (SR.MethodBase method)
 
315
                {
 
316
                        return method.IsGenericMethod && !method.IsGenericMethodDefinition;
 
317
                }
 
318
 
 
319
                MethodReference ImportMethodSpecification (SR.MethodBase method, IGenericContext context)
 
320
                {
 
321
                        var method_info = method as SR.MethodInfo;
 
322
                        if (method_info == null)
 
323
                                throw new InvalidOperationException ();
 
324
 
 
325
                        var element_method = ImportMethod (method_info.GetGenericMethodDefinition (), context, ImportGenericKind.Definition);
 
326
                        var instance = new GenericInstanceMethod (element_method);
 
327
                        var arguments = method.GetGenericArguments ();
 
328
                        var instance_arguments = instance.GenericArguments;
 
329
 
 
330
                        for (int i = 0; i < arguments.Length; i++)
 
331
                                instance_arguments.Add (ImportType (arguments [i], context ?? element_method));
 
332
 
 
333
                        return instance;
 
334
                }
 
335
 
 
336
                static bool HasCallingConvention (SR.MethodBase method, SR.CallingConventions conventions)
 
337
                {
 
338
                        return (method.CallingConvention & conventions) != 0;
 
339
                }
 
340
#endif
 
341
 
 
342
                public TypeReference ImportType (TypeReference type, IGenericContext context)
 
343
                {
 
344
                        if (type.IsTypeSpecification ())
 
345
                                return ImportTypeSpecification (type, context);
 
346
 
 
347
                        var reference = new TypeReference (
 
348
                                type.Namespace,
 
349
                                type.Name,
 
350
                                module,
 
351
                                ImportScope (type.Scope),
 
352
                                type.IsValueType);
 
353
 
 
354
                        MetadataSystem.TryProcessPrimitiveType (reference);
 
355
 
 
356
                        if (type.IsNested)
 
357
                                reference.DeclaringType = ImportType (type.DeclaringType, context);
 
358
 
 
359
                        if (type.HasGenericParameters)
 
360
                                ImportGenericParameters (reference, type);
 
361
 
 
362
                        return reference;
 
363
                }
 
364
 
 
365
                IMetadataScope ImportScope (IMetadataScope scope)
 
366
                {
 
367
                        switch (scope.MetadataScopeType) {
 
368
                        case MetadataScopeType.AssemblyNameReference:
 
369
                                return ImportAssemblyName ((AssemblyNameReference) scope);
 
370
                        case MetadataScopeType.ModuleDefinition:
 
371
                                return ImportAssemblyName (((ModuleDefinition) scope).Assembly.Name);
 
372
                        case MetadataScopeType.ModuleReference:
 
373
                                throw new NotImplementedException ();
 
374
                        }
 
375
 
 
376
                        throw new NotSupportedException ();
 
377
                }
 
378
 
 
379
                AssemblyNameReference ImportAssemblyName (AssemblyNameReference name)
 
380
                {
 
381
                        AssemblyNameReference reference;
 
382
                        if (TryGetAssemblyNameReference (name, out reference))
 
383
                                return reference;
 
384
 
 
385
                        reference = new AssemblyNameReference (name.Name, name.Version) {
 
386
                                Culture = name.Culture,
 
387
                                HashAlgorithm = name.HashAlgorithm,
 
388
                        };
 
389
 
 
390
                        var pk_token = !name.PublicKeyToken.IsNullOrEmpty ()
 
391
                                ? new byte [name.PublicKeyToken.Length]
 
392
                                : Empty<byte>.Array;
 
393
 
 
394
                        if (pk_token.Length > 0)
 
395
                                Buffer.BlockCopy (name.PublicKeyToken, 0, pk_token, 0, pk_token.Length);
 
396
 
 
397
                        reference.PublicKeyToken = pk_token;
 
398
 
 
399
                        module.AssemblyReferences.Add (reference);
 
400
 
 
401
                        return reference;
 
402
                }
 
403
 
 
404
                bool TryGetAssemblyNameReference (AssemblyNameReference name_reference, out AssemblyNameReference assembly_reference)
 
405
                {
 
406
                        var references = module.AssemblyReferences;
 
407
 
 
408
                        for (int i = 0; i < references.Count; i++) {
 
409
                                var reference = references [i];
 
410
                                if (name_reference.FullName != reference.FullName) // TODO compare field by field
 
411
                                        continue;
 
412
 
 
413
                                assembly_reference = reference;
 
414
                                return true;
 
415
                        }
 
416
 
 
417
                        assembly_reference = null;
 
418
                        return false;
 
419
                }
 
420
 
 
421
                static void ImportGenericParameters (IGenericParameterProvider imported, IGenericParameterProvider original)
 
422
                {
 
423
                        var parameters = original.GenericParameters;
 
424
                        var imported_parameters = imported.GenericParameters;
 
425
 
 
426
                        for (int i = 0; i < parameters.Count; i++)
 
427
                                imported_parameters.Add (new GenericParameter (parameters [i].Name, imported));
 
428
                }
 
429
 
 
430
                TypeReference ImportTypeSpecification (TypeReference type, IGenericContext context)
 
431
                {
 
432
                        switch (type.etype) {
 
433
                        case ElementType.SzArray:
 
434
                                var vector = (ArrayType) type;
 
435
                                return new ArrayType (ImportType (vector.ElementType, context));
 
436
                        case ElementType.Ptr:
 
437
                                var pointer = (PointerType) type;
 
438
                                return new PointerType (ImportType (pointer.ElementType, context));
 
439
                        case ElementType.ByRef:
 
440
                                var byref = (ByReferenceType) type;
 
441
                                return new ByReferenceType (ImportType (byref.ElementType, context));
 
442
                        case ElementType.Pinned:
 
443
                                var pinned = (PinnedType) type;
 
444
                                return new PinnedType (ImportType (pinned.ElementType, context));
 
445
                        case ElementType.Sentinel:
 
446
                                var sentinel = (SentinelType) type;
 
447
                                return new SentinelType (ImportType (sentinel.ElementType, context));
 
448
                        case ElementType.CModOpt:
 
449
                                var modopt = (OptionalModifierType) type;
 
450
                                return new OptionalModifierType (
 
451
                                        ImportType (modopt.ModifierType, context),
 
452
                                        ImportType (modopt.ElementType, context));
 
453
                        case ElementType.CModReqD:
 
454
                                var modreq = (RequiredModifierType) type;
 
455
                                return new RequiredModifierType (
 
456
                                        ImportType (modreq.ModifierType, context),
 
457
                                        ImportType (modreq.ElementType, context));
 
458
                        case ElementType.Array:
 
459
                                var array = (ArrayType) type;
 
460
                                var imported_array = new ArrayType (ImportType (array.ElementType, context));
 
461
                                if (array.IsVector)
 
462
                                        return imported_array;
 
463
 
 
464
                                var dimensions = array.Dimensions;
 
465
                                var imported_dimensions = imported_array.Dimensions;
 
466
 
 
467
                                imported_dimensions.Clear ();
 
468
 
 
469
                                for (int i = 0; i < dimensions.Count; i++) {
 
470
                                        var dimension = dimensions [i];
 
471
 
 
472
                                        imported_dimensions.Add (new ArrayDimension (dimension.LowerBound, dimension.UpperBound));
 
473
                                }
 
474
 
 
475
                                return imported_array;
 
476
                        case ElementType.GenericInst:
 
477
                                var instance = (GenericInstanceType) type;
 
478
                                var element_type = ImportType (instance.ElementType, context);
 
479
                                var imported_instance = new GenericInstanceType (element_type);
 
480
 
 
481
                                var arguments = instance.GenericArguments;
 
482
                                var imported_arguments = imported_instance.GenericArguments;
 
483
 
 
484
                                for (int i = 0; i < arguments.Count; i++)
 
485
                                        imported_arguments.Add (ImportType (arguments [i], context));
 
486
 
 
487
                                return imported_instance;
 
488
                        case ElementType.Var:
 
489
                                if (context == null || context.Type == null)
 
490
                                        throw new InvalidOperationException ();
 
491
 
 
492
                                return ((TypeReference) context.Type).GetElementType ().GenericParameters [((GenericParameter) type).Position];
 
493
                        case ElementType.MVar:
 
494
                                if (context == null || context.Method == null)
 
495
                                        throw new InvalidOperationException ();
 
496
 
 
497
                                return context.Method.GenericParameters [((GenericParameter) type).Position];
 
498
                        }
 
499
 
 
500
                        throw new NotSupportedException (type.etype.ToString ());
 
501
                }
 
502
 
 
503
                public FieldReference ImportField (FieldReference field, IGenericContext context)
 
504
                {
 
505
                        var declaring_type = ImportType (field.DeclaringType, context);
 
506
 
 
507
                        return new FieldReference {
 
508
                                Name = field.Name,
 
509
                                DeclaringType = declaring_type,
 
510
                                FieldType = ImportType (field.FieldType, context ?? declaring_type),
 
511
                        };
 
512
                }
 
513
 
 
514
                public MethodReference ImportMethod (MethodReference method, IGenericContext context)
 
515
                {
 
516
                        if (method.IsGenericInstance)
 
517
                                return ImportMethodSpecification (method, context);
 
518
 
 
519
                        var declaring_type = ImportType (method.DeclaringType, context);
 
520
 
 
521
                        var reference = new MethodReference {
 
522
                                Name = method.Name,
 
523
                                HasThis = method.HasThis,
 
524
                                ExplicitThis = method.ExplicitThis,
 
525
                                DeclaringType = declaring_type,
 
526
                        };
 
527
 
 
528
                        reference.CallingConvention = method.CallingConvention;
 
529
 
 
530
                        if (method.HasGenericParameters)
 
531
                                ImportGenericParameters (reference, method);
 
532
 
 
533
                        reference.ReturnType = ImportType (method.ReturnType, context ?? reference);
 
534
 
 
535
                        if (!method.HasParameters)
 
536
                                return reference;
 
537
 
 
538
                        var reference_parameters = reference.Parameters;
 
539
 
 
540
                        var parameters = method.Parameters;
 
541
                        for (int i = 0; i < parameters.Count; i++)
 
542
                                reference_parameters.Add (
 
543
                                        new ParameterDefinition (ImportType (parameters [i].ParameterType, context ?? reference)));
 
544
 
 
545
                        return reference;
 
546
                }
 
547
 
 
548
                MethodSpecification ImportMethodSpecification (MethodReference method, IGenericContext context)
 
549
                {
 
550
                        if (!method.IsGenericInstance)
 
551
                                throw new NotSupportedException ();
 
552
 
 
553
                        var instance = (GenericInstanceMethod) method;
 
554
                        var element_method = ImportMethod (instance.ElementMethod, context);
 
555
                        var imported_instance = new GenericInstanceMethod (element_method);
 
556
 
 
557
                        var arguments = instance.GenericArguments;
 
558
                        var imported_arguments = imported_instance.GenericArguments;
 
559
 
 
560
                        for (int i = 0; i < arguments.Count; i++)
 
561
                                imported_arguments.Add (ImportType (arguments [i], context));
 
562
 
 
563
                        return imported_instance;
 
564
                }
 
565
        }
 
566
}