本文整理汇总了C#中System.Function.Invoke方法的典型用法代码示例。如果您正苦于以下问题:C# Function.Invoke方法的具体用法?C# Function.Invoke怎么用?C# Function.Invoke使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Function
的用法示例。
在下文中一共展示了Function.Invoke方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Promise
public Promise(Function executor)
{
m_promiseTask = Task.Run(() =>
{
if (executor != null)
{
var executorArguments = new Arguments();
executorArguments.Add(new ExternalFunction(Resolve));
executorArguments.Add(new ExternalFunction(Reject));
executor.Invoke(executorArguments);
}
return m_result;
}, m_cancellationTokenSource.Token);
}
示例2: CreateFunction
public void CreateFunction(string name, int numberOfArguments, Function function, bool deterministic)
{
name = name.ToUpperInvariant();
var nativeFunction = new FunctionNative((context, numberArguments, nativeArguments) =>
{
object[] mangedArguments = ObtainManagedArguments(nativeArguments);
try
{
var result = function.Invoke(mangedArguments);
SetResult(context, result);
}
catch (Exception ex)
{
SetError(context, ex);
}
});
var functionDelegate = this.platformMarshal.ApplyNativeCallingConventionToFunction(nativeFunction);
this.functionDelegates[name] = functionDelegate;
var funcPtr = this.platformMarshal.MarshalDelegateToNativeFunctionPointer(functionDelegate);
int nameLength;
var namePtr = this.platformMarshal.MarshalStringManagedToNativeUTF8(name, out nameLength);
try
{
this.sqlite3Provider.Sqlite3CreateFunction(this.db, namePtr, numberOfArguments, deterministic, funcPtr);
}
finally
{
if (namePtr != IntPtr.Zero)
{
this.platformMarshal.CleanUpStringNativeUTF8(namePtr);
}
}
}
示例3: parse
//.........这里部分代码省略.........
if (stack.Peek().state != ParseState.Value)
throw new JSException((new SyntaxError("Unexpected token.")));
var v = stack.Peek();
v.state = ParseState.End;
v.value = false;
}
else if (code[pos] == '{')
{
if (stack.Peek().state == ParseState.Name)
throw new JSException((new SyntaxError("Unexpected token.")));
stack.Peek().value = JSObject.CreateObject();
stack.Peek().state = ParseState.Object;
//stack.Push(new StackFrame() { state = ParseState.Name, container = stack.Peek().value });
pos++;
}
else if (code[pos] == '[')
{
if (stack.Peek().state == ParseState.Name)
throw new JSException((new SyntaxError("Unexpected token.")));
stack.Peek().value = new Array();
stack.Peek().state = ParseState.Array;
//stack.Push(new StackFrame() { state = ParseState.Value, fieldName = (stack.Peek().valuesCount++).ToString(CultureInfo.InvariantCulture), container = stack.Peek().value });
pos++;
}
else if (stack.Peek().state != ParseState.End)
throw new JSException((new SyntaxError("Unexpected token.")));
if (stack.Peek().state == ParseState.End)
{
var t = stack.Pop();
if (reviewer != null)
{
revargs[0] = t.fieldName;
revargs[1] = t.value;
var val = reviewer.Invoke(revargs);
if (val.IsDefinded)
{
if (t.container != null)
t.container.GetMember(t.fieldName, true, true).Assign(val);
else
{
t.value = val;
stack.Push(t);
}
}
}
else if (t.container != null)
t.container.GetMember(t.fieldName, true, true).Assign(t.value);
else
stack.Push(t);
}
while (code.Length > pos && isSpace(code[pos]))
pos++;
if (code.Length <= pos)
{
if (stack.Peek().state != ParseState.End)
throw new JSException(new SyntaxError("Unexpected end of string."));
else
break;
}
switch (code[pos])
{
case ',':
{
if (stack.Peek().state == ParseState.Array)
stack.Push(new StackFrame() { state = ParseState.Value, fieldName = (stack.Peek().valuesCount++).ToString(CultureInfo.InvariantCulture), container = stack.Peek().value });
else if (stack.Peek().state == ParseState.Object)
示例4: ConstructDispose
public ConstructDispose(Function construct, Function dispose)
{
construct.Invoke();
this.dispose = dispose;
}
示例5: stringifyImpl
private static string stringifyImpl(string key, JSObject obj, Function replacer, string space, List<JSObject> processed, Arguments args)
{
if (processed.IndexOf(obj) != -1)
throw new JSException(new TypeError("Can not convert circular structure to JSON."));
processed.Add(obj);
try
{
{
if (replacer != null)
{
args[0] = "";
args[0].oValue = key;
args[1] = obj;
args.length = 2;
var t = replacer.Invoke(args);
if (t.valueType <= JSObjectType.Undefined || (t.valueType >= JSObjectType.Object && t.oValue == null))
return null;
obj = t;
}
}
if (obj.valueType <= JSObjectType.Undefined
|| obj.valueType == JSObjectType.Function)
return null;
obj = obj.Value as JSObject ?? obj;
StringBuilder res = null;
string strval = null;
if (obj.valueType < JSObjectType.Object)
{
if (obj.valueType == JSObjectType.String)
{
res = new StringBuilder("\"");
strval = obj.ToString();
for (var i = 0; i < strval.Length ; i++)
escapeIfNeed(res, strval[i]);
res.Append('"');
return res.ToString();
}
return obj.ToString();
}
if (obj.Value == null)
return "null";
var toJSONmemb = obj["toJSON"];
toJSONmemb = toJSONmemb.Value as JSObject ?? toJSONmemb;
if (toJSONmemb.valueType == JSObjectType.Function)
return stringifyImpl("", (toJSONmemb.oValue as Function).Invoke(obj, null), null, space, processed, null);
res = new StringBuilder(obj is Array ? "[" : "{");
bool first = true;
foreach (var member in obj)
{
var value = obj[member];
value = value.Value as JSObject ?? value;
if (value.valueType < JSObjectType.Undefined)
continue;
if (value.valueType == JSObjectType.Property)
value = ((value.oValue as PropertyPair).get ?? Function.emptyFunction).Invoke(obj, null);
strval = stringifyImpl(member, value, replacer, space, processed, args);
if (strval == null)
continue;
if (!first)
res.Append(",");
if (space != null)
res.Append(Environment.NewLine);
if (space != null)
res.Append(space);
if (res[0] == '[')
{
if (space != null)
res.Append(space);
/*
for (var i = 0; i < strval.Length; i++)
{
escapeIfNeed(res, strval[i]);
}
*/
res.Append(strval);
}
else
{
res.Append('"');
for (var i = 0; i < member.Length; i++)
{
escapeIfNeed(res, member[i]);
}
res.Append("\":")
.Append(space ?? "");
/*
if (strval.Length > 0 && strval[0] == '"')
{
res.Append(strval[0]);
for (var i = 1; i < strval.Length - 1; i++)
{
escapeIfNeed(res, strval[i]);
}
if (strval.Length > 1)
res.Append(strval[strval.Length - 1]);
}
else
*/
{
for (var i = 0; i < strval.Length; i++)
//.........这里部分代码省略.........