Exemplo n.º 1
0
        MethodReference ImportMethodSpecification(SR.MethodBase method, ImportGenericContext context)
        {
            var method_info = method as SR.MethodInfo;

            if (method_info == null)
            {
                throw new InvalidOperationException();
            }

            var element_method     = ImportMethod(method_info.GetGenericMethodDefinition(), context, ImportGenericKind.Definition);
            var instance           = new GenericInstanceMethod(element_method);
            var arguments          = method.GetGenericArguments();
            var instance_arguments = instance.GenericArguments;

            context.Push(element_method);
            try {
                for (int i = 0; i < arguments.Length; i++)
                {
                    instance_arguments.Add(ImportType(arguments [i], context));
                }

                return(instance);
            } finally {
                context.Pop();
            }
        }
Exemplo n.º 2
0
        MethodReference ImportMethod(SR.MethodBase method, ImportGenericContext context, ImportGenericKind import_kind)
        {
            if (IsMethodSpecification(method) || ImportOpenGenericMethod(method, import_kind))
            {
                return(ImportMethodSpecification(method, context));
            }

            var declaring_type = ImportType(method.DeclaringType, context);

            if (IsGenericInstance(method.DeclaringType))
            {
                method = ResolveMethodDefinition(method);
            }

            var reference = new MethodReference {
                Name          = method.Name,
                HasThis       = HasCallingConvention(method, SR.CallingConventions.HasThis),
                ExplicitThis  = HasCallingConvention(method, SR.CallingConventions.ExplicitThis),
                DeclaringType = ImportType(method.DeclaringType, context, ImportGenericKind.Definition),
            };

            if (HasCallingConvention(method, SR.CallingConventions.VarArgs))
            {
                reference.CallingConvention &= MethodCallingConvention.VarArg;
            }

            if (method.IsGenericMethod)
            {
                ImportGenericParameters(reference, method.GetGenericArguments());
            }

            context.Push(reference);
            try {
                var method_info = method as SR.MethodInfo;
                reference.ReturnType = method_info != null
                                        ? ImportType(method_info.ReturnType, context)
                                        : ImportType(typeof(void), default(ImportGenericContext));

                var parameters           = method.GetParameters();
                var reference_parameters = reference.Parameters;

                for (int i = 0; i < parameters.Length; i++)
                {
                    reference_parameters.Add(
                        new ParameterDefinition(ImportType(parameters [i].ParameterType, context)));
                }

                reference.DeclaringType = declaring_type;

                return(reference);
            } finally {
                context.Pop();
            }
        }
Exemplo n.º 3
0
        FieldReference ImportField(FieldReference field, ImportGenericContext context)
        {
            var declaring_type = ImportType(field.DeclaringType, context);

            context.Push(declaring_type);
            try {
                return(new FieldReference {
                    Name = field.Name,
                    DeclaringType = declaring_type,
                    FieldType = ImportType(field.FieldType, context),
                });
            } finally {
                context.Pop();
            }
        }
Exemplo n.º 4
0
        MethodReference ImportMethod(MethodReference method, ImportGenericContext context)
        {
            if (method.IsGenericInstance)
            {
                return(ImportMethodSpecification(method, context));
            }

            var declaring_type = ImportType(method.DeclaringType, context);

            var reference = new MethodReference {
                Name              = method.Name,
                HasThis           = method.HasThis,
                ExplicitThis      = method.ExplicitThis,
                DeclaringType     = declaring_type,
                CallingConvention = method.CallingConvention,
            };

            if (method.HasGenericParameters)
            {
                ImportGenericParameters(reference, method);
            }

            context.Push(reference);
            try {
                reference.ReturnType = ImportType(method.ReturnType, context);

                if (!method.HasParameters)
                {
                    return(reference);
                }

                var parameters           = method.Parameters;
                var reference_parameters = reference.parameters = new ParameterDefinitionCollection(reference, parameters.Count);
                for (int i = 0; i < parameters.Count; i++)
                {
                    reference_parameters.Add(
                        new ParameterDefinition(ImportType(parameters [i].ParameterType, context)));
                }

                return(reference);
            } finally {
                context.Pop();
            }
        }
Exemplo n.º 5
0
        TypeReference ImportGenericInstance(Type type, ImportGenericContext context)
        {
            var element_type       = ImportType(type.GetGenericTypeDefinition(), context, ImportGenericKind.Definition);
            var instance           = new GenericInstanceType(element_type);
            var arguments          = type.GetGenericArguments();
            var instance_arguments = instance.GenericArguments;

            context.Push(element_type);
            try {
                for (int i = 0; i < arguments.Length; i++)
                {
                    instance_arguments.Add(ImportType(arguments [i], context));
                }

                return(instance);
            } finally {
                context.Pop();
            }
        }
Exemplo n.º 6
0
        FieldReference ImportField(SR.FieldInfo field, ImportGenericContext context)
        {
            var declaring_type = ImportType(field.DeclaringType, context);

            if (IsGenericInstance(field.DeclaringType))
            {
                field = ResolveFieldDefinition(field);
            }

            context.Push(declaring_type);
            try {
                return(new FieldReference {
                    Name = field.Name,
                    DeclaringType = declaring_type,
                    FieldType = ImportType(field.FieldType, context),
                });
            } finally {
                context.Pop();
            }
        }