本文整理汇总了C#中TestMessage.GetType方法的典型用法代码示例。如果您正苦于以下问题:C# TestMessage.GetType方法的具体用法?C# TestMessage.GetType怎么用?C# TestMessage.GetType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TestMessage
的用法示例。
在下文中一共展示了TestMessage.GetType方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Serializing_messages_with_json_dot_net
public void Serializing_messages_with_json_dot_net()
{
_message = new TestMessage
{
Name = "Joe",
Details = new List<TestMessageDetail>
{
new TestMessageDetail {Item = "A", Value = 27.5d},
new TestMessageDetail {Item = "B", Value = 13.5d},
},
};
_envelope = new Envelope
{
Message = _message,
};
_envelope.MessageType.Add(_message.GetType().ToMessageName());
_envelope.MessageType.Add(typeof(MessageA).ToMessageName());
_envelope.MessageType.Add(typeof(MessageB).ToMessageName());
_serializer = JsonMessageSerializer.Serializer;
_deserializer = JsonMessageSerializer.Deserializer;
using (var memoryStream = new MemoryStream())
using (var writer = new StreamWriter(memoryStream))
using (var jsonWriter = new JsonTextWriter(writer))
{
jsonWriter.Formatting = Formatting.Indented;
_serializer.Serialize(jsonWriter, _envelope);
writer.Flush();
_body = Encoding.UTF8.GetString(memoryStream.ToArray());
}
_xml = JsonConvert.DeserializeXNode(_body, "envelope");
}