Exemplo n.º 1
0
            protected override DomObject Convert(DomDocument document, DomAttribute attribute)
            {
                var buffer = new CodeBuffer();

                RewriteExpressionSyntax.MatchVariablesAndEmit(buffer, attribute.Value);
                return(new HxlExpressionAttribute(attribute.Name, buffer.ToString()));
            }
Exemplo n.º 2
0
        // IScriptGenerator implementation
        public IEnumerable <string> Start(HxlForEachElement e)
        {
            yield return(EmitVarLoopStatus(e));

            var inExp = RewriteExpressionSyntax.BindVariables(e.In);

            yield return(string.Format("foreach (var {0} in {1}) {{", e.Var, inExp));

            yield return(string.Format("__closure.{0} = {0};", e.Var));

            yield return(EmitVarLoopStatusCurrent(e));
        }
Exemplo n.º 3
0
        private void InitProperty(string property, string value, DomAttributeWithInitializers withInit)
        {
            PropertyInfo prop;
            DomAttribute attr = withInit.Attribute;

            if (property == null)
            {
                var valueProp = HxlAttributeFragmentDefinition.ForComponent(attr).ValueProperty;
                if (valueProp == null)
                {
                    valueProp = Utility.ReflectGetProperty(attr.GetType(), "Value");
                }
                // TODO Might not have a value property (should implement an expression around the Value property)
                prop = valueProp;
            }
            else
            {
                // TODO Obtain line numbers
                prop = Utility.ReflectGetProperty(attr.GetType(), property);

                if (prop == null)
                {
                    throw HxlFailure.ServerAttributePropertyNotFound(attr.GetType(), property, -1, -1);
                }
            }

            if (!HxlAttributeConverter.IsExpr(value))
            {
                if (property == null)
                {
                    withInit.Attribute.Value = value;
                }

                withInit.Initializers.Add(prop.Name, value);
                return;
            }

            var buffer = new ExpressionBuffer();

            RewriteExpressionSyntax.MatchVariablesAndEmit(buffer, value);

            // TODO Could allow multiple exprs
            if (buffer.Parts.Count == 1)
            {
            }
            else
            {
                throw new NotImplementedException("ex");
            }

            attr.AddAnnotation(new ExpressionInitializers(prop, buffer.Parts[0]));
        }
Exemplo n.º 4
0
        private string[] BindIf(Expression test, bool negate)
        {
            var testExp = RewriteExpressionSyntax.BindVariables(test).ToString();

            // TODO Should bind as a Boolean here

            if (negate)
            {
                testExp = string.Format("!({0})", testExp);
            }
            return(new []
            {
                string.Format("if ({0}) {{", testExp)
            });
        }
Exemplo n.º 5
0
        internal HxlRenderWorkElement BindConditional(Expression test, bool negate)
        {
            var testExp = RewriteExpressionSyntax.BindVariables(test).ToString();

            // TODO Should bind as a Boolean here
            if (negate)
            {
                testExp = string.Format("!({0})", testExp);
            }
            string[] pre =
            {
                string.Format("if ({0}) {{", testExp)
            };

            string[] post = { "}" };
            return(new HxlRenderWorkElement(pre, post));
        }
Exemplo n.º 6
0
        internal static void EmitRenderingThunk(TextWriter sw, string name, DomObject component)
        {
            StringBuilder rendering = new StringBuilder();

            // TODO Undesirable that expressions get serialized in EmitInstantiation
            // TODO This serialization logic implies that only strings can be used with expressions
            foreach (PropertyInfo m in Utility.ReflectGetProperties(component.GetType()))
            {
                if (m.CanWrite && m.PropertyType == typeof(string))
                {
                    // TODO Need to check more than CanWrite -- may need to check accessibility of the setter (rare)

                    string text = (string)m.GetValue(component) ?? string.Empty;
                    if (HxlAttributeConverter.IsExpr(text))
                    {
                        CodeBuffer cb = new CodeBuffer();
                        RewriteExpressionSyntax.MatchVariablesAndEmit(cb, text);
                        rendering.AppendFormat("    {2}.{0} = {1};", m.Name, cb, name);
                        rendering.AppendLine();
                    }
                }
            }

            var additional = component.Annotations <ExpressionInitializers>();

            foreach (ExpressionInitializers m in additional)
            {
                rendering.AppendFormat("    {2}.{0} = {1};", m.Member.Name, m.Expression, name);
                rendering.AppendLine();
            }

            // TODO Use of __self__ is a hack (will it actually be used?)
            if (rendering.Length > 0)
            {
                sw.WriteLine("{0}.Rendering = (__context, __self__) => {{", name);
                sw.WriteLine("    dynamic __closure = __context;");
                sw.Write(rendering);
                sw.WriteLine("};");
            }
        }