本文整理汇总了C#中Closure类的典型用法代码示例。如果您正苦于以下问题:C# Closure类的具体用法?C# Closure怎么用?C# Closure使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Closure类属于命名空间,在下文中一共展示了Closure类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Add
static public Handle Add (uint t, GLib.TimeoutHandler timeout_handler)
{
Closure c;
c = new Closure (timeout_handler);
c.Id = GLib.Timeout.Add (t, new GLib.TimeoutHandler (c.Handler));
return c;
}
示例2: IfClosure
/**
* Constructor that performs no validation.
* Use <code>getInstance</code> if you want that.
*
* @param predicate predicate to switch on, not null
* @param trueClosure closure used if true, not null
* @param falseClosure closure used if false, not null
*/
public IfClosure(Predicate predicate, Closure trueClosure, Closure falseClosure)
: base()
{
iPredicate = predicate;
iTrueClosure = trueClosure;
iFalseClosure = falseClosure;
}
示例3: SwitchClosure
/**
* Constructor that performs no validation.
* Use <code>getInstance</code> if you want that.
*
* @param predicates array of predicates, not cloned, no nulls
* @param closures matching array of closures, not cloned, no nulls
* @param defaultClosure the closure to use if no match, null means nop
*/
public SwitchClosure(Predicate[] predicates, Closure[] closures, Closure defaultClosure)
: base()
{
iPredicates = predicates;
iClosures = closures;
iDefault = (defaultClosure == null ? NOPClosure.INSTANCE : defaultClosure);
}
示例4: LuaFFreeClosure
// we have a gc, so nothing to do
public static void LuaFFreeClosure(LuaState L, Closure c)
{
int size = (c.c.isC != 0) ? SizeCclosure(c.c.nupvalues) :
SizeLclosure(c.l.nupvalues);
//luaM_freemem(L, c, size);
SubtractTotalBytes(L, size);
}
示例5: WhileClosure
/**
* Constructor that performs no validation.
* Use <code>getInstance</code> if you want that.
*
* @param predicate the predicate used to evaluate when the loop terminates, not null
* @param closure the closure the execute, not null
* @param doLoop true to act as a do-while loop, always executing the closure once
*/
public WhileClosure(Predicate predicate, Closure closure, bool doLoop)
: base()
{
iPredicate = predicate;
iClosure = closure;
iDoLoop = doLoop;
}
示例6: StronglyTypedAstBuilder
public StronglyTypedAstBuilder(Closure externalClosure)
{
foreach (var pair in externalClosure)
{
_closure.Add(pair.Key, pair.Value);
}
}
示例7: Generate
public void Generate()
{
indensionStack.Clear();
indensionStack.Push(-1);
if (app == null) app = new Application();
thisPresentation = app.Presentations.Add(MsoTriState.msoFalse);
var cl = new DocumentClosure(null, thisPresentation, app);
CurrentClosure = cl;
ChangeTheme();
cl.Initialize();
cl.WorkPath = DefaultWorkPath;
var module = thisPresentation.VBProject.VBComponents.Add(vbext_ComponentType.vbext_ct_StdModule);
module.CodeModule.AddFromString(Resources.VBAModule);
while (true)
{
var thisLine = ScriptReader.ReadLine();
if (thisLine == null) break;
Console.WriteLine(thisLine);
if (!string.IsNullOrWhiteSpace(thisLine) && thisLine.TrimStart()[0] != '#')
ParseLine(thisLine);
}
while (CurrentClosure != null) ExitClosure();
app.Run("PAG_PostProcess", thisPresentation);
var wnd = thisPresentation.NewWindow();
thisPresentation.VBProject.VBComponents.Remove(module);
wnd.Activate();
//thisPresentation.Close();
}
示例8: luaF_freeclosure
// we have a gc, so nothing to do
public static void luaF_freeclosure(lua_State L, Closure c)
{
int size = (c.c.isC != 0) ? sizeCclosure(c.c.nupvalues) :
sizeLclosure(c.l.nupvalues);
//luaM_freemem(L, c, size);
SubtractTotalBytes(L, size);
}
示例9: ShouldBeAbleToNestClosures
public void ShouldBeAbleToNestClosures()
{
MathOperation add = delegate(int a, int b) { return a + b; };
Closure doMath = new Closure(add, new Closure(add, new Closure(add, 1, 1), 1), 1);
int result = (int) doMath.Invoke();
Assert.IsTrue(result == 4);
}
示例10: CallLuaClosure
protected IEnumerator CallLuaClosure(LuaEnvironment luaEnv, Closure callback)
{
yield return new WaitForEndOfFrame();
if (callback != null)
{
luaEnv.RunLuaFunction(callback, true);
}
}
示例11: getInstance
/**
* Factory method that performs validation.
*
* @param closure the closure to call, not null
* @return the <code>closure</code> transformer
* @throws IllegalArgumentException if the closure is null
*/
public static Transformer getInstance(Closure closure)
{
if (closure == null)
{
throw new java.lang.IllegalArgumentException("Closure must not be null");
}
return new ClosureTransformer(closure);
}
示例12: copy
/**
* Clone the closures to ensure that the internal reference can't be messed with.
*
* @param closures the closures to copy
* @return the cloned closures
*/
internal static Closure[] copy(Closure[] closures)
{
if (closures == null)
{
return null;
}
return (Closure[])closures.clone();
}
示例13: getInstance
/**
* Factory method that performs validation and copies the parameter array.
*
* @param closures the closures to chain, copied, no nulls
* @return the <code>chained</code> closure
* @throws IllegalArgumentException if the closures array is null
* @throws IllegalArgumentException if any closure in the array is null
*/
public static Closure getInstance(Closure[] closures)
{
FunctorUtils.validate(closures);
if (closures.Length == 0)
{
return NOPClosure.INSTANCE;
}
closures = FunctorUtils.copy(closures);
return new ChainedClosure(closures);
}
示例14: Coroutine_Create
public DynValue Coroutine_Create(Closure closure)
{
// create a processor instance
Processor P = new Processor(this);
// Put the closure as first value on the stack, for future reference
P.m_ValueStack.Push(DynValue.NewClosure(closure));
// Return the coroutine handle
return DynValue.NewCoroutine(new Coroutine(P));
}
示例15: CurriedClosureShouldBeAbleToBindToAStronglyTypedDelegate
public void CurriedClosureShouldBeAbleToBindToAStronglyTypedDelegate()
{
MathOperation add = delegate(int a, int b) { return a + b; };
Closure doMath = new Closure(add, Args.Lambda, 1);
SingleOperatorMathOperation mathOp = doMath.AdaptTo<SingleOperatorMathOperation>();
// return 5 + 1
int result = mathOp(5);
// The result should be 6
Assert.AreEqual(6, result);
}