예제 #1
0
        public MethodReference Import(MethodReference method)
        {
            CheckMethod(method);

            if (method.Module == this)
            {
                return(method);
            }

            return(MetadataImporter.ImportMethod(method, null));
        }
예제 #2
0
        public TypeReference Import(TypeReference type)
        {
            CheckType(type);

            if (type.Module == this)
            {
                return(type);
            }

            return(MetadataImporter.ImportType(type, default(ImportGenericContext)));
        }
예제 #3
0
        public MethodReference Import(SR.MethodBase method, IGenericParameterProvider context)
        {
            CheckMethod(method);
            CheckContext(context, this);

            return(MetadataImporter.ImportMethod(method,
                                                 GetContext(context),
                                                 context != null
                                        ? ImportGenericKind.Open
                                        : ImportGenericKind.Definition));
        }
예제 #4
0
        public TypeReference Import(TypeReference type)
        {
            CheckType(type);

            if (type.Module == this)
            {
                return(type);
            }

            return(MetadataImporter.ImportType(type, null));
        }
예제 #5
0
        public FieldReference Import(FieldReference field)
        {
            CheckField(field);

            if (field.Module == this)
            {
                return(field);
            }

            return(MetadataImporter.ImportField(field, default(ImportGenericContext)));
        }
예제 #6
0
        public FieldReference Import(FieldReference field)
        {
            CheckField(field);

            if (field.Module == this)
            {
                return(field);
            }

            return(MetadataImporter.ImportField(field, null));
        }
예제 #7
0
        TypeReference Import(Type type, IGenericParameterProvider context)
        {
            CheckType(type);
            CheckContext(context, this);

            return(MetadataImporter.ImportType(
                       type,
                       (IGenericContext)context,
                       context != null
                                        ? ImportGenericKind.Open
                                        : ImportGenericKind.Definition));
        }
예제 #8
0
        public FieldReference ImportReference(FieldReference field, IGenericParameterProvider context)
        {
            Mixin.CheckField(field);

            if (field.Module == this)
            {
                return(field);
            }

            CheckContext(context, this);

            return(MetadataImporter.ImportReference(field, context));
        }
예제 #9
0
        public MethodReference ImportReference(MethodReference method, IGenericParameterProvider context)
        {
            Mixin.CheckMethod(method);

            if (method.Module == this)
            {
                return(method);
            }

            CheckContext(context, this);

            return(MetadataImporter.ImportReference(method, context));
        }
예제 #10
0
        public TypeReference ImportReference(TypeReference type, IGenericParameterProvider context)
        {
            Mixin.CheckType(type);

            if (type.Module == this)
            {
                return(type);
            }

            CheckContext(context, this);

            return(MetadataImporter.ImportReference(type, context));
        }
예제 #11
0
        FieldReference Import(FieldReference field, IGenericParameterProvider context)
        {
            CheckField(field);

            if (field.Module == this)
            {
                return(field);
            }

            CheckContext(context, this);

            return(MetadataImporter.ImportField(field, (IGenericContext)context));
        }
예제 #12
0
        MethodReference Import(MethodReference method, IGenericParameterProvider context)
        {
            CheckMethod(method);

            if (method.Module == this)
            {
                return(method);
            }

            CheckContext(context, this);

            return(MetadataImporter.ImportMethod(method, (IGenericContext)context));
        }
예제 #13
0
        TypeReference Import(TypeReference type, IGenericParameterProvider context)
        {
            CheckType(type);

            if (type.Module == this)
            {
                return(type);
            }

            CheckContext(context, this);

            return(MetadataImporter.ImportType(type, (IGenericContext)context));
        }
예제 #14
0
        public MethodReference ImportMethod(MethodBase method, ImportGenericContext context, ImportGenericKind import_kind)
        {
            MethodReference methodReference;

            if (MetadataImporter.IsMethodSpecification(method) || MetadataImporter.ImportOpenGenericMethod(method, import_kind))
            {
                return(this.ImportMethodSpecification(method, context));
            }
            TypeReference typeReference = this.ImportType(method.DeclaringType, context);

            if (MetadataImporter.IsGenericInstance(method.DeclaringType))
            {
                method = method.Module.ResolveMethod(method.MetadataToken);
            }
            MethodReference methodReference1 = new MethodReference()
            {
                Name          = method.Name,
                HasThis       = MetadataImporter.HasCallingConvention(method, CallingConventions.HasThis),
                ExplicitThis  = MetadataImporter.HasCallingConvention(method, CallingConventions.ExplicitThis),
                DeclaringType = this.ImportType(method.DeclaringType, context, ImportGenericKind.Definition)
            };

            if (MetadataImporter.HasCallingConvention(method, CallingConventions.VarArgs))
            {
                MethodReference callingConvention = methodReference1;
                callingConvention.CallingConvention = callingConvention.CallingConvention & MethodCallingConvention.VarArg;
            }
            if (method.IsGenericMethod)
            {
                MetadataImporter.ImportGenericParameters(methodReference1, method.GetGenericArguments());
            }
            context.Push(methodReference1);
            try
            {
                MethodInfo methodInfo = method as MethodInfo;
                methodReference1.ReturnType = (methodInfo != null ? this.ImportType(methodInfo.ReturnType, context) : this.ImportType(typeof(void), new ImportGenericContext()));
                ParameterInfo[] parameters = method.GetParameters();
                Collection <ParameterDefinition> parameterDefinitions = methodReference1.Parameters;
                for (int i = 0; i < (int)parameters.Length; i++)
                {
                    parameterDefinitions.Add(new ParameterDefinition(this.ImportType(parameters[i].ParameterType, context)));
                }
                methodReference1.DeclaringType = typeReference;
                methodReference = methodReference1;
            }
            finally
            {
                context.Pop();
            }
            return(methodReference);
        }
예제 #15
0
 private static TypeReference ImportGenericParameter(Type type, ImportGenericContext context)
 {
     if (context.IsEmpty)
     {
         throw new InvalidOperationException();
     }
     if (type.DeclaringMethod != null)
     {
         return(context.MethodParameter(MetadataImporter.NormalizeMethodName(type.DeclaringMethod), type.GenericParameterPosition));
     }
     if (type.DeclaringType == null)
     {
         throw new InvalidOperationException();
     }
     return(context.TypeParameter(MetadataImporter.NormalizeTypeFullName(type.DeclaringType), type.GenericParameterPosition));
 }
예제 #16
0
        public MethodReference ImportMethod(MethodReference method, ImportGenericContext context)
        {
            MethodReference methodReference;

            if (method.IsGenericInstance)
            {
                return(this.ImportMethodSpecification(method, context));
            }
            TypeReference   typeReference    = this.ImportType(method.DeclaringType, context);
            MethodReference methodReference1 = new MethodReference()
            {
                Name              = method.Name,
                HasThis           = method.HasThis,
                ExplicitThis      = method.ExplicitThis,
                DeclaringType     = typeReference,
                CallingConvention = method.CallingConvention
            };

            if (method.HasGenericParameters)
            {
                MetadataImporter.ImportGenericParameters(methodReference1, method);
            }
            context.Push(methodReference1);
            try
            {
                methodReference1.ReturnType = this.ImportType(method.ReturnType, context);
                if (method.HasParameters)
                {
                    Collection <ParameterDefinition> parameters           = methodReference1.Parameters;
                    Collection <ParameterDefinition> parameterDefinitions = method.Parameters;
                    for (int i = 0; i < parameterDefinitions.Count; i++)
                    {
                        parameters.Add(new ParameterDefinition(this.ImportType(parameterDefinitions[i].ParameterType, context)));
                    }
                    methodReference = methodReference1;
                }
                else
                {
                    methodReference = methodReference1;
                }
            }
            finally
            {
                context.Pop();
            }
            return(methodReference);
        }
예제 #17
0
        public TypeReference ImportType(TypeReference type, ImportGenericContext context)
        {
            if (type.IsTypeSpecification())
            {
                return(this.ImportTypeSpecification(type, context));
            }
            TypeReference typeReference = new TypeReference(type.Namespace, type.Name, this.module, this.ImportScope(type.Scope), type.IsValueType);

            MetadataSystem.TryProcessPrimitiveTypeReference(typeReference);
            if (type.IsNested)
            {
                typeReference.DeclaringType = this.ImportType(type.DeclaringType, context);
            }
            if (type.HasGenericParameters)
            {
                MetadataImporter.ImportGenericParameters(typeReference, type);
            }
            return(typeReference);
        }
예제 #18
0
 private TypeReference ImportTypeSpecification(Type type, ImportGenericContext context)
 {
     if (type.IsByRef)
     {
         return(new ByReferenceType(this.ImportType(type.GetElementType(), context)));
     }
     if (type.IsPointer)
     {
         return(new PointerType(this.ImportType(type.GetElementType(), context)));
     }
     if (type.IsArray)
     {
         return(new ArrayType(this.ImportType(type.GetElementType(), context), type.GetArrayRank()));
     }
     if (type.IsGenericType)
     {
         return(this.ImportGenericInstance(type, context));
     }
     if (!type.IsGenericParameter)
     {
         throw new NotSupportedException(type.FullName);
     }
     return(MetadataImporter.ImportGenericParameter(type, context));
 }
예제 #19
0
        public MethodReference Import(SR.MethodBase method)
        {
            CheckMethod(method);

            return(MetadataImporter.ImportMethod(method, null, ImportGenericKind.Definition));
        }
예제 #20
0
        public FieldReference Import(SR.FieldInfo field)
        {
            CheckField(field);

            return(MetadataImporter.ImportField(field, null));
        }
예제 #21
0
        public TypeReference Import(Type type)
        {
            CheckType(type);

            return(MetadataImporter.ImportType(type, null, ImportGenericKind.Definition));
        }
예제 #22
0
        public MethodReference Import(SR.MethodBase method)
        {
            CheckMethod(method);

            return(MetadataImporter.ImportMethod(method, default(ImportGenericContext), ImportGenericKind.Definition));
        }
예제 #23
0
 private static string NormalizeMethodName(MethodBase method)
 {
     return(string.Concat(MetadataImporter.NormalizeTypeFullName(method.DeclaringType), ".", method.Name));
 }
예제 #24
0
        public MethodReference Import(SR.MethodBase method)
        {
            CheckMethod(method);

            return(MetadataImporter.ImportMethod(method, null));
        }