HashParametersExpression() public static method

public static HashParametersExpression ( object>.Dictionary parameters ) : HandlebarsDotNet.Compiler.HashParametersExpression
parameters object>.Dictionary
return HandlebarsDotNet.Compiler.HashParametersExpression
        public override IEnumerable <object> ConvertTokens(IEnumerable <object> sequence)
        {
            var enumerator = sequence.GetEnumerator();

            while (enumerator.MoveNext())
            {
                var item = enumerator.Current;

                if (item is HashParameterAssignmentExpression parameterAssignment)
                {
                    bool moveNext;
                    var  parameters = AccumulateParameters(enumerator, out moveNext);

                    if (parameters.Any())
                    {
                        yield return(HandlebarsExpression.HashParametersExpression(parameters));
                    }

                    if (!moveNext)
                    {
                        yield break;
                    }

                    item = enumerator.Current;
                }

                yield return(item is Expression expression?Visit(expression) : item);
            }
        }
Beispiel #2
0
        public override IEnumerable <object> ConvertTokens(IEnumerable <object> sequence)
        {
            var enumerator = sequence.GetEnumerator();

            while (enumerator.MoveNext())
            {
                var item = enumerator.Current;

                if (item is HashParameterToken)
                {
                    var parameters = AccumulateParameters(enumerator);

                    if (parameters.Any())
                    {
                        yield return(HandlebarsExpression.HashParametersExpression(parameters));
                    }

                    yield return(enumerator.Current);
                }
                else
                {
                    yield return(item);
                }
            }
        }
        protected virtual Expression VisitHashParametersExpression(HashParametersExpression hpex)
        {
            var  parameters        = new Dictionary <string, Expression>();
            bool parametersChanged = false;

            foreach (string key in hpex.Parameters.Keys)
            {
                Expression value = Visit(hpex.Parameters[key]);
                parameters.Add(key, value);
                if (value != hpex.Parameters[key])
                {
                    parametersChanged = true;
                }
            }
            if (parametersChanged)
            {
                return(HandlebarsExpression.HashParametersExpression(parameters));
            }
            return(hpex);
        }