Microsoft.JScript.Vsa.VsaEngine.CreateHostCallbackIL C# (CSharp) Method

CreateHostCallbackIL() private method

private CreateHostCallbackIL ( ILGenerator il, FieldInfo site ) : void
il System.Reflection.Emit.ILGenerator
site System.Reflection.FieldInfo
return void
      private void CreateHostCallbackIL(ILGenerator il, FieldInfo site){
        // Do callbacks to the host for global object instances
        MethodInfo getGlobalInstance = site.FieldType.GetMethod("GetGlobalInstance");
        MethodInfo getEventSourceInstance = site.FieldType.GetMethod("GetEventSourceInstance");
        foreach (Object item in this.vsaItems){
          if (item is VsaHostObject){
            VsaHostObject hostObject = (VsaHostObject)item;
            // get global item instance from site
            il.Emit(OpCodes.Ldarg_0);
            il.Emit(OpCodes.Ldfld, site);
            il.Emit(OpCodes.Ldstr, hostObject.Name);
            il.Emit(OpCodes.Callvirt, getGlobalInstance);
            // cast instance to the correct type and store into the global field
            Type target_type = hostObject.Field.FieldType;
            il.Emit(OpCodes.Ldtoken, target_type);
            il.Emit(OpCodes.Call, CompilerGlobals.getTypeFromHandleMethod);
            ConstantWrapper.TranslateToILInt(il, 0);
            il.Emit(OpCodes.Call, CompilerGlobals.coerceTMethod);
            if (target_type.IsValueType)
              Microsoft.JScript.Convert.EmitUnbox(il, target_type, Type.GetTypeCode(target_type));
            else
              il.Emit(OpCodes.Castclass, target_type);
            il.Emit(OpCodes.Stsfld, hostObject.Field);
          }
        }
      }