Ejemplo n.º 1
0
        public Field(uint token)
            : base(token)
        {
            char[] szName = new char[1024];
            uint   outNameSize;
            uint   tokclass, attr, sigBlobSize, constValueType, constValueSize;
            IntPtr sigBlob, constValue;

            Context.importIntf.GetFieldProps
                (token, out tokclass, szName, 1024, out outNameSize, out attr,
                out sigBlob, out sigBlobSize,
                out constValueType, out constValue, out constValueSize);

            this.name          = Decoder.ReadString(szName, (int)outNameSize);
            this.flags         = (CorFieldAttr)attr;
            this.declaringType = Type.Get(tokclass, null);

            int idx = 0;
            CorCallingConvention b = (CorCallingConvention)Decoder.ReadValue(sigBlob, ref idx);

            if (b != CorCallingConvention.FIELD)
            {
                throw new ArgumentException("Not a field signature");
            }
            CustomMod.ReadCustomMods(sigBlob, ref idx);
            this.type = new Type(sigBlob, ref idx, this.declaringType);

            if (this.IsLiteral)
            {
                this.constValue = new ConstValue(constValueType, constValue, constValueSize);
            }
        }
Ejemplo n.º 2
0
        static public List <CustomMod> ReadCustomMods(IntPtr sig, ref int idx)
        {
            List <CustomMod> customMods = null;

            while (CustomMod.IsCustomMod(sig, idx))
            {
                if (customMods == null)
                {
                    customMods = new List <CustomMod>();
                }

                customMods.Add(new CustomMod(sig, ref idx));
            }

            return(customMods);
        }
Ejemplo n.º 3
0
        public void SetSig(IntPtr sig, ref int idx, Token context)
        {
            CustomMod.ReadCustomMods(sig, ref idx);

            CorElementType b = (CorElementType)Decoder.ReadByte(sig, idx);

            if (b == CorElementType.TYPEDBYREF)
            {
                idx++;
                this.kind = ParamKind.TypedByRef;
            }
            else if (b == CorElementType.VOID)
            {
                idx++;
                this.kind = ParamKind.Void;
            }
            else
            {
                this.kind = ParamKind.Type;
                if (b == CorElementType.BYREF)
                {
                    idx++;
                    this.byRef = true;
                }
                this.type = new Type(sig, ref idx, context);
                if (this.type.IsGenericInstance)
                {
                    throw new System.ArgumentException
                              ("Unsupported generic instance as parameter");
                }
            }

            // Mode_Out and by ref parameters are not supported. Raise an error in those cases.
            if ((this.Mode == ParamMode.Mode_Out) || (this.byRef))
            {
                throw new ArgumentException
                          ("Mode Out or ByRef parameters are not handled");
            }
        }