예제 #1
0
        /// <summary>
        /// Creates a CIL method body or returns an empty one if <paramref name="codeReader"/> doesn't
        /// point to the start of a valid CIL method body.
        /// </summary>
        /// <param name="opResolver">The operand resolver</param>
        /// <param name="codeReader">A reader positioned at the start of a .NET method body</param>
        /// <param name="ehReader">Exception handler reader or <c>null</c> if exceptions aren't
        /// present or if <paramref name="codeReader"/> contains the exception handlers</param>
        /// <param name="parameters">Method parameters</param>
        /// <param name="gpContext">Generic parameter context</param>
        /// <param name="context">The module context</param>
        public static CilBody CreateCilBody(IInstructionOperandResolver opResolver, DataReader codeReader, DataReader?ehReader, IList <Parameter> parameters, GenericParamContext gpContext, ModuleContext context)
        {
            var mbReader = new MethodBodyReader(opResolver, codeReader, ehReader, parameters, gpContext, context);

            if (!mbReader.Read())
            {
                return(new CilBody());
            }
            return(mbReader.CreateCilBody());
        }
예제 #2
0
        /// <summary>
        /// Creates a CIL method body or returns an empty one if <paramref name="code"/> is not
        /// a valid CIL method body.
        /// </summary>
        /// <param name="opResolver">The operand resolver</param>
        /// <param name="code">All code</param>
        /// <param name="exceptions">Exceptions or <c>null</c> if all exception handlers are in
        /// <paramref name="code"/></param>
        /// <param name="parameters">Method parameters</param>
        /// <param name="flags">Method header flags, eg. 2 if tiny method</param>
        /// <param name="maxStack">Max stack</param>
        /// <param name="codeSize">Code size</param>
        /// <param name="localVarSigTok">Local variable signature token or 0 if none</param>
        /// <param name="gpContext">Generic parameter context</param>
        /// <param name="context">The module context</param>
        public static CilBody CreateCilBody(IInstructionOperandResolver opResolver, byte[] code, byte[] exceptions, IList <Parameter> parameters, ushort flags, ushort maxStack, uint codeSize, uint localVarSigTok, GenericParamContext gpContext, ModuleContext context)
        {
            var codeReader = ByteArrayDataReaderFactory.CreateReader(code);
            var ehReader   = exceptions is null ? (DataReader?)null : ByteArrayDataReaderFactory.CreateReader(exceptions);
            var mbReader   = new MethodBodyReader(opResolver, codeReader, ehReader, parameters, gpContext, context);

            mbReader.SetHeader(flags, maxStack, codeSize, localVarSigTok);
            if (!mbReader.Read())
            {
                return(new CilBody());
            }
            return(mbReader.CreateCilBody());
        }