private static CustomAttributeTypedArgument LoadChar(IBinaryAccessor accessor, Module module, bool isArray, int arrayLength)
        {
            var type = TypeReference.GetPrimitiveType(PrimitiveTypeCode.Char, module.Assembly);

            if (isArray)
            {
                var value = new short[arrayLength];
                for (int i = 0; i < arrayLength; i++)
                {
                    value[i] = accessor.ReadInt16();
                }

                return(new CustomAttributeTypedArgument(value, type));
            }
            else
            {
                short value = accessor.ReadInt16();
                return(new CustomAttributeTypedArgument(value, type));
            }
        }
        private ExceptionHandler LoadTinyExceptionHandler(IBinaryAccessor accessor, Module module)
        {
            var handler = new ExceptionHandler();

            int flags = accessor.ReadInt16() & ILExceptionFlag.MASK;

            switch (flags)
            {
            case 0:
                handler.Type = ExceptionHandlerType.Catch;
                break;

            case 1:
                handler.Type = ExceptionHandlerType.Filter;
                break;

            case 2:
                handler.Type = ExceptionHandlerType.Finally;
                break;

            case 4:
                handler.Type = ExceptionHandlerType.Fault;
                break;
            }

            handler.TryOffset     = accessor.ReadUInt16();
            handler.TryLength     = accessor.ReadByte();
            handler.HandlerOffset = accessor.ReadUInt16();
            handler.HandlerLength = accessor.ReadByte();

            switch (handler.Type)
            {
            case ExceptionHandlerType.Catch:
            {
                int token = accessor.ReadInt32();
                handler.CatchType = TypeSignature.Load(module, token);
            }
            break;

            case ExceptionHandlerType.Filter:
            {
                handler.FilterOffset = accessor.ReadInt32();
            }
            break;

            default:
            {
                accessor.Position += 4;                                 // padded
            }
            break;
            }

            return(handler);
        }
		protected internal override void Read(IBinaryAccessor accessor, TableCompressionInfo compressionInfo, int count)
		{
			if (count == 0)
				return;

			var rows = new DeclSecurityRow[count];
			for (int i = 0; i < count; i++)
			{
				var row = new DeclSecurityRow();
				row.Action = (SecurityAction)accessor.ReadInt16();
				row.Parent = accessor.ReadCell(compressionInfo.CodedTokenDataSize4[4]);
				row.PermissionSet = accessor.ReadCell(compressionInfo.BlobHeapOffsetSize4);

				rows[i] = row;
			}

			_count = count;
			_rows = rows;
		}
        protected void Load(IBinaryAccessor accessor)
        {
            // The encoded blob begins with the prolog, which is always the 2-byte value 0x0001.
            // This is actually the version of the custom attribute blob encoding scheme, which hasn't changed
            // since its introduction, so the prolog is the same for all existing versions of the runtime.
            short prolog = accessor.ReadInt16();

            if (prolog != 1)
            {
                throw new CodeModelException(string.Format(SR.AssemblyLoadError, _module.Location));
            }

            // Ctor arguments.
            _ctorArguments = new CustomAttributeCtorArgumentCollection(this);
            _ctorArguments.Load(accessor);

            // Named arguments.
            _namedArguments = new CustomAttributeNamedArgumentCollection(this);
            _namedArguments.Load(accessor);
        }
        private void StateLoadInstructions(IBinaryAccessor accessor, Module module)
        {
            int instructionCount = accessor.Read7BitEncodedInt();

            _instructions = new List <Instruction>(instructionCount);

            for (int i = 0; i < instructionCount; i++)
            {
                OpCode opCode;
                byte   opByte = accessor.ReadByte();
                if (opByte == 0xFE)
                {
                    opByte = accessor.ReadByte();
                    opCode = OpCodes.OpCodeArray[256 + opByte];
                }
                else
                {
                    opCode = OpCodes.OpCodeArray[opByte];
                }

                object value;
                switch (opCode.OperandType)
                {
                case OperandType.InlineBrTarget:
                {
                    value = accessor.ReadInt32();
                }
                break;

                case OperandType.InlineField:
                {
                    int token = accessor.ReadInt32();
                    value = module.GetSignature <Signature>(token);
                }
                break;

                case OperandType.InlineI:
                {
                    value = accessor.ReadInt32();
                }
                break;

                case OperandType.InlineI8:
                {
                    value = accessor.ReadInt64();
                }
                break;

                case OperandType.InlineMethod:
                {
                    int token = accessor.ReadInt32();
                    value = module.GetSignature <Signature>(token);
                }
                break;

                case OperandType.InlineR:
                {
                    value = accessor.ReadDouble();
                }
                break;

                case OperandType.InlineSig:
                {
                    int token = accessor.ReadInt32();
                    value = module.GetSignature <Signature>(token);
                }
                break;

                case OperandType.InlineString:
                {
                    // Token of a userdefined string, whose RID portion is actually an offset in the #US blob stream.
                    value = accessor.ReadLengthPrefixedString(Encoding.Unicode);
                }
                break;

                case OperandType.InlineSwitch:
                {
                    int   count   = accessor.ReadInt32();
                    int[] targets = new int[count];
                    for (int j = 0; j < count; j++)
                    {
                        targets[j] = accessor.ReadInt32();
                    }

                    value = targets;
                }
                break;

                case OperandType.InlineTok:
                {
                    int token = accessor.ReadInt32();
                    value = module.GetSignature <Signature>(token);
                }
                break;

                case OperandType.InlineType:
                {
                    int token = accessor.ReadInt32();
                    value = module.GetSignature <Signature>(token);
                }
                break;

                case OperandType.InlineVar:
                {
                    value = accessor.ReadInt16();
                }
                break;

                case OperandType.ShortInlineBrTarget:
                {
                    value = accessor.ReadSByte();
                }
                break;

                case OperandType.ShortInlineI:
                {
                    value = accessor.ReadByte();
                }
                break;

                case OperandType.ShortInlineR:
                {
                    value = accessor.ReadSingle();
                }
                break;

                case OperandType.ShortInlineVar:
                {
                    value = accessor.ReadByte();
                }
                break;

                default:
                {
                    value = null;
                }
                break;
                }

                _instructions.Add(new Instruction(opCode, value));
            }
        }
        private void LoadInstructions(IBinaryAccessor accessor, Module module, int codeSize)
        {
            long startOffset = accessor.Position;

            var image = module.Image;

            _instructions = new List <Instruction>();

            while (accessor.Position < startOffset + codeSize)
            {
                OpCode opCode;
                byte   opByte = accessor.ReadByte();
                if (opByte == 0xFE)
                {
                    opByte = accessor.ReadByte();
                    opCode = OpCodes.OpCodeArray[256 + opByte];
                }
                else
                {
                    opCode = OpCodes.OpCodeArray[opByte];
                }

                if (opCode == null)
                {
                    throw new CodeModelException(string.Format(SR.AssemblyLoadError, module.Location));
                }

                object value;
                switch (opCode.OperandType)
                {
                case OperandType.InlineBrTarget:
                {
                    value = accessor.ReadInt32();
                }
                break;

                case OperandType.InlineField:
                {
                    int token = accessor.ReadInt32();
                    value = FieldReference.Load(module, token);
                }
                break;

                case OperandType.InlineI:
                {
                    value = accessor.ReadInt32();
                }
                break;

                case OperandType.InlineI8:
                {
                    value = accessor.ReadInt64();
                }
                break;

                case OperandType.InlineMethod:
                {
                    int token = accessor.ReadInt32();
                    value = MethodReference.Load(module, token);
                }
                break;

                case OperandType.InlineR:
                {
                    value = accessor.ReadDouble();
                }
                break;

                case OperandType.InlineSig:
                {
                    int token = accessor.ReadInt32();
                    if (MetadataToken.GetType(token) == MetadataTokenType.Signature)
                    {
                        int rid = MetadataToken.GetRID(token);
                        value = CallSite.LoadStandAloneSig(module, rid);
                    }
                    else
                    {
                        throw new CodeModelException(SR.MethodBodyBlobNotValid);
                    }
                }
                break;

                case OperandType.InlineString:
                {
                    // Token of a userdefined string, whose RID portion is actually an offset in the #US blob stream.
                    uint token = accessor.ReadUInt32();
                    int  rid   = (int)(token & 0x00ffffff);
                    value = image.GetUserString(rid);
                }
                break;

                case OperandType.InlineSwitch:
                {
                    int   count   = accessor.ReadInt32();
                    int[] targets = new int[count];
                    for (int i = 0; i < count; i++)
                    {
                        targets[i] = accessor.ReadInt32();
                    }

                    value = targets;
                }
                break;

                case OperandType.InlineTok:
                {
                    int token = accessor.ReadInt32();
                    int rid   = MetadataToken.GetRID(token);
                    switch (MetadataToken.GetType(token))
                    {
                    case MetadataTokenType.Method:
                        value = MethodReference.LoadMethodDef(module, rid);
                        break;

                    case MetadataTokenType.MethodSpec:
                        value = GenericMethodReference.LoadMethodSpec(module, rid);
                        break;

                    case MetadataTokenType.MemberRef:
                        value = MethodReference.LoadMemberRef(module, rid);
                        break;

                    case MetadataTokenType.Field:
                        value = FieldReference.LoadFieldDef(module, rid);
                        break;

                    case MetadataTokenType.TypeDef:
                        value = TypeReference.LoadTypeDef(module, rid);
                        break;

                    case MetadataTokenType.TypeRef:
                        value = TypeReference.LoadTypeRef(module, rid);
                        break;

                    case MetadataTokenType.TypeSpec:
                        value = TypeSignature.LoadTypeSpec(module, rid);
                        break;

                    default:
                        throw new CodeModelException(SR.MethodBodyBlobNotValid);
                    }
                }
                break;

                case OperandType.InlineType:
                {
                    int token = accessor.ReadInt32();
                    value = TypeSignature.Load(module, token);
                }
                break;

                case OperandType.InlineVar:
                {
                    value = accessor.ReadInt16();
                }
                break;

                case OperandType.ShortInlineBrTarget:
                {
                    value = accessor.ReadSByte();
                }
                break;

                case OperandType.ShortInlineI:
                {
                    value = accessor.ReadByte();
                }
                break;

                case OperandType.ShortInlineR:
                {
                    value = accessor.ReadSingle();
                }
                break;

                case OperandType.ShortInlineVar:
                {
                    value = accessor.ReadByte();
                }
                break;

                default:
                {
                    value = null;
                }
                break;
                }

                _instructions.Add(new Instruction(opCode, value));
            }
        }