예제 #1
0
 private static string NormalizedFullName(Type type)
 {
     if (ReflectionImporter.IsNestedType(type))
     {
         return(ReflectionImporter.NormalizedFullName(type.DeclaringType) + "/" + type.Name);
     }
     return(type.FullName);
 }
예제 #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);
        }
예제 #3
0
 private static TypeReference ImportGenericParameter(Type type, ImportGenericContext context)
 {
     if (context.IsEmpty)
     {
         throw new InvalidOperationException();
     }
     if (type.DeclaringMethod != null)
     {
         return(context.MethodParameter(type.DeclaringMethod.Name, type.GenericParameterPosition));
     }
     if (type.DeclaringType != null)
     {
         return(context.TypeParameter(ReflectionImporter.NormalizedFullName(type.DeclaringType), type.GenericParameterPosition));
     }
     throw new InvalidOperationException();
 }
예제 #4
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);
        }
예제 #5
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)
     {
         return(ReflectionImporter.ImportGenericParameter(type, context));
     }
     throw new NotSupportedException(type.FullName);
 }
예제 #6
0
 private static bool IsTypeSpecification(Type type)
 {
     return(type.HasElementType || ReflectionImporter.IsGenericInstance(type) || type.IsGenericParameter);
 }