本文整理汇总了C#中Engine.SetValue方法的典型用法代码示例。如果您正苦于以下问题:C# Engine.SetValue方法的具体用法?C# Engine.SetValue怎么用?C# Engine.SetValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Engine
的用法示例。
在下文中一共展示了Engine.SetValue方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CanConvertEnumsToString
public void CanConvertEnumsToString()
{
var engine1 = new Engine(o => o.AddObjectConverter(new EnumsToStringConverter()))
.SetValue("assert", new Action<bool>(Assert.True));
engine1.SetValue("p", new { Comparison = StringComparison.CurrentCulture });
engine1.Execute("assert(p.Comparison === 'CurrentCulture');");
engine1.Execute("var result = p.Comparison;");
Assert.Equal("CurrentCulture", (string)engine1.GetValue("result").ToObject());
}
示例2: ShouldParseAsUtc
public void ShouldParseAsUtc(string date)
{
const string customName = "Custom Time";
var customTimeZone = TimeZoneInfo.CreateCustomTimeZone(customName, new TimeSpan(7, 11, 0), customName, customName, customName, null, false);
var engine = new Engine(cfg => cfg.LocalTimeZone(customTimeZone));
engine.SetValue("d", date);
var result = engine.Execute("Date.parse(d);").GetCompletionValue().AsNumber();
Assert.Equal(0, result);
}
示例3: CanSetCustomConverters
public void CanSetCustomConverters()
{
var engine1 = new Engine();
engine1.SetValue("p", new { Test = true });
engine1.Execute("var result = p.Test;");
Assert.True((bool)engine1.GetValue("result").ToObject());
var engine2 = new Engine(o => o.AddObjectConverter(new NegateBoolConverter()));
engine2.SetValue("p", new { Test = true });
engine2.Execute("var result = p.Test;");
Assert.False((bool)engine2.GetValue("result").ToObject());
}