Expression Items(ContainerItemHandler handler) { // If the list is an empty element we won't read anything var isEmpty = Expression.Variable(typeof(bool), "isEmpty"); // Generate the following code for the "next" expression: // if (isEmpty) // { // return false; // } // else // { // while (reader.NodeType == XmlNodeType.Whitespace) reader.Read; // do { reader.Read(); } while (reader.NodeType == XmlNodeType.Whitespace; // // if (reader.NodeType == XmlNodeType.Element) && // reader.LocalName != "Item") // { // throw new InvalidDataException(); // } // // return reader.XmlNode != XmlNodeType.EndElement; // } var whitespace = Expression.Equal(Reader.NodeType, Expression.Constant(XmlNodeType.Whitespace)); var next = Expression.Condition(isEmpty, Expression.Constant(false), Expression.Block( ControlExpression.While(whitespace, Reader.Read()), ControlExpression.DoWhile(Reader.Read(), whitespace), Expression.IfThen( Expression.AndAlso( Expression.Equal(Reader.NodeType, Expression.Constant(XmlNodeType.Element)), Expression.NotEqual(Reader.LocalName, Expression.Constant("Item"))), ParsingError()), Expression.NotEqual(Reader.NodeType, Expression.Constant(XmlNodeType.EndElement)))); return(Expression.Block( new[] { isEmpty }, Expression.Assign(isEmpty, Reader.IsEmptyElement), handler(next))); }
public virtual Expression Apply(ITransform transform) { IEnumerable <TransformSchemaPair> transforms; if (flatten && schema.HasBase) { // collect transform/schema pairs for all the bases var flatteningParser = new FlatteningParser(Schema); flatteningParser.Apply(transform); transforms = flatteningParser.Transforms; } else { transforms = new[] { new TransformSchemaPair(transform, Schema) }; } var state = Expression.Variable(typeof(byte), "state"); var requiredFields = RequiredFields.Variable("requiredFields"); var requiredFieldNames = GetRequiredFieldNames(); var stateMachine = CreateStateMachine(transforms, requiredFields); return(Expression.Block( new[] { state, requiredFields }, transform.Begin, RequiredFields.Init(requiredFields, requiredFieldNames.Count), Expression.Assign(state, Expression.Constant(stateMachine.InitialState)), ControlExpression.While( Expression.AndAlso( Expression.Not(EOF), Expression.NotEqual(state, Expression.Constant(stateMachine.FinalState))), SwitchToken(stateMachine, state), Expression.Label("endStateMachineLoop")), VerifyRequiredFields(requiredFields, requiredFieldNames), transform.End)); }