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

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

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

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

            return(MetadataImporter.ImportType(type, default(ImportGenericContext)));
        }
Exemple #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));
        }
Exemple #4
0
        public TypeReference Import(TypeReference type)
        {
            CheckType(type);

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

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

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

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

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

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

            return(MetadataImporter.ImportType(
                       type,
                       (IGenericContext)context,
                       context != null
                                        ? ImportGenericKind.Open
                                        : ImportGenericKind.Definition));
        }
Exemple #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));
        }
Exemple #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));
        }
Exemple #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));
        }
        FieldReference Import(FieldReference field, IGenericParameterProvider context)
        {
            CheckField(field);

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

            CheckContext(context, this);

            return(MetadataImporter.ImportField(field, (IGenericContext)context));
        }
        MethodReference Import(MethodReference method, IGenericParameterProvider context)
        {
            CheckMethod(method);

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

            CheckContext(context, this);

            return(MetadataImporter.ImportMethod(method, (IGenericContext)context));
        }
        TypeReference Import(TypeReference type, IGenericParameterProvider context)
        {
            CheckType(type);

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

            CheckContext(context, this);

            return(MetadataImporter.ImportType(type, (IGenericContext)context));
        }
Exemple #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);
        }
Exemple #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));
 }
Exemple #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);
        }
Exemple #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);
        }
Exemple #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));
 }
        public MethodReference Import(SR.MethodBase method)
        {
            CheckMethod(method);

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

            return(MetadataImporter.ImportField(field, null));
        }
        public TypeReference Import(Type type)
        {
            CheckType(type);

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

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

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