public void AddFunction(CultureInfo culture, string name, LocFunction function)
        {
            var bundle = _contexts[culture];

            bundle.AddFunction(name, (args, options)
                               => CallFunction(function, args, options), out _, InsertBehavior.Overriding);
        }
        /// <summary>
        /// SetFunctionActualState set the actual state of a function in the given loc.
        /// </summary>
        public static void SetFunctionActualState(this ILocState loc, LocFunction function, bool value)
        {
            IStateProperty <bool> state;

            if (loc.TryGetFunctionState(function, out state))
            {
                state.Actual = value;
            }
        }
        /// <summary>
        /// GetFunctionActualState returns the actual state of a function in the given loc.
        /// If no such function exists, false is returned.
        /// </summary>
        public static bool GetFunctionActualState(this ILocState loc, LocFunction function)
        {
            IStateProperty <bool> state;

            if (loc.TryGetFunctionState(function, out state))
            {
                return(state.Actual);
            }
            return(false);
        }
        private IFluentType CallFunction(LocFunction function,
                                         IList <IFluentType> positionalArgs, IDictionary <string, IFluentType> namedArgs)
        {
            var args = new ILocValue[positionalArgs.Count];

            for (var i = 0; i < args.Length; i++)
            {
                args[i] = positionalArgs[i].ToLocValue();
            }

            var options = new Dictionary <string, ILocValue>(namedArgs.Count);

            foreach (var(k, v) in namedArgs)
            {
                options.Add(k, v.ToLocValue());
            }

            var argStruct = new LocArgs(args, options);

            return(function.Invoke(argStruct).FluentFromVal());
        }
        private FluentType CallFunction(
            LocFunction function,
            IList <object> fluentArgs, IDictionary <string, object> fluentOptions)
        {
            var args = new ILocValue[fluentArgs.Count];

            for (var i = 0; i < args.Length; i++)
            {
                args[i] = ValFromFluent(fluentArgs[i]);
            }

            var options = new Dictionary <string, ILocValue>(fluentOptions.Count);

            foreach (var(k, v) in fluentOptions)
            {
                options.Add(k, ValFromFluent(v));
            }

            var argStruct = new LocArgs(args, options);

            var ret = function(argStruct);

            return(ValToFluent(ret));
        }
 private void AddCtxFunction(FluentBundle ctx, string name, LocFunction function)
 {
     ctx.AddFunction(name, (args, options)
                     => CallFunction(function, args, options), out _, InsertBehavior.Overriding);
 }
        public void AddFunction(CultureInfo culture, string name, LocFunction function)
        {
            var context = _contexts[culture];

            context.Functions.Add(name, (args, options) => CallFunction(function, args, options));
        }
 private void AddCtxFunction(MessageContext ctx, string name, LocFunction function)
 {
     ctx.Functions.Add(name, (args, options) => CallFunction(function, args, options));
 }