public XamlIlNodeEmitResult Emit(XamlIlEmitContext context, IXamlIlEmitter codeGen) { var so = context.Configuration.WellKnownTypes.Object; var isp = context.Configuration.TypeMappings.ServiceProvider; var subType = context.CreateSubType("XamlIlClosure_" + Guid.NewGuid(), so); var buildMethod = subType.DefineMethod(so, new[] { isp }, "Build", true, true, false); CompileBuilder(new XamlIlEmitContext(buildMethod.Generator, context.Configuration, context.RuntimeContext, buildMethod.Generator.DefineLocal(context.RuntimeContext.ContextType), (s, type) => subType.DefineSubType(type, s, false), context.Emitters)); var funcType = Type.GetClrType(); codeGen .Ldnull() .Ldftn(buildMethod) .Newobj(funcType.Constructors.FirstOrDefault(ct => ct.Parameters.Count == 2 && ct.Parameters[0].Equals(context.Configuration.WellKnownTypes.Object))); // Allow to save values from the parent context, pass own service provider, etc, etc if (context.Configuration.TypeMappings.DeferredContentExecutorCustomization != null) { codeGen .Ldloc(context.ContextLocal) .EmitCall(context.Configuration.TypeMappings.DeferredContentExecutorCustomization); } subType.CreateType(); return(XamlIlNodeEmitResult.Type(0, funcType)); }
protected override void DoEmit(XamlIlEmitContext context, IXamlIlEmitter codeGen) => codeGen.Ldnull();
public static IXamlIlEmitter Ldstr(this IXamlIlEmitter emitter, string arg) => arg == null?emitter.Ldnull() : emitter.Emit(OpCodes.Ldstr, arg);