EmitConversionToType() static private method

Pops the value on the stack, converts it from an object to the given type, then pushes the result onto the stack.
static private EmitConversionToType ( ILGenerator generator, Type toType, bool convertToAddress ) : void
generator ILGenerator The IL generator.
toType System.Type The type to convert to.
convertToAddress bool true if the value is intended for use as an /// instance pointer; false otherwise.
return void
Beispiel #1
0
        /// <summary>
        /// Generates a method that does type conversion and calls the bound method.
        /// </summary>
        /// <param name="generator"> The ILGenerator used to output the body of the method. </param>
        /// <param name="argumentCount"> The number of arguments that will be passed to the delegate. </param>
        /// <returns> A delegate that does type conversion and calls the method represented by this
        /// object. </returns>
        protected override void GenerateStub(ILGenerator generator, int argumentCount)
        {
            // Check for the correct number of arguments.
            if (argumentCount != 0)
            {
                EmitHelpers.EmitThrow(generator, ErrorType.TypeError, "Wrong number of arguments");
                EmitHelpers.EmitDefaultValue(generator, PrimitiveType.Any);
                generator.Complete();
                return;
            }

            if (this.field.IsStatic == false)
            {
                generator.LoadArgument(1);
                ClrBinder.EmitConversionToType(generator, this.field.DeclaringType, convertToAddress: true);
            }
            generator.LoadField(this.field);
            ClrBinder.EmitConversionToObject(generator, this.field.FieldType);
            generator.Complete();
        }
Beispiel #2
0
 /// <summary>
 /// Generates a method that does type conversion and calls the bound method.
 /// </summary>
 /// <param name="generator"> The ILGenerator used to output the body of the method. </param>
 /// <param name="argumentCount"> The number of arguments that will be passed to the delegate. </param>
 /// <returns> A delegate that does type conversion and calls the method represented by this
 /// object. </returns>
 protected override void GenerateStub(ILGenerator generator, int argumentCount)
 {
     // Check for the correct number of arguments.
     if (argumentCount != 1)
     {
         EmitHelpers.EmitThrow(generator, "TypeError", "Wrong number of arguments");
         EmitHelpers.EmitDefaultValue(generator, PrimitiveType.Any);
         generator.Complete();
         return;
     }
     if (this.field.IsStatic == false)
     {
         generator.LoadArgument(1);
         ClrBinder.EmitConversionToType(generator, this.field.DeclaringType, convertToAddress: true);
     }
     generator.LoadArgument(2);
     generator.LoadInt32(0);
     generator.LoadArrayElement(typeof(object));
     ClrBinder.EmitConversionToType(generator, this.field.FieldType, convertToAddress: false);
     generator.StoreField(this.field);
     EmitHelpers.EmitUndefined(generator);
     generator.Complete();
 }