_Core/Lang/Helpers/FunctionHelper.cs

(开头部分) 16KB

这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;


namespace ComLib.Lang.Helpers
{
    /// <summary>
    /// Helper class for calling functions in the script.
    /// </summary>
    public class FunctionHelper
    {
        /// <summary>
        /// Whether or not the name/member combination supplied is a script level function or an external C# function
        /// </summary>
        /// <param name="ctx">Context of script</param>
        /// <param name="name">Object name "Log"</param>
        /// <param name="member">Member name "Info" as in "Log.Info"</param>
        /// <returns></returns>
        public static bool IsInternalOrExternalFunction(Context ctx, string name, string member)
        {
            string fullName = name;
            if (!string.IsNullOrEmpty(member))
                fullName += "." + member;

            // Case 1: getuser() script function
            if (ctx.Functions.Contains(fullName) || ctx.ExternalFunctions.Contains(fullName))
                return true;

            return false;
        }        


        /// <summary>
        /// Call internal/external script.
        /// </summary>
        /// <param name="ctx"></param>
        /// <param name="name"></param>
        /// <param name="exp"></param>
        /// <returns></returns>
        public static object FunctionCall(Context ctx, string name, FunctionCallExpr exp)
        {
            // Case 1: Custom C# function blog.create blog.*
            if (ctx.ExternalFunctions.Contains(name))
                return ctx.ExternalFunctions.Call(name, exp);

            // Case 2: Script functions "createUser('john');" 
            return ctx.Functions.Call(exp);
        }


        /// <summary>
        /// Execute a member call.
        /// </summary>
        /// <param name="ctx">The context of the script</param>
        /// <param name="type">The type of the object</param>
        /// <param name="obj">The object to call the method on</param>
        /// <param name="varname">The name of the variable</param>
后面还有 333 行代码,解锁后查看完整代码

24 小时内免费解锁 3 个项目,之后 1 积分/个。 规则说明

AI 解读

登录后可用,每次 10 积分,解读结果公开显示在下面。

还没有人解读过这个文件。