Esempio 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()));
            }
Esempio n. 2
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("};");
            }
        }