public TypeReference GetModifierType(CustomMod [] cmods, TypeReference type)
        {
            TypeReference ret = type;

            for (int i = cmods.Length - 1; i >= 0; i--)
            {
                CustomMod     cmod    = cmods [i];
                TypeReference modType = null;

                if (cmod.TypeDefOrRef.TokenType == TokenType.TypeDef)
                {
                    modType = GetTypeDefAt(cmod.TypeDefOrRef.RID);
                }
                else
                {
                    modType = GetTypeRefAt(cmod.TypeDefOrRef.RID);
                }

                if (cmod.CMOD == CustomMod.CMODType.OPT)
                {
                    ret = new ModifierOptional(ret, modType);
                }
                else if (cmod.CMOD == CustomMod.CMODType.REQD)
                {
                    ret = new ModifierRequired(ret, modType);
                }
            }
            return(ret);
        }
Exemplo n.º 2
0
        public TypeReference GetModifierType(CustomMod [] cmods, TypeReference type)
        {
            if (cmods == null || cmods.Length == 0)
                return type;

            TypeReference ret = type;
            for (int i = cmods.Length - 1; i >= 0; i--) {
                CustomMod cmod = cmods [i];
                TypeReference modType;

                if (cmod.TypeDefOrRef.TokenType == TokenType.TypeDef)
                    modType = GetTypeDefAt (cmod.TypeDefOrRef.RID);
                else
                    modType = GetTypeRefAt (cmod.TypeDefOrRef.RID);

                if (cmod.CMOD == CustomMod.CMODType.OPT)
                    ret = new ModifierOptional (ret, modType);
                else if (cmod.CMOD == CustomMod.CMODType.REQD)
                    ret = new ModifierRequired (ret, modType);
            }
            return ret;
        }
Exemplo n.º 3
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;
        }
Exemplo n.º 4
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);
        }