本文整理汇总了C#中Newtonsoft.Json.JsonReader.CanReadObject方法的典型用法代码示例。如果您正苦于以下问题:C# JsonReader.CanReadObject方法的具体用法?C# JsonReader.CanReadObject怎么用?C# JsonReader.CanReadObject使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Newtonsoft.Json.JsonReader
的用法示例。
在下文中一共展示了JsonReader.CanReadObject方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ReadJson
/// <summary>
/// Reads the JSON representation of a <see cref="CommandEnvelope"/> instance.
/// </summary>
/// <param name="reader">The <see cref="JsonReader"/> to read from.</param>
/// <param name="objectType">The type of object.</param>
/// <param name="existingValue">The existing value of the object being read.</param>
/// <param name="serializer">The calling serializer.</param>
public override Object ReadJson(JsonReader reader, Type objectType, Object existingValue, JsonSerializer serializer)
{
if (!reader.CanReadObject())
return null;
var aggregateId = Guid.Empty;
var command = default(Command);
while (reader.Read() && reader.TokenType != JsonToken.EndObject)
{
String propertyName;
if (!reader.TryGetProperty(out propertyName))
continue;
switch (propertyName)
{
case "a":
aggregateId = serializer.Deserialize<Guid>(reader);
break;
case "c":
command = serializer.Deserialize<Command>(reader);
break;
}
}
return new CommandEnvelope(aggregateId, command);
}
示例2: ReadJson
/// <summary>
/// Reads the JSON representation of a <see cref="EventCollection"/> instance.
/// </summary>
/// <param name="reader">The <see cref="JsonReader"/> to read from.</param>
/// <param name="objectType">The type of object.</param>
/// <param name="existingValue">The existing value of the object being read.</param>
/// <param name="serializer">The calling serializer.</param>
public override Object ReadJson(JsonReader reader, Type objectType, Object existingValue, JsonSerializer serializer)
{
if (!reader.CanReadObject())
return null;
var id = Guid.Empty;
var payload = default(Object);
var headers = HeaderCollection.Empty;
var payloadType = KnownPayloadTypes[objectType];
while (reader.Read() && reader.TokenType != JsonToken.EndObject)
{
String propertyName;
if (!reader.TryGetProperty(out propertyName))
continue;
switch (propertyName)
{
case "id":
id = serializer.Deserialize<Guid>(reader);
break;
case "h":
headers = serializer.Deserialize<HeaderCollection>(reader);
break;
case "p":
payload = serializer.Deserialize(reader, payloadType);
break;
}
}
return Activator.CreateInstance(objectType, id, headers, payload);
}
示例3: ReadJson
/// <summary>
/// Reads the JSON representation of an <see cref="EventVersion"/> instance.
/// </summary>
/// <param name="reader">The <see cref="JsonReader"/> to read from.</param>
/// <param name="objectType">The type of object.</param>
/// <param name="existingValue">The existing value of the object being read.</param>
/// <param name="serializer">The calling serializer.</param>
public override Object ReadJson(JsonReader reader, Type objectType, Object existingValue, JsonSerializer serializer)
{
if (!reader.CanReadObject())
return null;
var item = 0;
var count = 0;
var version = 0;
while (reader.Read() && reader.TokenType != JsonToken.EndObject)
{
String propertyName;
if (!reader.TryGetProperty(out propertyName))
continue;
switch (propertyName)
{
case "v":
version = serializer.Deserialize<Int32>(reader);
break;
case "c":
count = serializer.Deserialize<Int32>(reader);
break;
case "i":
item = serializer.Deserialize<Int32>(reader);
break;
}
}
return new EventVersion(version, count, item);
}
示例4: ReadJson
/// <summary>
/// Reads the JSON representation of a <see cref="CommitData"/> instance.
/// </summary>
/// <param name="reader">The <see cref="JsonReader"/> to read from.</param>
/// <param name="objectType">The type of object.</param>
/// <param name="existingValue">The existing value of the object being read.</param>
/// <param name="serializer">The calling serializer.</param>
public override Object ReadJson(JsonReader reader, Type objectType, Object existingValue, JsonSerializer serializer)
{
if (!reader.CanReadObject())
return CommitData.Empty;
var events = EventCollection.Empty;
var headers = HeaderCollection.Empty;
while (reader.Read() && reader.TokenType != JsonToken.EndObject)
{
String propertyName;
if (!reader.TryGetProperty(out propertyName))
continue;
switch (propertyName)
{
case "h":
headers = serializer.Deserialize<HeaderCollection>(reader);
break;
case "e":
events = serializer.Deserialize<EventCollection>(reader);
break;
}
}
return new CommitData(headers, events);
}
示例5: ReadJson
/// <summary>
/// Reads the JSON representation of an <see cref="StateObject"/> instance.
/// </summary>
/// <param name="reader">The <see cref="JsonReader"/> to read from.</param>
/// <param name="objectType">The type of object.</param>
/// <param name="existingValue">The existing value of the object being read.</param>
/// <param name="serializer">The calling serializer.</param>
public override Object ReadJson(JsonReader reader, Type objectType, Object existingValue, JsonSerializer serializer)
{
if (!reader.CanReadObject())
return null;
var stateObject = default(StateObject);
var state = new Dictionary<String, Object>();
while (reader.Read() && reader.TokenType != JsonToken.EndObject)
{
var propertyName = String.Empty;
if (!reader.TryGetProperty(out propertyName))
continue;
if (propertyName == TypePropertyName)
{
objectType = Type.GetType(serializer.Deserialize<String>(reader), throwOnError: true, ignoreCase: true);
stateObject = (StateObject)FormatterServices.GetUninitializedObject(objectType);
}
else
{
stateObject = stateObject ?? (StateObject)FormatterServices.GetUninitializedObject(objectType);
state.Add(propertyName, serializer.Deserialize(reader, stateObject.GetFieldType(propertyName)));
}
}
stateObject?.SetState(state);
return stateObject;
}
示例6: ReadJson
/// <summary>
/// Reads the JSON representation of an <see cref="EventEnvelope"/> instance.
/// </summary>
/// <param name="reader">The <see cref="JsonReader"/> to read from.</param>
/// <param name="objectType">The type of object.</param>
/// <param name="existingValue">The existing value of the object being read.</param>
/// <param name="serializer">The calling serializer.</param>
public override Object ReadJson(JsonReader reader, Type objectType, Object existingValue, JsonSerializer serializer)
{
if (!reader.CanReadObject())
return null;
var e = default(Event);
var aggregateId = Guid.Empty;
var correlationId = Guid.Empty;
var version = EventVersion.Empty;
while (reader.Read() && reader.TokenType != JsonToken.EndObject)
{
String propertyName;
if (!reader.TryGetProperty(out propertyName))
continue;
switch (propertyName)
{
case "a":
aggregateId = serializer.Deserialize<Guid>(reader);
break;
case "v":
version = serializer.Deserialize<EventVersion>(reader);
break;
case "e":
e = serializer.Deserialize<Event>(reader);
break;
case "c":
correlationId = serializer.Deserialize<Guid>(reader);
break;
}
}
return new EventEnvelope(correlationId, aggregateId, version, e);
}
示例7: ReadJson
/// <summary>
/// Reads the JSON representation of a <see cref="HeaderCollection"/> instance.
/// </summary>
/// <param name="reader">The <see cref="JsonReader"/> to read from.</param>
/// <param name="objectType">The type of object.</param>
/// <param name="existingValue">The existing value of the object being read.</param>
/// <param name="serializer">The calling serializer.</param>
public override Object ReadJson(JsonReader reader, Type objectType, Object existingValue, JsonSerializer serializer)
{
if (!reader.CanReadObject())
return null;
var dictionary = new Dictionary<String, String>();
while (reader.Read() && reader.TokenType != JsonToken.EndObject)
{
String propertyName;
if (!reader.TryGetProperty(out propertyName))
continue;
dictionary.Add(propertyName, serializer.Deserialize<String>(reader));
}
return new HeaderCollection(dictionary);
}
示例8: ReadJson
/// <summary>
/// Reads the JSON representation of a <see cref="ValueObject"/> instance.
/// </summary>
/// <param name="reader">The <see cref="JsonReader"/> to read from.</param>
/// <param name="objectType">The type of object.</param>
/// <param name="existingValue">The existing value of the object being read.</param>
/// <param name="serializer">The calling serializer.</param>
public override Object ReadJson(JsonReader reader, Type objectType, Object existingValue, JsonSerializer serializer)
{
if (!reader.CanReadObject())
return null;
var genericTypes = GetGenericTypeArguments(objectType);
var dictionary = (IDictionary)Activator.CreateInstance(objectType);
while (reader.Read() && reader.TokenType != JsonToken.EndObject)
{
String propertyName;
if (!reader.TryGetProperty(out propertyName))
continue;
dictionary.Add(ValueObject.Parse(genericTypes.Key, propertyName), serializer.Deserialize(reader, genericTypes.Value));
}
return dictionary;
}