Exemplo n.º 1
0
        private static CustomAttributeTypedArgument ReadFixedArg(Module context, ByteReader br, Type type)
        {
            Universe u = context.universe;

            if (type == u.System_String)
            {
                return(new CustomAttributeTypedArgument(type, br.ReadString()));
            }
            else if (type == u.System_Boolean)
            {
                return(new CustomAttributeTypedArgument(type, br.ReadByte() != 0));
            }
            else if (type == u.System_Char)
            {
                return(new CustomAttributeTypedArgument(type, br.ReadChar()));
            }
            else if (type == u.System_Single)
            {
                return(new CustomAttributeTypedArgument(type, br.ReadSingle()));
            }
            else if (type == u.System_Double)
            {
                return(new CustomAttributeTypedArgument(type, br.ReadDouble()));
            }
            else if (type == u.System_SByte)
            {
                return(new CustomAttributeTypedArgument(type, br.ReadSByte()));
            }
            else if (type == u.System_Int16)
            {
                return(new CustomAttributeTypedArgument(type, br.ReadInt16()));
            }
            else if (type == u.System_Int32)
            {
                return(new CustomAttributeTypedArgument(type, br.ReadInt32()));
            }
            else if (type == u.System_Int64)
            {
                return(new CustomAttributeTypedArgument(type, br.ReadInt64()));
            }
            else if (type == u.System_Byte)
            {
                return(new CustomAttributeTypedArgument(type, br.ReadByte()));
            }
            else if (type == u.System_UInt16)
            {
                return(new CustomAttributeTypedArgument(type, br.ReadUInt16()));
            }
            else if (type == u.System_UInt32)
            {
                return(new CustomAttributeTypedArgument(type, br.ReadUInt32()));
            }
            else if (type == u.System_UInt64)
            {
                return(new CustomAttributeTypedArgument(type, br.ReadUInt64()));
            }
            else if (type == u.System_Type)
            {
                return(new CustomAttributeTypedArgument(type, ReadType(context, br)));
            }
            else if (type == u.System_Object)
            {
                return(ReadFixedArg(context, br, ReadFieldOrPropType(context, br)));
            }
            else if (type.IsArray)
            {
                int length = br.ReadInt32();
                if (length == -1)
                {
                    return(new CustomAttributeTypedArgument(type, null));
                }
                Type elementType = type.GetElementType();
                CustomAttributeTypedArgument[] array = new CustomAttributeTypedArgument[length];
                for (int i = 0; i < length; i++)
                {
                    array[i] = ReadFixedArg(context, br, elementType);
                }
                return(new CustomAttributeTypedArgument(type, array));
            }
            else if (type.IsEnum)
            {
                return(new CustomAttributeTypedArgument(type, ReadFixedArg(context, br, type.GetEnumUnderlyingTypeImpl()).Value));
            }
            else
            {
                throw new InvalidOperationException();
            }
        }
Exemplo n.º 2
0
        private static Type ReadFieldOrPropType(Module context, ByteReader br)
        {
            Universe u = context.universe;

            switch (br.ReadByte())
            {
            case Signature.ELEMENT_TYPE_BOOLEAN:
                return(u.System_Boolean);

            case Signature.ELEMENT_TYPE_CHAR:
                return(u.System_Char);

            case Signature.ELEMENT_TYPE_I1:
                return(u.System_SByte);

            case Signature.ELEMENT_TYPE_U1:
                return(u.System_Byte);

            case Signature.ELEMENT_TYPE_I2:
                return(u.System_Int16);

            case Signature.ELEMENT_TYPE_U2:
                return(u.System_UInt16);

            case Signature.ELEMENT_TYPE_I4:
                return(u.System_Int32);

            case Signature.ELEMENT_TYPE_U4:
                return(u.System_UInt32);

            case Signature.ELEMENT_TYPE_I8:
                return(u.System_Int64);

            case Signature.ELEMENT_TYPE_U8:
                return(u.System_UInt64);

            case Signature.ELEMENT_TYPE_R4:
                return(u.System_Single);

            case Signature.ELEMENT_TYPE_R8:
                return(u.System_Double);

            case Signature.ELEMENT_TYPE_STRING:
                return(u.System_String);

            case Signature.ELEMENT_TYPE_SZARRAY:
                return(ReadFieldOrPropType(context, br).MakeArrayType());

            case 0x55:
                return(ReadType(context, br));

            case 0x50:
                return(u.System_Type);

            case 0x51:
                return(u.System_Object);

            default:
                throw new BadImageFormatException();
            }
        }
Exemplo n.º 3
0
 internal Module(Universe universe)
 {
     this.universe = universe;
 }
Exemplo n.º 4
0
 protected NonPEModule(Universe universe)
     : base(universe)
 {
 }
Exemplo n.º 5
0
        internal Type GetType(Universe universe, Module context, bool throwOnError, string originalName, bool resolve, bool ignoreCase)
        {
            Debug.Assert(!resolve || !ignoreCase);
            TypeName name = TypeName.Split(this.name);
            Type     type;

            if (assemblyName != null)
            {
                Assembly asm = universe.Load(assemblyName, context, throwOnError);
                if (asm == null)
                {
                    return(null);
                }
                if (resolve)
                {
                    type = asm.ResolveType(context, name);
                }
                else if (ignoreCase)
                {
                    type = asm.FindTypeIgnoreCase(name.ToLowerInvariant());
                }
                else
                {
                    type = asm.FindType(name);
                }
            }
            else if (context == null)
            {
                if (resolve)
                {
                    type = universe.Mscorlib.ResolveType(context, name);
                }
                else if (ignoreCase)
                {
                    type = universe.Mscorlib.FindTypeIgnoreCase(name.ToLowerInvariant());
                }
                else
                {
                    type = universe.Mscorlib.FindType(name);
                }
            }
            else
            {
                if (ignoreCase)
                {
                    name = name.ToLowerInvariant();
                    type = context.FindTypeIgnoreCase(name);
                }
                else
                {
                    type = context.FindType(name);
                }
                if (type == null && context != universe.Mscorlib.ManifestModule)
                {
                    if (ignoreCase)
                    {
                        type = universe.Mscorlib.FindTypeIgnoreCase(name);
                    }
                    else
                    {
                        type = universe.Mscorlib.FindType(name);
                    }
                }
                if (type == null && resolve)
                {
                    if (universe.Mscorlib.__IsMissing && !context.__IsMissing)
                    {
                        type = universe.Mscorlib.ResolveType(context, name);
                    }
                    else
                    {
                        type = context.Assembly.ResolveType(context, name);
                    }
                }
            }
            return(Expand(type, context, throwOnError, originalName, resolve, ignoreCase));
        }