Ejemplo n.º 1
0
        private TypeReference ImportType(Type type, ImportGenericContext context, ReflectionImporter.ImportGenericKind import_kind)
        {
            if (ReflectionImporter.IsTypeSpecification(type) || ReflectionImporter.ImportOpenGenericType(type, import_kind))
            {
                return(this.ImportTypeSpecification(type, context));
            }
            TypeReference typeReference = new TypeReference(string.Empty, type.Name, this.module, this.ImportScope(type.Assembly), type.IsValueType);

            typeReference.etype = ReflectionImporter.ImportElementType(type);
            if (ReflectionImporter.IsNestedType(type))
            {
                typeReference.DeclaringType = this.ImportType(type.DeclaringType, context, import_kind);
            }
            else
            {
                typeReference.Namespace = (type.Namespace ?? string.Empty);
            }
            if (type.IsGenericType)
            {
                ReflectionImporter.ImportGenericParameters(typeReference, type.GetGenericArguments());
            }
            return(typeReference);
        }
Ejemplo n.º 2
0
        private MethodReference ImportMethod(MethodBase method, ImportGenericContext context, ReflectionImporter.ImportGenericKind import_kind)
        {
            if (ReflectionImporter.IsMethodSpecification(method) || ReflectionImporter.ImportOpenGenericMethod(method, import_kind))
            {
                return(this.ImportMethodSpecification(method, context));
            }
            TypeReference declaringType = this.ImportType(method.DeclaringType, context);

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

            if (ReflectionImporter.HasCallingConvention(method, CallingConventions.VarArgs))
            {
                MethodReference expr_9C = methodReference;
                expr_9C.CallingConvention &= MethodCallingConvention.VarArg;
            }
            if (method.IsGenericMethod)
            {
                ReflectionImporter.ImportGenericParameters(methodReference, method.GetGenericArguments());
            }
            context.Push(methodReference);
            MethodReference result;

            try
            {
                MethodInfo methodInfo = method as MethodInfo;
                methodReference.ReturnType = ((methodInfo != null) ? this.ImportType(methodInfo.ReturnType, context) : this.ImportType(typeof(void), default(ImportGenericContext)));
                ParameterInfo[] parameters = method.GetParameters();
                Collection <ParameterDefinition> parameters2 = methodReference.Parameters;
                for (int i = 0; i < parameters.Length; i++)
                {
                    parameters2.Add(new ParameterDefinition(this.ImportType(parameters[i].ParameterType, context)));
                }
                methodReference.DeclaringType = declaringType;
                result = methodReference;
            }
            finally
            {
                context.Pop();
            }
            return(result);
        }
Ejemplo n.º 3
0
 private static bool ImportOpenGenericMethod(MethodBase method, ReflectionImporter.ImportGenericKind import_kind)
 {
     return(method.IsGenericMethod && method.IsGenericMethodDefinition && import_kind == ReflectionImporter.ImportGenericKind.Open);
 }
Ejemplo n.º 4
0
 private static bool ImportOpenGenericType(Type type, ReflectionImporter.ImportGenericKind import_kind)
 {
     return(type.IsGenericType && type.IsGenericTypeDefinition && import_kind == ReflectionImporter.ImportGenericKind.Open);
 }