public void WriteNameValue(NameValue nameValue) { this.WriteText(nameValue.Name); this.WriteInt32((int)nameValue.Kind); switch (nameValue.Kind) { case NameValue.ValueKind.Text: this.WriteText(nameValue.GetValue <string>()); break; case NameValue.ValueKind.Int32: this.WriteInt32(nameValue.GetValue <int>()); break; case NameValue.ValueKind.Double: this.WriteDouble(nameValue.GetValue <double>()); break; case NameValue.ValueKind.Guid: this.WriteGuid(nameValue.GetValue <Guid>()); break; default: throw new ArgumentOutOfRangeException("NameValueKind is not supported".Formatted(nameValue.Kind)); } }
public void WriteNameValue(NameValue nameValue) { this.WriteText(nameValue.Name); this.WriteInt32((int)nameValue.Kind); switch (nameValue.Kind) { case NameValue.ValueKind.Text: this.WriteText(nameValue.GetValue<string>()); break; case NameValue.ValueKind.Int32: this.WriteInt32(nameValue.GetValue<int>()); break; case NameValue.ValueKind.Double: this.WriteDouble(nameValue.GetValue<double>()); break; case NameValue.ValueKind.Guid: this.WriteGuid(nameValue.GetValue<Guid>()); break; default: throw new ArgumentOutOfRangeException("NameValueKind is not supported".Formatted(nameValue.Kind)); } }
public void NameValueRoundTripTest() { var stream = new MemoryStream(); var fio = new FileIO(stream); var w = new FormattedWriter(fio); Guid g = new Guid("1116C195-8975-4E73-B777-23E1C548BC71"); const string testText = "some text with special characters €,@, ʤǤDŽƪҗ∰"; { var nv1 = new NameValue("name1", 1.23); var nv2 = new NameValue("name2", 722); var nv3 = new NameValue("name3", g); var nv4 = new NameValue("name4", testText); w.WriteNameValue(nv1); w.WriteNameValue(nv2); w.WriteNameValue(nv3); w.WriteNameValue(nv4); } stream.Position = 0; var r = new FormattedReader(fio); { var nv1 = r.ReadNameValue(); nv1.Name.Should().Be("name1"); nv1.GetValue<double>().Should().Be(1.23); nv1.Kind.Should().Be(NameValue.ValueKind.Double); var nv2 = r.ReadNameValue(); nv2.Name.Should().Be("name2"); nv2.GetValue<int>().Should().Be(722); nv2.Kind.Should().Be(NameValue.ValueKind.Int32); var nv3 = r.ReadNameValue(); nv3.Name.Should().Be("name3"); nv3.GetValue<Guid>().Should().Be(g); nv3.Kind.Should().Be(NameValue.ValueKind.Guid); var nv4 = r.ReadNameValue(); nv4.Name.Should().Be("name4"); nv4.GetValue<string>().Should().Be(testText); nv4.Kind.Should().Be(NameValue.ValueKind.Text); } }
public void GetValue() { nameValue.GetValue("a"); }