Exemple #1
0
        private Expression NodeNameEquals(string localName, string namespaceUri)
        {
            if (string.IsNullOrEmpty(namespaceUri))
            {
                return(StringExpression.Equals(Reader.LocalName, localName, StringComparison.OrdinalIgnoreCase));
            }

            return(Expression.AndAlso(
                       StringExpression.Equals(Reader.LocalName, localName, StringComparison.OrdinalIgnoreCase),
                       Expression.OrElse(
                           StringExpression.Equals(Reader.NamespaceURI, StringExpression.Empty(), StringComparison.OrdinalIgnoreCase),
                           StringExpression.Equals(Reader.NamespaceURI, namespaceUri, StringComparison.OrdinalIgnoreCase))));
        }
Exemple #2
0
        public override Expression Scalar(Expression valueType, BondDataType expectedType, ValueHandler handler)
        {
            var stringValue = Expression.Variable(typeof(string), "valueAsString");

            // Reading primitive field of a struct, or a primitive list item - value is in Xml element text.
            // If we have an empty element, parse it as if it has an empty text.
            // Otherwise: read once to get to the text, handle the text, read once more to get to the end element.
            return(Expression.Block(
                       new[] { stringValue },
                       Expression.IfThenElse(
                           Reader.IsEmptyElement,
                           Expression.Assign(stringValue, StringExpression.Empty()),
                           Expression.Block(
                               Reader.Read(),
                               Expression.IfThenElse(
                                   Expression.Equal(Reader.NodeType, Expression.Constant(XmlNodeType.EndElement)),
                                   Expression.Assign(stringValue, Expression.Constant(string.Empty)),
                                   Expression.Block(
                                       IfNotNodeType(XmlNodeType.Text, IfNotNodeType(XmlNodeType.Whitespace, ParsingError())),
                                       Expression.Assign(stringValue, Reader.Value),
                                       Reader.Read(),
                                       IfNotNodeType(XmlNodeType.EndElement, ParsingError()))))),
                       handler(StringExpression.Convert(stringValue, expectedType))));
        }
            static Cache()
            {
                Expression create;

                if (typeof(T) == typeof(string))
                {
                    create = StringExpression.Empty();
                }
                else if (typeof(T).IsBonded())
                {
                    create = Expression.Field(null,
                                              typeof(Bonded <>).MakeGenericType(typeof(T).GetValueType()).GetTypeInfo().GetDeclaredField("Empty"));
                }
                else if (typeof(T).IsClass())
                {
                    create = Expression.New(typeof(T));
                }
                else
                {
                    create = Expression.Default(typeof(T));
                }

                Create = Expression.Lambda <Func <T> >(create).Compile();
            }