private void ApplyRewriteRule(Dictionary <string, string> entityProperties, RewriteDirective.Rule rule, EvaluationContext context) { var attributeName = Evaluation.EvaluateInterpolatedString(rule.Attribute, context); if (rule.DeleteAttribute) { entityProperties.Remove(attributeName); context.Bind(attributeName, null); } else { var value = Evaluation.EvaluateInterpolatedString(rule.NewValue, context); entityProperties[attributeName] = value; context.Bind(attributeName, value); } }
/// <summary> /// Creates functions for all public instance methods in the given instance, and creates bindings for them in the given context. /// </summary> public static void RegisterInstanceMethods(EvaluationContext context, object instance) { foreach (var method in instance.GetType().GetMethods(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly)) { var function = CreateFunction(method, instance); context.Bind(function.Name, function); } }
/// <summary> /// Creates functions for all public static methods in the given type, and creates bindings for them in the given context. /// </summary> public static void RegisterStaticMethods(EvaluationContext context, Type functionsContainer) { foreach (var method in functionsContainer.GetMethods(BindingFlags.Public | BindingFlags.Static | BindingFlags.DeclaredOnly)) { var function = CreateFunction(method); context.Bind(function.Name, function); } }
static Evaluation() { // The globals context gives access to various global functions: _globalsContext = new EvaluationContext(); NativeUtils.RegisterStaticMethods(_globalsContext, typeof(GlobalFunctions)); // as well as some constants: _globalsContext.Bind("PI", Math.PI); }