コード例 #1
0
        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));
        }