public static void TypedConstant(this LiteralEncoder encoder, TypedConstant constant) { switch (constant.Kind) { case TypedConstantKind.Primitive: encoder.Scalar().Constant(constant.Value); break; case TypedConstantKind.Enum: encoder.Scalar().Constant(constant.Value); break; // This looks more correct, but the code above matches what the C# compiler produces // encoder.TaggedScalar( // type => type.Enum(constant.Type.ToString()), // scalar => scalar.Constant(constant.Value) //); case TypedConstantKind.Type: encoder.Scalar().SystemType(constant.Type.ToString()); break; case TypedConstantKind.Array: { LiteralsEncoder arrayEncoder = encoder.Vector().Count(constant.Values.Length); foreach (var arrayConstant in constant.Values) { arrayEncoder.AddLiteral().TypedConstant(arrayConstant); } break; } } }
public void LiteralsEncoder_Scalar() { var b = new BlobBuilder(); var e = new LiteralsEncoder(b); Assert.Same(b, e.Builder); var s = e.AddLiteral(); AssertEx.Equal(new byte[0], b.ToArray()); Assert.Same(b, s.Builder); }