Esempio n. 1
0
        protected TypeSpecification GetTypeSpec(TypeSpecification original, ImportContext context)
        {
            TypeSpecification typeSpec;

            TypeReference elementType = ImportTypeReference (original.ElementType, context);
            if (original is PointerType) {
                typeSpec = new PointerType (elementType);
            } else if (original is ArrayType) { // deal with complex arrays
                typeSpec = new ArrayType (elementType);
            } else if (original is ReferenceType) {
                typeSpec = new ReferenceType (elementType);
            } else if (original is GenericInstanceType) {
                GenericInstanceType git = original as GenericInstanceType;
                GenericInstanceType genElemType = new GenericInstanceType (elementType);

                context.GenericContext.CheckProvider (genElemType.GetOriginalType (), git.GenericArguments.Count);

                foreach (GenericParameter genericParameter in git.GenericParameters)
                    genElemType.GenericParameters.Add(GetGenericParameter(genericParameter, context));
                foreach (TypeReference arg in git.GenericArguments)
                    genElemType.GenericArguments.Add (ImportTypeReference (arg, context));

                typeSpec = genElemType;
            } else if (original is ModifierOptional) {
                TypeReference mt = (original as ModifierOptional).ModifierType;
                typeSpec = new ModifierOptional (elementType, ImportTypeReference (mt, context));
            } else if (original is ModifierRequired) {
                TypeReference mt = (original as ModifierRequired).ModifierType;
                typeSpec = new ModifierRequired (elementType, ImportTypeReference (mt, context));
            } else if (original is SentinelType) {
                typeSpec = new SentinelType (elementType);
            } else if (original is FunctionPointerType) {
                FunctionPointerType ori = original as FunctionPointerType;

                FunctionPointerType fnptr = new FunctionPointerType (
                    ori.HasThis,
                    ori.ExplicitThis,
                    ori.CallingConvention,
                    new MethodReturnType (ImportTypeReference (ori.ReturnType.ReturnType, context)));

                foreach (ParameterDefinition parameter in ori.Parameters)
                    fnptr.Parameters.Add (new ParameterDefinition (ImportTypeReference (parameter.ParameterType, context)));

                typeSpec = fnptr;
            } else
                throw new ReflectionException ("Unknown element type: {0}", original.GetType ().Name);

            return typeSpec;
        }
Esempio n. 2
0
        TypeSpecification GetTypeSpec(TypeSpecification original, ImportContext context)
        {
            TypeSpecification typeSpec;

            TypeReference elementType = ImportTypeReference(original.ElementType, context);

            if (original is PointerType)
            {
                typeSpec = new PointerType(elementType);
            }
            else if (original is ArrayType)                 // deal with complex arrays
            {
                typeSpec = new ArrayType(elementType);
            }
            else if (original is ReferenceType)
            {
                typeSpec = new ReferenceType(elementType);
            }
            else if (original is GenericInstanceType)
            {
                GenericInstanceType git         = original as GenericInstanceType;
                GenericInstanceType genElemType = new GenericInstanceType(elementType);

                context.GenericContext.CheckProvider(genElemType.GetOriginalType(), git.GenericArguments.Count);
                foreach (TypeReference arg in git.GenericArguments)
                {
                    genElemType.GenericArguments.Add(ImportTypeReference(arg, context));
                }

                typeSpec = genElemType;
            }
            else if (original is ModifierOptional)
            {
                TypeReference mt = (original as ModifierOptional).ModifierType;
                typeSpec = new ModifierOptional(elementType, ImportTypeReference(mt, context));
            }
            else if (original is ModifierRequired)
            {
                TypeReference mt = (original as ModifierRequired).ModifierType;
                typeSpec = new ModifierRequired(elementType, ImportTypeReference(mt, context));
            }
            else if (original is SentinelType)
            {
                typeSpec = new SentinelType(elementType);
            }
            else if (original is FunctionPointerType)
            {
                FunctionPointerType ori = original as FunctionPointerType;

                FunctionPointerType fnptr = new FunctionPointerType(
                    ori.HasThis,
                    ori.ExplicitThis,
                    ori.CallingConvention,
                    new MethodReturnType(ImportTypeReference(ori.ReturnType.ReturnType, context)));

                foreach (ParameterDefinition parameter in ori.Parameters)
                {
                    fnptr.Parameters.Add(new ParameterDefinition(ImportTypeReference(parameter.ParameterType, context)));
                }

                typeSpec = fnptr;
            }
            else
            {
                throw new ReflectionException("Unknown element type: {0}", original.GetType().Name);
            }

            return(typeSpec);
        }