Exemplo n.º 1
0
        public Expression <FunctionComponent> BuildRendererExpression()
        {
            var context = new ComponentBuilderContext(this);
            var element = null as ElementBuilder;

            try
            {
                // build element to be rendered
                element = Render(context);
            }
            catch (Exception e)
            {
                context.OnException(e);
            }

            context.ThrowExceptions();

            var body = new List <Expression>();

            // declare and initialize variables step
            var variables = context.Variables.OrderBy(x => x.Key).Select(x => x.Value).ToArray();

            foreach (var variable in variables)
            {
                body.Add(Expression.Assign(variable.Name, variable.Value));
            }

            // return rendered element step
            body.Add(element?.GetValue(context) ?? Expression.Constant(null, typeof(ofElement)));

            return(Expression.Lambda <FunctionComponent>(Expression.Block(variables.Select(v => v.Name), body), context.Node));
        }
Exemplo n.º 2
0
        public virtual Expression GetValue(ComponentBuilderContext context)
        {
            Expression expr = Expression.New(Constructor, Parameters.Select(p => Props[p.Name].GetValue(context)));

            if (Assignee != null)
            {
                expr = Expression.Assign(Assignee, expr);
            }

            return(expr);
        }
Exemplo n.º 3
0
        public Expression GetValue(ComponentBuilderContext context)
        {
            var items = _items.Select(x => x.GetValue(context));

            var elementType = _type.GetElementType();

            if (elementType != null)
            {
                return(Expression.NewArrayInit(elementType, items));
            }

            return(Expression.ListInit(Expression.New(_type), items));
        }
Exemplo n.º 4
0
            public Expression GetValue(ComponentBuilderContext context)
            {
                if (_parameter.HasDefaultValue)
                {
                    if (_parameter.DefaultValue == null && _parameter.ParameterType.IsValueType)
                    {
                        return(Expression.Default(_parameter.ParameterType));
                    }

                    return(Expression.Constant(_parameter.DefaultValue, _parameter.ParameterType));
                }

                throw new ArgumentException($"Parameter {_parameter} of constructor {_parameter.Member} in {_parameter.Member.DeclaringType} is required but no value was provided.");
            }
Exemplo n.º 5
0
 public override Expression GetValue(ComponentBuilderContext context) => Expression.Constant(null, typeof(ofElement));
Exemplo n.º 6
0
 protected abstract ElementBuilder Render(ComponentBuilderContext context);