internal static MethodSignature ReadSig(ModuleReader module, ByteReader br, IGenericContext context)
        {
            CallingConventions callingConvention;
            int  genericParamCount;
            Type returnType;

            Type[] parameterTypes;
            byte   flags = br.ReadByte();

            switch (flags & 7)
            {
            case DEFAULT:
                callingConvention = CallingConventions.Standard;
                break;

            case VARARG:
                callingConvention = CallingConventions.VarArgs;
                break;

            default:
                throw new BadImageFormatException();
            }
            if ((flags & HASTHIS) != 0)
            {
                callingConvention |= CallingConventions.HasThis;
            }
            if ((flags & EXPLICITTHIS) != 0)
            {
                callingConvention |= CallingConventions.ExplicitThis;
            }
            genericParamCount = 0;
            if ((flags & GENERIC) != 0)
            {
                genericParamCount = br.ReadCompressedUInt();
                context           = new UnboundGenericMethodContext(context);
            }
            int paramCount = br.ReadCompressedUInt();

            CustomModifiers[] modifiers = null;
            PackedCustomModifiers.Pack(ref modifiers, 0, CustomModifiers.Read(module, br, context), paramCount + 1);
            returnType     = ReadRetType(module, br, context);
            parameterTypes = new Type[paramCount];
            for (int i = 0; i < parameterTypes.Length; i++)
            {
                if ((callingConvention & CallingConventions.VarArgs) != 0 && br.PeekByte() == SENTINEL)
                {
                    Array.Resize(ref parameterTypes, i);
                    if (modifiers != null)
                    {
                        Array.Resize(ref modifiers, i + 1);
                    }
                    break;
                }
                PackedCustomModifiers.Pack(ref modifiers, i + 1, CustomModifiers.Read(module, br, context), paramCount + 1);
                parameterTypes[i] = ReadParam(module, br, context);
            }
            return(new MethodSignature(returnType, parameterTypes, PackedCustomModifiers.Wrap(modifiers), callingConvention, genericParamCount));
        }
Exemple #2
0
		internal static MethodSignature ReadSig(ModuleReader module, ByteReader br, IGenericContext context)
		{
			CallingConventions callingConvention;
			int genericParamCount;
			Type returnType;
			Type[] parameterTypes;
			byte flags = br.ReadByte();
			switch (flags & 7)
			{
				case DEFAULT:
					callingConvention = CallingConventions.Standard;
					break;
				case VARARG:
					callingConvention = CallingConventions.VarArgs;
					break;
				default:
					throw new BadImageFormatException();
			}
			if ((flags & HASTHIS) != 0)
			{
				callingConvention |= CallingConventions.HasThis;
			}
			if ((flags & EXPLICITTHIS) != 0)
			{
				callingConvention |= CallingConventions.ExplicitThis;
			}
			genericParamCount = 0;
			if ((flags & GENERIC) != 0)
			{
				genericParamCount = br.ReadCompressedInt();
				context = new UnboundGenericMethodContext(context);
			}
			int paramCount = br.ReadCompressedInt();
			Type[][][] modifiers = null;
			Type[] optionalCustomModifiers;
			Type[] requiredCustomModifiers;
			ReadCustomModifiers(module, br, context, out requiredCustomModifiers, out optionalCustomModifiers);
			returnType = ReadRetType(module, br, context);
			parameterTypes = new Type[paramCount];
			PackedCustomModifiers.SetModifiers(ref modifiers, 0, 0, optionalCustomModifiers, paramCount + 1);
			PackedCustomModifiers.SetModifiers(ref modifiers, 0, 1, requiredCustomModifiers, paramCount + 1);
			for (int i = 0; i < parameterTypes.Length; i++)
			{
				if ((callingConvention & CallingConventions.VarArgs) != 0 && br.PeekByte() == SENTINEL)
				{
					Array.Resize(ref parameterTypes, i);
					if (modifiers != null)
					{
						Array.Resize(ref modifiers, i + 1);
					}
					break;
				}
				ReadCustomModifiers(module, br, context, out requiredCustomModifiers, out optionalCustomModifiers);
				PackedCustomModifiers.SetModifiers(ref modifiers, i + 1, 0, optionalCustomModifiers, paramCount + 1);
				PackedCustomModifiers.SetModifiers(ref modifiers, i + 1, 1, requiredCustomModifiers, paramCount + 1);
				parameterTypes[i] = ReadParam(module, br, context);
			}
			return new MethodSignature(returnType, parameterTypes, modifiers, callingConvention, genericParamCount);
		}