public Expression Apply(ITransform transform) { Debug.Assert(schema.IsStruct); var body = new List <Expression> { transform.Begin }; if (schema.HasBase) { body.Add(transform.Base(new UntaggedParser <R>(this, schema.GetBaseSchema()))); } // Performs left outer join of schema fields with transform fields. // The result contains entry for each schema field. For fields not handled // by the transform default to Skip. body.AddRange( from fieldDef in schema.StructDef.fields join transfromField in transform.Fields on fieldDef.id equals transfromField.Id into fields from knownField in fields.DefaultIfEmpty() select Field(transform, fieldDef, knownField)); body.Add(transform.End); return(Expression.Block(body)); }
public Expression Apply(ITransform transform) { var structVar = Expression.Variable(objectType, objectType.Name); var body = new List <Expression> { Expression.Assign(structVar, Expression.Convert(objParam, objectType)), transform.Begin }; var baseType = schemaType.GetBaseSchemaType(); if (baseType != null) { var baseObject = Expression.Convert(structVar, objectType.GetBaseSchemaType()); body.Add(transform.Base(new ObjectParser(this, baseObject, baseType))); } // Performs left outer join of object fields with transform fields. // The result contains entry for each schema field. For fields not handled // by the transform default to Skip. body.AddRange( from objectField in schemaType.GetSchemaFields() join transfromField in transform.Fields on objectField.Id equals transfromField.Id into fields from knownField in fields.DefaultIfEmpty() select Field(transform, structVar, objectField.Id, objectField, knownField)); body.Add(transform.End); return(Expression.Block( new [] { structVar }, body)); }
public Expression Apply(ITransform transform) { var structVar = Expression.Variable(objectType, objectType.Name); var body = new List<Expression> { Expression.Assign(structVar, Expression.Convert(objParam, objectType)), transform.Begin }; var baseType = schemaType.GetBaseSchemaType(); if (baseType != null) { var baseObject = Expression.Convert(structVar, objectType.GetBaseSchemaType()); body.Add(transform.Base(new ObjectParser(this, baseObject, baseType))); } // Performs left outer join of object fields with transform fields. // The result contains entry for each schema field. For fields not handled // by the transform default to Skip. body.AddRange( from objectField in schemaType.GetSchemaFields() join transfromField in transform.Fields on objectField.Id equals transfromField.Id into fields from knownField in fields.DefaultIfEmpty() select Field(transform, structVar, objectField.Id, objectField, knownField)); body.Add(transform.End); return Expression.Block( new [] { structVar }, body); }
public Expression Apply(ITransform transform) { pairs.Add(new TransformSchemaPair(transform, schema)); if (schema.HasBase) { schema = schema.GetBaseSchema(); transform.Base(this); } return(Expression.Empty()); }
public Expression Apply(ITransform transform) { pairs.Add(new TransformSchemaPair(transform, schema)); if (schema.HasBase) { schema = schema.GetBaseSchema(); transform.Base(this); } return Expression.Empty(); }
public Expression Apply(ITransform transform) { var fieldId = Expression.Variable(typeof(UInt16), "fieldId"); var fieldType = Expression.Variable(typeof(BondDataType), "fieldType"); var endLabel = Expression.Label("end"); var breakLoop = Expression.Break(endLabel); // (int)fieldType > (int)BT_STOP_BASE var notEndOrEndBase = Expression.GreaterThan( Expression.Convert(fieldType, typeof(int)), Expression.Constant((int)BondDataType.BT_STOP_BASE)); var notEnd = isBase ? notEndOrEndBase : Expression.NotEqual(fieldType, Expression.Constant(BondDataType.BT_STOP)); var isEndBase = Expression.Equal(fieldType, Expression.Constant(BondDataType.BT_STOP_BASE)); var body = new List <Expression> { isBase?reader.ReadBaseBegin() : reader.ReadStructBegin(), transform.Begin, transform.Base(baseParser), reader.ReadFieldBegin(fieldType, fieldId) }; // known fields body.AddRange( from f in transform.Fields select Expression.Loop( Expression.IfThenElse(notEndOrEndBase, Expression.Block( Expression.IfThenElse( Expression.Equal(fieldId, Expression.Constant(f.Id)), Expression.Block( f.Value(fieldParser, fieldType), reader.ReadFieldEnd(), reader.ReadFieldBegin(fieldType, fieldId), breakLoop), Expression.IfThenElse( Expression.GreaterThan(fieldId, Expression.Constant(f.Id)), Expression.Block( f.Omitted, breakLoop), transform.UnknownField(fieldParser, fieldType, fieldId) ?? Skip(fieldType))), reader.ReadFieldEnd(), reader.ReadFieldBegin(fieldType, fieldId), Expression.IfThen( Expression.GreaterThan(fieldId, Expression.Constant(f.Id)), breakLoop)), Expression.Block( f.Omitted, breakLoop)), endLabel)); // unknown fields body.Add( ControlExpression.While(notEnd, Expression.Block( Expression.IfThenElse( isEndBase, transform.UnknownEnd, Expression.Block( transform.UnknownField(fieldParser, fieldType, fieldId) ?? Skip(fieldType), reader.ReadFieldEnd())), reader.ReadFieldBegin(fieldType, fieldId)))); body.Add(isBase ? reader.ReadBaseEnd() : reader.ReadStructEnd()); body.Add(transform.End); return(Expression.Block( new[] { fieldType, fieldId }, body)); }