本文整理汇总了C#中RiakObject.GetObject方法的典型用法代码示例。如果您正苦于以下问题:C# RiakObject.GetObject方法的具体用法?C# RiakObject.GetObject怎么用?C# RiakObject.GetObject使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类RiakObject
的用法示例。
在下文中一共展示了RiakObject.GetObject方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ObjectsAreConvertedProperly
public void ObjectsAreConvertedProperly()
{
var testPerson = new Person
{
DateOfBirth = new DateTime(1978, 12, 5, 0, 0, 0, DateTimeKind.Utc),
Email = "[email protected]",
Name = new Name
{
FirstName = "OJ",
Surname = "Reeves"
},
PhoneNumbers = new List<PhoneNumber>
{
new PhoneNumber
{
Number = "12345678",
NumberType = PhoneNumberType.Home
}
}
};
var obj = new RiakObject("bucket", "key");
obj.SetObject(testPerson);
obj.Value.ShouldNotBeNull();
obj.ContentType.ShouldEqual(RiakConstants.ContentTypes.ApplicationJson);
var json = obj.Value.FromRiakString();
json.ShouldEqual("{\"Name\":{\"FirstName\":\"OJ\",\"Surname\":\"Reeves\"},\"PhoneNumbers\":[{\"Number\":\"12345678\",\"NumberType\":1}],\"DateOfBirth\":\"1978-12-05T00:00:00Z\",\"Email\":\"[email protected]\"}");
var deserialisedPerson = obj.GetObject<Person>();
deserialisedPerson.ShouldEqual(testPerson);
}
示例2: CustomSerializerWillSerializeJson
public void CustomSerializerWillSerializeJson()
{
var testPerson = new Person
{
DateOfBirth = new DateTime(1978, 12, 5, 0, 0, 0, DateTimeKind.Utc),
Email = "[email protected]",
Name = new Name
{
FirstName = "OJ",
Surname = "Reeves"
},
PhoneNumbers = new List<PhoneNumber>
{
new PhoneNumber
{
Number = "12345678",
NumberType = PhoneNumberType.Home
}
}
};
var sots = new SerializeObjectToString<Person>(JsonConvert.SerializeObject);
var obj = new RiakObject("bucket", "key");
obj.SetObject(testPerson, RiakConstants.ContentTypes.ApplicationJson, sots);
obj.Value.ShouldNotBeNull();
obj.ContentType.ShouldEqual(RiakConstants.ContentTypes.ApplicationJson);
var json = obj.Value.FromRiakString();
json.ShouldEqual("{\"Name\":{\"FirstName\":\"OJ\",\"Surname\":\"Reeves\"},\"PhoneNumbers\":[{\"Number\":\"12345678\",\"NumberType\":1}],\"DateOfBirth\":\"\\/Date(281664000000)\\/\",\"Email\":\"[email protected]\"}");
var deserialisedPerson = obj.GetObject<Person>();
deserialisedPerson.ShouldEqual(testPerson);
}
示例3: JsonConversionTimerTest
public void JsonConversionTimerTest()
{
var testPerson = new Person
{
DateOfBirth = new DateTime(1978, 12, 5, 0, 0, 0, DateTimeKind.Utc),
Email = "[email protected]",
Name = new Name
{
FirstName = "OJ",
Surname = "Reeves"
},
PhoneNumbers = new List<PhoneNumber>
{
new PhoneNumber
{
Number = "12345678",
NumberType = PhoneNumberType.Home
}
}
};
var obj = new RiakObject("bucket", "key");
var sw = new Stopwatch();
sw.Start();
const int iterations = 1000000;
for (var i = 0; i < iterations; ++i)
{
obj.SetObject(testPerson);
}
sw.Stop();
Console.WriteLine("Serialisation took a total of {0} - {1} per iteration", sw.Elapsed, new TimeSpan(sw.ElapsedTicks / iterations));
sw.Reset();
sw.Start();
for (var i = 0; i < iterations; ++i)
{
var result = obj.GetObject<Person>();
}
sw.Stop();
Console.WriteLine("De" +
"serialisation took a total of {0} - {1} per iteration", sw.Elapsed, new TimeSpan(sw.ElapsedTicks / iterations));
}
示例4: NonJsonObjectsCantBeDeserialisedFromJson
public void NonJsonObjectsCantBeDeserialisedFromJson()
{
var obj = new RiakObject("bucket", "key", "{\"Name\":{\"FirstName\":\"OJ\",\"Surname\":\"Reeves\"},\"PhoneNumbers\":[{\"Number\":\"12345678\",\"NumberType\":1}],\"DateOfBirth\":\"1978-12-05T00:00:00Z\",\"Email\":\"[email protected]\"}", RiakConstants.ContentTypes.TextPlain);
obj.GetObject<Person>();
}