当前位置: 首页>>代码示例>>C#>>正文


C# Function.Invoke方法代码示例

本文整理汇总了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);
        }
开发者ID:Oceanswave,项目名称:SkraprSharp,代码行数:16,代码来源:Promise.cs

示例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);
                }
            }
        }
开发者ID:matrostik,项目名称:SQLitePCL.Windows.SQLCipher,代码行数:40,代码来源:SQLiteConnection.cs

示例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)
开发者ID:modulexcite,项目名称:NiL.JS,代码行数:67,代码来源:JSON.cs

示例4: ConstructDispose

		public ConstructDispose(Function construct, Function dispose)
		{
			construct.Invoke();
			this.dispose = dispose;
		}
开发者ID:davelondon,项目名称:dontstayin,代码行数:5,代码来源:ConstructDispose.cs

示例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++)
//.........这里部分代码省略.........
开发者ID:modulexcite,项目名称:NiL.JS,代码行数:101,代码来源:JSON.cs


注:本文中的System.Function.Invoke方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。