示例#1
0
        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);
            }
        }
示例#2
0
 /// <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);
     }
 }
示例#3
0
 /// <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);
     }
 }
示例#4
0
        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);
        }