Ejemplo n.º 1
0
        private DomAttributeWithInitializers CreateServerDomAttribute(DomAttribute m, string property)
        {
            var result = new DomAttributeWithInitializers();

            try {
                result.Attribute = Document.CreateAttribute(m.Name);
            } catch (Exception ex) {
                if (Failure.IsCriticalException(ex))
                {
                    throw;
                }
                else
                {
                    throw HxlFailure.CannotCreateAttributeOnConversion(m.Name, ex);
                }
            }

            if (result.Attribute == null)
            {
                throw HxlFailure.ServerAttributeCannotBeCreated(m.Name, -1, -1);
            }

            _current.Attributes.Add(result.Attribute);
            AddImplicitType(result.Attribute.GetType());

            return(result);
        }
Ejemplo n.º 2
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]));
        }