本文整理汇总了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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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'");
}
示例9: Not
public static object Not(XmlNode node, ScriptContext ctx)
{
return !(bool) ctx.Eval(node);
}
示例10: Equals
public static object Equals(XmlNode node, ScriptContext ctx)
{
return ctx.Eval(node) == ctx.Eval(node);
}
示例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);
}