當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。