当前位置: 首页>>代码示例>>C#>>正文


C# JsonReader.CanReadObject方法代码示例

本文整理汇总了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);
        }
开发者ID:SparkSoftware,项目名称:infrastructure,代码行数:33,代码来源:CommandEnvelopeConverter.cs

示例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);
        }
开发者ID:SparkSoftware,项目名称:infrastructure,代码行数:38,代码来源:MessageConverter.cs

示例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);
        }
开发者ID:SparkSoftware,项目名称:infrastructure,代码行数:37,代码来源:EventVersionConverter.cs

示例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);
        }
开发者ID:SparkSoftware,项目名称:infrastructure,代码行数:33,代码来源:CommitDataConverter.cs

示例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;
        }
开发者ID:SparkSoftware,项目名称:infrastructure,代码行数:36,代码来源:StateObjectConverter.cs

示例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);
        }
开发者ID:SparkSoftware,项目名称:infrastructure,代码行数:41,代码来源:EventEnvelopeConverter.cs

示例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);
        }
开发者ID:SparkSoftware,项目名称:infrastructure,代码行数:24,代码来源:HeaderCollectionConverter.cs

示例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;
        }
开发者ID:SparkSoftware,项目名称:infrastructure,代码行数:25,代码来源:ValueObjectKeyedDictionaryConverter.cs


注:本文中的Newtonsoft.Json.JsonReader.CanReadObject方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。