本文整理汇总了C#中ODocument.Serialize方法的典型用法代码示例。如果您正苦于以下问题:C# ODocument.Serialize方法的具体用法?C# ODocument.Serialize怎么用?C# ODocument.Serialize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ODocument
的用法示例。
在下文中一共展示了ODocument.Serialize方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ShouldSerializeNumbers
public void ShouldSerializeNumbers()
{
string recordString = "[email protected]:123b,ShortNumber:1234s,IntNumber:123456,LongNumber:12345678901l,FloatNumber:3.14f,DoubleNumber:3.14d,DecimalNumber:1234567.8901c,embedded:(ByteNumber:123b,ShortNumber:1234s,IntNumber:123456,LongNumber:12345678901l,FloatNumber:3.14f,DoubleNumber:3.14d,DecimalNumber:1234567.8901c)";
ODocument document = new ODocument()
.SetField("@ClassName", "TestClass")
.SetField("ByteNumber", byte.Parse("123"))
.SetField("ShortNumber", short.Parse("1234"))
.SetField("IntNumber", 123456)
.SetField("LongNumber", 12345678901)
.SetField("FloatNumber", 3.14f)
.SetField("DoubleNumber", 3.14)
.SetField("DecimalNumber", new Decimal(1234567.8901))
.SetField("embedded.ByteNumber", byte.Parse("123"))
.SetField("embedded.ShortNumber", short.Parse("1234"))
.SetField("embedded.IntNumber", 123456)
.SetField("embedded.LongNumber", 12345678901)
.SetField("embedded.FloatNumber", 3.14f)
.SetField("embedded.DoubleNumber", 3.14)
.SetField("embedded.DecimalNumber", new Decimal(1234567.8901));
string serializedRecord = document.Serialize();
Assert.AreEqual(serializedRecord, recordString);
}
示例2: ShouldSerializeNull
public void ShouldSerializeNull()
{
string recordString = "[email protected]:,embedded:(null:)";
ODocument document = new ODocument()
.SetField("@ClassName", "TestClass")
.SetField<object>("null", null)
.SetField<object>("embedded.null", null);
string serializedRecord = document.Serialize();
Assert.AreEqual(serializedRecord, recordString);
}
示例3: ShouldNotSerializeFieldsWithAtCharacter
public void ShouldNotSerializeFieldsWithAtCharacter()
{
string recordString = "[email protected]:true";
ODocument document = new ODocument()
.SetField("@ClassName", "TestClass")
.SetField("@ClassId", 123)
.SetField("@Foo", "bar")
.SetField("@ORID", new ORID(8, 0))
.SetField<bool>("foo", true);
string serializedRecord = document.Serialize();
Assert.AreEqual(serializedRecord, recordString);
}
示例4: ShouldSerializeBoolean
public void ShouldSerializeBoolean()
{
string recordString = "[email protected]:true,isFalse:false,embedded:(isTrue:true,isFalse:false),array:[true,false]";
ODocument document = new ODocument()
.SetField("@ClassName", "TestClass")
.SetField("isTrue", true)
.SetField("isFalse", false)
.SetField("embedded.isTrue", true)
.SetField("embedded.isFalse", false)
.SetField<List<bool>>("array", new List<bool> { true, false });
string serializedRecord = document.Serialize();
Assert.AreEqual(serializedRecord, recordString);
}
示例5: ShouldSerializeDateTime
public void ShouldSerializeDateTime()
{
DateTime dateTime = DateTime.Now;
// get Unix time version
DateTime unixEpoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
string timeString = ((long)((DateTime)dateTime - unixEpoch).TotalMilliseconds).ToString();
string recordString = "[email protected]:" + timeString + "t,embedded:(DateTime:" + timeString + "t)";
ODocument document = new ODocument()
.SetField("@ClassName", "TestClass")
.SetField("DateTime", dateTime)
.SetField("embedded.DateTime", dateTime);
string serializedRecord = document.Serialize();
Assert.AreEqual(serializedRecord, recordString);
}
示例6: ShouldSerializeSetOfORIDs
public void ShouldSerializeSetOfORIDs()
{
string recordString = "[email protected]:#8:0,Set:<#8:1,#8:2>,embedded:(Set:<#9:1,#9:2>)";
ODocument document = new ODocument()
.SetField("@ClassName", "TestClass")
.SetField("Single", new ORID(8, 0))
.SetField("Set", new HashSet<ORID> { new ORID(8, 1), new ORID(8, 2) })
.SetField("embedded.Set", new HashSet<ORID> { new ORID(9, 1), new ORID(9, 2) });
string serializedString = document.Serialize();
Assert.AreEqual(serializedString, recordString);
}
示例7: ShouldSerializeListOfORIDs
public void ShouldSerializeListOfORIDs()
{
string recordString = "[email protected]:#8:0,Array:[#8:1,#8:2],embedded:(Array:[#9:1,#9:2])";
ODocument document = new ODocument()
.SetField("@ClassName", "TestClass")
.SetField("Single", new ORID(8, 0))
.SetField("Array", new List<ORID> { new ORID(8, 1), new ORID(8, 2) })
.SetField("embedded.Array", new List<ORID> { new ORID(9, 1), new ORID(9, 2) });
string serializedString = document.Serialize();
Assert.AreEqual(serializedString, recordString);
}
示例8: ShouldSerializeStrings
public void ShouldSerializeStrings()
{
string recordString = "[email protected]:\"Bra\\" + "\"vo \\\\ asdf\",Array:[\"foo\",\"bar\"],embedded:(String:\"Bra\\" + "\"vo \\\\ asdf\",Array:[\"foo\",\"bar\"])";
ODocument document = new ODocument()
.SetField("@ClassName", "TestClass")
.SetField("String", "Bra\"vo \\ asdf")
.SetField("Array", new List<string> { "foo", "bar" })
.SetField("embedded.String", "Bra\"vo \\ asdf")
.SetField("embedded.Array", new List<string> { "foo", "bar" });
string serializedString = document.Serialize();
Assert.AreEqual(serializedString, recordString);
}