Esempio n. 1
0
        /// <summary>
        /// Writes the CIL stream out to the MethodBuilder used to create this Emit.
        ///
        /// Validation that cannot be run until a method is finished is run, and various instructions
        /// are re-written to choose "optimal" forms (Br may become Br_S, for example).
        ///
        /// Once this method is called the Emit may no longer be modified.
        ///
        /// Returns a MethodBuilder, which can be used to define overrides or for further inspection.
        ///
        /// `instructions` will be set to a representation of the instructions making up the returned method.
        /// Note that this string is typically *not* enough to regenerate the method, it is available for
        /// debugging purposes only.  Consumers may find it useful to log the instruction stream in case
        /// the returned method fails validation (indicative of a bug in Sigil) or
        /// behaves unexpectedly (indicative of a logic bug in the consumer code).
        /// </summary>
        public MethodBuilder CreateMethod(out string instructions, OptimizationOptions optimizationOptions = OptimizationOptions.All)
        {
            if (MtdBuilder == null)
            {
                throw new InvalidOperationException("Emit was not created to build a method, thus CreateMethod cannot be called");
            }

            if (MethodBuilt)
            {
                instructions = null;
                return(MtdBuilder);
            }

            Seal(optimizationOptions);

            MethodBuilt = true;

            var il = MtdBuilder.GetILGenerator();

            instructions = IL.UnBuffer(il);

            AutoNamer.Release(this);

            return(MtdBuilder);
        }
Esempio n. 2
0
        /// <summary>
        /// Writes the CIL stream out to the ConstructorBuilder used to create this Emit.
        ///
        /// Validation that cannot be run until a method is finished is run, and various instructions
        /// are re-written to choose "optimal" forms (Br may become Br_S, for example).
        ///
        /// Once this method is called the Emit may no longer be modified.
        ///
        /// Returns a ConstructorBuilder, which can be used to define overrides or for further inspection.
        ///
        /// `instructions` will be set to a representation of the instructions making up the returned constructor.
        /// Note that this string is typically *not* enough to regenerate the constructor, it is available for
        /// debugging purposes only.  Consumers may find it useful to log the instruction stream in case
        /// the returned constructor fails validation (indicative of a bug in Sigil) or
        /// behaves unexpectedly (indicative of a logic bug in the consumer code).
        /// </summary>
        public ConstructorBuilder CreateConstructor(out string instructions, OptimizationOptions optimizationOptions = OptimizationOptions.All)
        {
            if (ConstrBuilder == null)
            {
                throw new InvalidOperationException("Emit was not created to build a constructor, thus CreateConstructor cannot be called");
            }

            if (ConstructorBuilt)
            {
                instructions = null;
                return(ConstrBuilder);
            }

            ConstructorBuilt = true;

            Seal(optimizationOptions);

            var il = ConstrBuilder.GetILGenerator();

            instructions = IL.UnBuffer(il);

            AutoNamer.Release(this);

            return(ConstrBuilder);
        }
Esempio n. 3
0
        internal Delegate InnerCreateDelegate(Type delegateType, out string instructions, OptimizationOptions optimizationOptions)
        {
            Seal(optimizationOptions);

            var il = DynMethod.GetILGenerator();

            instructions = IL.UnBuffer(il);

            AutoNamer.Release(this);

            return(DynMethod.CreateDelegate(delegateType));
        }