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


C# ScriptContext.Eval方法代码示例

本文整理汇总了C#中ScriptContext.Eval方法的典型用法代码示例。如果您正苦于以下问题:C# ScriptContext.Eval方法的具体用法?C# ScriptContext.Eval怎么用?C# ScriptContext.Eval使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ScriptContext的用法示例。


在下文中一共展示了ScriptContext.Eval方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Modulus

 public static object Modulus(XmlNode node, ScriptContext ctx)
 {
     if(node.ChildNodes.Count != 2) throw new Exception();
     int a = (int) ctx.Eval(node.ChildNodes[0]);
     int b = (int)ctx.Eval(node.ChildNodes[1]);
     return a % b;
 }
开发者ID:rofr,项目名称:playground,代码行数:7,代码来源:Arithmetic.cs

示例2: LessThanOrEqual

        public static object LessThanOrEqual(XmlNode node, ScriptContext ctx)
        {
            if(node.ChildNodes.Count != 2) throw new Exception("Expected 2 child nodes");
            object o1 = ctx.Eval(node.ChildNodes[0]);
            object o2 = ctx.Eval(node.ChildNodes[1]);

            var n1 = o1 is double ? (double) o1 : (int) o1;
            var n2 = o2 is double ? (double)o2 : (int) o2;
            return n1 <= n2;
        }
开发者ID:rofr,项目名称:playground,代码行数:10,代码来源:BooleanOperators.cs

示例3: Eval

        public static object Eval(XmlNode node, ScriptContext ctx)
        {
            XmlNode condition = node.FirstChild;

            object result = null;
            while ((bool)(ctx.Eval(condition)))
            {
                result = ctx.Eval(node.ChildNodes, 1, node.ChildNodes.Count-1);
            }
            return result;
        }
开发者ID:rofr,项目名称:playground,代码行数:11,代码来源:while.cs

示例4: Eval

        public static object Eval(XmlNode node, ScriptContext ctx)
        {
            string varName = XmlHelper.ReadAttribute(node, "var");
            string className = XmlHelper.ReadAttribute(node, "class");
            string propertyName = XmlHelper.ReadAttribute(node, "property");

            object value = ctx.Eval(node.ChildNodes);

            if (varName != null)
            {
                if (propertyName == null)//Assign a new value to the variable
                {
                    ctx.State[varName] = value;
                }
                else //assign a property of the variable
                {
                    ReflectionHelper.SetProperty(ctx.State[varName], propertyName, value);
                }
            }
            else if (className != null) //static property
            {
                throw new NotImplementedException("Static property setter not implemented");
            }

            return value;
        }
开发者ID:rofr,项目名称:playground,代码行数:26,代码来源:Set.cs

示例5: And

 public static object And(XmlNode node, ScriptContext ctx)
 {
     foreach(XmlNode childNode in node.ChildNodes)
     {
         if (!(bool)ctx.Eval(childNode)) return false;
     }
     return true;
 }
开发者ID:rofr,项目名称:playground,代码行数:8,代码来源:BooleanOperators.cs

示例6: Add

 public static object Add(XmlNode node, ScriptContext ctx)
 {
     double sum = 0;
     foreach(XmlNode childNode in node.ChildNodes)
     {
         object o =  ctx.Eval(childNode);
         double operand = o is int ? (int) o : (double) o;
         sum += operand;
     }
     return sum;
 }
开发者ID:rofr,项目名称:playground,代码行数:11,代码来源:Arithmetic.cs

示例7: Eval

        public static object Eval(XmlNode node, ScriptContext ctx)
        {
            XmlNode condition = node.FirstChild;
            XmlNode elseBlock = null;
            int ifNodes = node.ChildNodes.Count - 1;
            if (node.LastChild.Name == "else")
            {
                elseBlock = node.LastChild;
                ifNodes--;
            }

            if ((bool)(ctx.Eval(condition)))
            {
                return ctx.Eval(node.ChildNodes, 1, ifNodes);
            }
            else if (elseBlock != null)
            {
                return ctx.Eval(elseBlock.ChildNodes);
            }
            else return null;
        }
开发者ID:rofr,项目名称:playground,代码行数:21,代码来源:If.cs

示例8: Eval

        public static object Eval(XmlNode node, ScriptContext ctx)
        {
            string methodName = XmlHelper.ReadAttribute(node, "method");
            string className = XmlHelper.ReadAttribute(node, "class");
            string varName = XmlHelper.ReadAttribute(node, "object");

            //Get arguments to pass
            List<object> args = new List<object>();
            foreach (XmlNode argExpr in node.ChildNodes) args.Add(ctx.Eval(argExpr));

            if (className != null)
            {
                Type t = ReflectionHelper.ResolveType(className, ctx.Engine.Namespaces);
                MethodInfo mi = ReflectionHelper.ResolveMethodByArgs(t, methodName, args);
                return mi.Invoke(null, args.ToArray());
            }
            else if (varName != null)
            {
                object obj = ctx.State[varName];
                MethodInfo mi = ReflectionHelper.ResolveMethodByArgs(obj.GetType(), methodName, args);
                return mi.Invoke(obj, args.ToArray());
            }
            else throw new Exception("Missing attribute, 'class' or 'object'");
        }
开发者ID:rofr,项目名称:playground,代码行数:24,代码来源:Call.cs

示例9: Not

 public static object Not(XmlNode node, ScriptContext ctx)
 {
     return !(bool) ctx.Eval(node);
 }
开发者ID:rofr,项目名称:playground,代码行数:4,代码来源:ImmediateValues.cs

示例10: Equals

 public static object Equals(XmlNode node, ScriptContext ctx)
 {
     return ctx.Eval(node) == ctx.Eval(node);
 }
开发者ID:rofr,项目名称:playground,代码行数:4,代码来源:ImmediateValues.cs

示例11: Register

 /// <summary>
 /// Registers the module inside a script context.
 /// </summary>
 /// <param name="context">The context to register the module to.</param>
 public void Register(ScriptContext context)
 {
     context.Eval(Resources.Linq);
 }
开发者ID:mizzunet,项目名称:spike-box,代码行数:8,代码来源:Modules.cs


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