public DelegateInfo GenerateDelegateStub() { PerfTrack.NoteEvent(PerfTrack.Categories.DelegateCreate, ToString()); Type[] delegateParams = new Type[_parameters.Length]; for (int i = 0; i < _parameters.Length; i++) { delegateParams[i] = _parameters[i].ParameterType; } AssemblyGen snippets = ScriptDomainManager.CurrentManager.Snippets.Assembly; // Create new constant pool ConstantPool constants = new ConstantPool(); // Create the method CodeGen cg = snippets.DefineMethod(ToString(), _returnType, delegateParams, constants); cg.Binder = _binder; // Add the space for the delegate target and save the index at which it was placed, // most likely zero. int targetIndex = constants.Count; #if DEBUG Slot target = constants.AddData(TargetPlaceHolder); #else Slot target = constants.AddData(null); #endif // Add the CodeContext into the constant pool Slot context = cg.ConstantPool.AddData(_binder.Context); Debug.Assert(typeof(CodeContext).IsAssignableFrom(context.Type)); cg.ContextSlot = context; // Emit the stub StubGenerator.EmitClrCallStub(cg, target, 0, StubGenerator.CallType.None); // Finish the method MethodInfo method = cg.CreateDelegateMethodInfo(); // Save the constants in the delegate info class return(new DelegateInfo(method, constants.Data, targetIndex)); }