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


C# JsonReader.Skip方法代码示例

本文整理汇总了C#中JsonReader.Skip方法的典型用法代码示例。如果您正苦于以下问题:C# JsonReader.Skip方法的具体用法?C# JsonReader.Skip怎么用?C# JsonReader.Skip使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在JsonReader的用法示例。


在下文中一共展示了JsonReader.Skip方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ReadJson

    /// <summary>
    /// Reads the JSON representation of the object.
    /// </summary>
    /// <param name="reader">The <see cref="JsonReader"/> to read from.</param>
    /// <param name="objectType">Type of the object.</param>
    /// <param name="existingValue">The existing value of object being read.</param>
    /// <param name="serializer">The calling serializer.</param>
    /// <returns>The object value.</returns>
    public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
    {
      bool isNullable = ReflectionUtils.IsNullableType(objectType);

      if (reader.TokenType == JsonToken.Null)
      {
        if (!isNullable)
          throw new Exception("Could not deserialize Null to KeyValuePair.");

        return null;
      }

      Type t = (isNullable)
       ? Nullable.GetUnderlyingType(objectType)
       : objectType;

      IList<Type> genericArguments = t.GetGenericArguments();
      Type keyType = genericArguments[0];
      Type valueType = genericArguments[1];

      object key = null;
      object value = null;

      reader.Read();

      while (reader.TokenType == JsonToken.PropertyName)
      {
        switch (reader.Value.ToString())
        {
          case "Key":
            reader.Read();
            key = serializer.Deserialize(reader, keyType);
            break;
          case "Value":
            reader.Read();
            value = serializer.Deserialize(reader, valueType);
            break;
          default:
            reader.Skip();
            break;
        }

        reader.Read();
      }

      return ReflectionUtils.CreateInstance(t, key, value);
    }
开发者ID:techtronics,项目名称:mapreduce-net,代码行数:55,代码来源:KeyValuePairConverter.cs

示例2: ReadJson

 // Token: 0x0600019F RID: 415
 // RVA: 0x0002BCE4 File Offset: 0x00029EE4
 public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
 {
     bool flag;
     Type key = (flag = ReflectionUtils.IsNullableType(objectType)) ? Nullable.GetUnderlyingType(objectType) : objectType;
     ReflectionObject reflectionObject = KeyValuePairConverter.ReflectionObjectPerType.Get(key);
     if (reader.TokenType != JsonToken.Null)
     {
         object obj = null;
         object obj2 = null;
         KeyValuePairConverter.ReadAndAssert(reader);
         while (reader.TokenType == JsonToken.PropertyName)
         {
             string a = reader.Value.ToString();
             if (string.Equals(a, "Key", StringComparison.OrdinalIgnoreCase))
             {
                 KeyValuePairConverter.ReadAndAssert(reader);
                 obj = serializer.Deserialize(reader, reflectionObject.GetType("Key"));
             }
             else if (string.Equals(a, "Value", StringComparison.OrdinalIgnoreCase))
             {
                 KeyValuePairConverter.ReadAndAssert(reader);
                 obj2 = serializer.Deserialize(reader, reflectionObject.GetType("Value"));
             }
             else
             {
                 reader.Skip();
             }
             KeyValuePairConverter.ReadAndAssert(reader);
         }
         return reflectionObject.Creator(new object[]
         {
             obj,
             obj2
         });
     }
     if (!flag)
     {
         throw JsonSerializationException.Create(reader, "Cannot convert null value to KeyValuePair.");
     }
     return null;
 }
开发者ID:newchild,项目名称:Project-DayZero,代码行数:43,代码来源:KeyValuePairConverter.cs

示例3: ImportFromObject

        protected override object ImportFromObject(ImportContext context, JsonReader reader)
        {
            Debug.Assert(context != null);
            Debug.Assert(reader != null);

            reader.Read();
            
            object o = Activator.CreateInstance(OutputType);
            
            while (reader.TokenClass != JsonTokenClass.EndObject)
            {
                string memberName = reader.ReadMember();
               
                PropertyDescriptor property = _properties.Find(memberName, true);
                
                if (property != null && !property.IsReadOnly)
                    property.SetValue(o, context.Import(property.PropertyType, reader));
                else 
                    reader.Skip();
            }
         
            return ReadReturning(reader, o);
        }
开发者ID:BackupTheBerlios,项目名称:jayrock-svn,代码行数:23,代码来源:ComponentImporter.cs

示例4: ImportValue

        protected override object ImportValue(JsonReader reader)
        {
            if (reader == null)
                throw new ArgumentNullException("reader");

            reader.ReadToken(JsonTokenClass.Object);
            
            object o = Activator.CreateInstance(OutputType);
            
            while (reader.TokenClass != JsonTokenClass.EndObject)
            {
                string memberName = reader.ReadMember();
               
                PropertyDescriptor property = _properties[memberName];
                
                if (property != null && !property.IsReadOnly)
                    property.SetValue(o, reader.ReadValue(property.PropertyType));
                else 
                    reader.Skip();
            }
         
            return o;
        }
开发者ID:BackupTheBerlios,项目名称:jayrock-svn,代码行数:23,代码来源:ComponentImporter.cs

示例5: SetPropertyValue

    private void SetPropertyValue(JsonProperty property, JsonConverter propertyConverter, JsonReader reader, object target)
    {
      if (property.Ignored)
      {
        reader.Skip();
        return;
      }

      object currentValue = null;
      bool useExistingValue = false;
      bool gottenCurrentValue = false;

      ObjectCreationHandling objectCreationHandling =
        property.ObjectCreationHandling.GetValueOrDefault(Serializer.ObjectCreationHandling);

      if ((objectCreationHandling == ObjectCreationHandling.Auto || objectCreationHandling == ObjectCreationHandling.Reuse)
        && (reader.TokenType == JsonToken.StartArray || reader.TokenType == JsonToken.StartObject)
          && property.Readable)
      {
        currentValue = property.ValueProvider.GetValue(target);
        gottenCurrentValue = true;

        useExistingValue = (currentValue != null
          && !property.PropertyType.IsArray
            && !ReflectionUtils.InheritsGenericDefinition(property.PropertyType, typeof (ReadOnlyCollection<>))
              && !property.PropertyType.IsValueType());
      }

      if (!property.Writable && !useExistingValue)
      {
        reader.Skip();
        return;
      }

      // test tokentype here because null might not be convertable to some types, e.g. ignoring null when applied to DateTime
      if (property.NullValueHandling.GetValueOrDefault(Serializer.NullValueHandling) == NullValueHandling.Ignore && reader.TokenType == JsonToken.Null)
      {
        reader.Skip();
        return;
      }

      // test tokentype here because default value might not be convertable to actual type, e.g. default of "" for DateTime
      if (HasFlag(property.DefaultValueHandling.GetValueOrDefault(Serializer.DefaultValueHandling), DefaultValueHandling.Ignore)
        && JsonReader.IsPrimitiveToken(reader.TokenType)
          && MiscellaneousUtils.ValueEquals(reader.Value, property.DefaultValue))
      {
        reader.Skip();
        return;
      }

      object existingValue = (useExistingValue) ? currentValue : null;
      object value = CreateValueProperty(reader, property, propertyConverter, target, gottenCurrentValue, existingValue);

      // always set the value if useExistingValue is false,
      // otherwise also set it if CreateValue returns a new value compared to the currentValue
      // this could happen because of a JsonConverter against the type
      if ((!useExistingValue || value != currentValue)
        && ShouldSetPropertyValue(property, value))
      {
        property.ValueProvider.SetValue(target, value);

        if (property.SetIsSpecified != null)
          property.SetIsSpecified(target, true);
      }
    }
开发者ID:bladefist,项目名称:Newtonsoft.Json,代码行数:65,代码来源:JsonSerializerInternalReader.cs

示例6: PopulateObject

    private object PopulateObject(object newObject, JsonReader reader, JsonObjectContract contract, string id)
    {
      contract.InvokeOnDeserializing(newObject, Serializer.Context);

      Dictionary<JsonProperty, PropertyPresence> propertiesPresence =
        contract.Properties.ToDictionary(m => m, m => PropertyPresence.None);

      if (id != null)
        Serializer.ReferenceResolver.AddReference(this, id, newObject);

      int initialDepth = reader.Depth;

      do
      {
        switch (reader.TokenType)
        {
          case JsonToken.PropertyName:
            {
              string memberName = reader.Value.ToString();

              try
              {
                // attempt exact case match first
                // then try match ignoring case
                JsonProperty property = contract.Properties.GetClosestMatchProperty(memberName);

                if (property == null)
                {
                  if (Serializer.MissingMemberHandling == MissingMemberHandling.Error)
                    throw CreateSerializationException(reader, "Could not find member '{0}' on object of type '{1}'".FormatWith(CultureInfo.InvariantCulture, memberName, contract.UnderlyingType.Name));

                  reader.Skip();
                  continue;
                }

                if (property.PropertyContract == null)
                  property.PropertyContract = GetContractSafe(property.PropertyType);

                JsonConverter propertyConverter = GetConverter(property.PropertyContract, property.MemberConverter);

                if (!ReadForType(reader, property.PropertyContract, propertyConverter != null, false))
                  throw CreateSerializationException(reader, "Unexpected end when setting {0}'s value.".FormatWith(CultureInfo.InvariantCulture, memberName));

                SetPropertyPresence(reader, property, propertiesPresence);

                SetPropertyValue(property, propertyConverter, reader, newObject);
              }
              catch (Exception ex)
              {
                if (IsErrorHandled(newObject, contract, memberName, reader.Path, ex))
                  HandleError(reader, initialDepth);
                else
                  throw;
              }
            }
            break;
          case JsonToken.EndObject:
            {
              foreach (KeyValuePair<JsonProperty, PropertyPresence> propertyPresence in propertiesPresence)
              {
                JsonProperty property = propertyPresence.Key;
                PropertyPresence presence = propertyPresence.Value;

                if (presence == PropertyPresence.None || presence == PropertyPresence.Null)
                {
                  try
                  {
                    switch (presence)
                    {
                      case PropertyPresence.None:
                        if (property.Required == Required.AllowNull || property.Required == Required.Always)
                          throw CreateSerializationException(reader, "Required property '{0}' not found in JSON.".FormatWith(CultureInfo.InvariantCulture, property.PropertyName));

                        if (property.PropertyContract == null)
                          property.PropertyContract = GetContractSafe(property.PropertyType);

                        if (HasFlag(property.DefaultValueHandling.GetValueOrDefault(Serializer.DefaultValueHandling), DefaultValueHandling.Populate)
                            && property.Writable)
                          property.ValueProvider.SetValue(newObject, EnsureType(reader, property.DefaultValue, CultureInfo.InvariantCulture, property.PropertyContract, property.PropertyType));
                        break;
                      case PropertyPresence.Null:
                        if (property.Required == Required.Always)
                          throw CreateSerializationException(reader, "Required property '{0}' expects a value but got null.".FormatWith(CultureInfo.InvariantCulture, property.PropertyName));
                        break;
                    }
                  }
                  catch (Exception ex)
                  {
                    if (IsErrorHandled(newObject, contract, property.PropertyName, reader.Path, ex))
                      HandleError(reader, initialDepth);
                    else
                      throw;
                  }
                }
              }

              contract.InvokeOnDeserialized(newObject, Serializer.Context);
              return newObject;
            }
          case JsonToken.Comment:
//.........这里部分代码省略.........
开发者ID:bladefist,项目名称:Newtonsoft.Json,代码行数:101,代码来源:JsonSerializerInternalReader.cs

示例7: ReadJson

        /// <summary>
        /// Reads the JSON representation of the object.
        /// </summary>
        /// <param name="reader">The <see cref="JsonReader"/> to read from.</param>
        /// <param name="objectType">Type of the object.</param>
        /// <param name="existingValue">The existing value of object being read.</param>
        /// <param name="serializer">The calling serializer.</param>
        /// <returns>The object value.</returns>
        internal override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            bool isNullable = ReflectionUtils.IsNullableType(objectType);

              if (reader.TokenType == JsonToken.Null)
              {
            if (!isNullable)
              throw JsonSerializationException.Create(reader, "Cannot convert null value to KeyValuePair.");

            return null;
              }

              Type t = (isNullable)
               ? Nullable.GetUnderlyingType(objectType)
               : objectType;

              IList<Type> genericArguments = t.GetGenericArguments();
              Type keyType = genericArguments[0];
              Type valueType = genericArguments[1];

              object key = null;
              object value = null;

              reader.Read();

              while (reader.TokenType == JsonToken.PropertyName)
              {
            string propertyName = reader.Value.ToString();
            if (string.Equals(propertyName, KeyName, StringComparison.OrdinalIgnoreCase))
            {
              reader.Read();
              key = serializer.Deserialize(reader, keyType);
            }
            else if (string.Equals(propertyName, ValueName, StringComparison.OrdinalIgnoreCase))
            {
              reader.Read();
              value = serializer.Deserialize(reader, valueType);
            }
            else
            {
              reader.Skip();
            }

            reader.Read();
              }

              return Activator.CreateInstance(t, key, value);
        }
开发者ID:theofanis,项目名称:dotnetwrapper,代码行数:56,代码来源:KeyValuePairConverter.cs

示例8: HandleError

        private void HandleError(JsonReader reader, bool readPastError, int initialDepth)
        {
            ClearErrorContext();

              if (readPastError)
              {
            reader.Skip();

            while (reader.Depth > (initialDepth + 1))
            {
              if (!reader.Read())
            break;
            }
              }
        }
开发者ID:rv192,项目名称:Fussen,代码行数:15,代码来源:JsonSerializerInternalReader.cs

示例9: SetExtensionData

        private void SetExtensionData(JsonObjectContract contract, JsonProperty member, JsonReader reader, string memberName, object o)
        {
            if (contract.ExtensionDataSetter != null)
              {
            try
            {
              object value = CreateValueInternal(reader, null, null, null, contract, member, null);

              contract.ExtensionDataSetter(o, memberName, value);
            }
            catch (Exception ex)
            {
              throw JsonSerializationException.Create(reader, "Error setting value in extension data for type '{0}'.".FormatWith(CultureInfo.InvariantCulture, contract.UnderlyingType), ex);
            }
              }
              else
              {
            reader.Skip();
              }
        }
开发者ID:rv192,项目名称:Fussen,代码行数:20,代码来源:JsonSerializerInternalReader.cs

示例10: PopulateList

        private object PopulateList(IList list, JsonReader reader, JsonArrayContract contract, JsonProperty containerProperty, string id)
        {
            IWrappedCollection wrappedCollection = list as IWrappedCollection;
              object underlyingList = wrappedCollection != null ? wrappedCollection.UnderlyingCollection : list;

              if (id != null)
            AddReference(reader, id, underlyingList);

              // can't populate an existing array
              if (list.IsFixedSize)
              {
            reader.Skip();
            return underlyingList;
              }

              OnDeserializing(reader, contract, underlyingList);

              int initialDepth = reader.Depth;

              if (contract.ItemContract == null)
            contract.ItemContract = GetContractSafe(contract.CollectionItemType);

              JsonConverter collectionItemConverter = GetConverter(contract.ItemContract, null, contract, containerProperty);

              int? previousErrorIndex = null;

              bool finished = false;
              do
              {
            try
            {
              if (ReadForType(reader, contract.ItemContract, collectionItemConverter != null))
              {
            switch (reader.TokenType)
            {
              case JsonToken.EndArray:
                finished = true;
                break;
              case JsonToken.Comment:
                break;
              default:
                object value;

                if (collectionItemConverter != null && collectionItemConverter.CanRead)
                  value = DeserializeConvertable(collectionItemConverter, reader, contract.CollectionItemType, null);
                else
                  value = CreateValueInternal(reader, contract.CollectionItemType, contract.ItemContract, null, contract, containerProperty, null);

                list.Add(value);
                break;
            }
              }
              else
              {
            break;
              }
            }
            catch (Exception ex)
            {
              JsonPosition errorPosition = reader.GetPosition(initialDepth);

              if (IsErrorHandled(underlyingList, contract, errorPosition.Position, reader as IJsonLineInfo, reader.Path, ex))
              {
            HandleError(reader, true, initialDepth);

            if (previousErrorIndex != null && previousErrorIndex == errorPosition.Position)
            {
              // reader index has not moved since previous error handling
              // break out of reading array to prevent infinite loop
              throw JsonSerializationException.Create(reader, "Infinite loop detected from error handling.", ex);
            }
            else
            {
              previousErrorIndex = errorPosition.Position;
            }
              }
              else
              {
            throw;
              }
            }
              } while (!finished);

              if (!finished)
            ThrowUnexpectedEndException(reader, contract, underlyingList, "Unexpected end when deserializing array.");

              OnDeserialized(reader, contract, underlyingList);
              return underlyingList;
        }
开发者ID:rv192,项目名称:Fussen,代码行数:89,代码来源:JsonSerializerInternalReader.cs

示例11: ResolvePropertyAndCreatorValues

        private List<CreatorPropertyContext> ResolvePropertyAndCreatorValues(JsonObjectContract contract, JsonProperty containerProperty, JsonReader reader, Type objectType)
        {
            List<CreatorPropertyContext> propertyValues = new List<CreatorPropertyContext>();
            bool exit = false;
            do
            {
                switch (reader.TokenType)
                {
                    case JsonToken.PropertyName:
                        string memberName = reader.Value.ToString();

                        CreatorPropertyContext creatorPropertyContext = new CreatorPropertyContext
                        {
                            Name = reader.Value.ToString(),
                            ConstructorProperty = contract.CreatorParameters.GetClosestMatchProperty(memberName),
                            Property = contract.Properties.GetClosestMatchProperty(memberName)
                        };
                        propertyValues.Add(creatorPropertyContext);

                        JsonProperty property = creatorPropertyContext.ConstructorProperty ?? creatorPropertyContext.Property;
                        if (property != null && !property.Ignored)
                        {
                            if (property.PropertyContract == null)
                            {
                                property.PropertyContract = GetContractSafe(property.PropertyType);
                            }

                            JsonConverter propertyConverter = GetConverter(property.PropertyContract, property.MemberConverter, contract, containerProperty);

                            if (!ReadForType(reader, property.PropertyContract, propertyConverter != null))
                            {
                                throw JsonSerializationException.Create(reader, "Unexpected end when setting {0}'s value.".FormatWith(CultureInfo.InvariantCulture, memberName));
                            }

                            if (propertyConverter != null && propertyConverter.CanRead)
                            {
                                creatorPropertyContext.Value = DeserializeConvertable(propertyConverter, reader, property.PropertyType, null);
                            }
                            else
                            {
                                creatorPropertyContext.Value = CreateValueInternal(reader, property.PropertyType, property.PropertyContract, property, contract, containerProperty, null);
                            }

                            continue;
                        }
                        else
                        {
                            if (!reader.Read())
                            {
                                throw JsonSerializationException.Create(reader, "Unexpected end when setting {0}'s value.".FormatWith(CultureInfo.InvariantCulture, memberName));
                            }

                            if (TraceWriter != null && TraceWriter.LevelFilter >= TraceLevel.Verbose)
                            {
                                TraceWriter.Trace(TraceLevel.Verbose, JsonPosition.FormatMessage(reader as IJsonLineInfo, reader.Path, "Could not find member '{0}' on {1}.".FormatWith(CultureInfo.InvariantCulture, memberName, contract.UnderlyingType)), null);
                            }

                            if (Serializer._missingMemberHandling == MissingMemberHandling.Error)
                            {
                                throw JsonSerializationException.Create(reader, "Could not find member '{0}' on object of type '{1}'".FormatWith(CultureInfo.InvariantCulture, memberName, objectType.Name));
                            }
                        }

                        if (contract.ExtensionDataSetter != null)
                        {
                            creatorPropertyContext.Value = ReadExtensionDataValue(contract, containerProperty, reader);
                        }
                        else
                        {
                            reader.Skip();
                        }
                        break;
                    case JsonToken.Comment:
                        break;
                    case JsonToken.EndObject:
                        exit = true;
                        break;
                    default:
                        throw JsonSerializationException.Create(reader, "Unexpected token when deserializing object: " + reader.TokenType);
                }
            } while (!exit && reader.Read());

            if (!exit)
            {
                ThrowUnexpectedEndException(reader, contract, null, "Unexpected end when deserializing object.");
            }

            return propertyValues;
        }
开发者ID:JamesNK,项目名称:Newtonsoft.Json,代码行数:89,代码来源:JsonSerializerInternalReader.cs

示例12: PopulateList

		private object PopulateList(IWrappedCollection wrappedList, JsonReader reader, string reference, JsonArrayContract contract)
		{
			object list = wrappedList.UnderlyingCollection;

			// can't populate an existing array
			if (wrappedList.IsFixedSize)
			{
				reader.Skip();
				return wrappedList.UnderlyingCollection;
			}

			if (reference != null)
				Serializer.ReferenceResolver.AddReference(this, reference, list);

			contract.InvokeOnDeserializing(list, Serializer.Context);

			int initialDepth = reader.Depth;

			while (ReadForTypeArrayHack(reader, contract.CollectionItemType))
			{
				switch (reader.TokenType)
				{
					case JsonToken.EndArray:
						contract.InvokeOnDeserialized(list, Serializer.Context);

						return wrappedList.UnderlyingCollection;
					case JsonToken.Comment:
						break;
					default:
						try
						{
							object value = CreateValueNonProperty(reader, contract.CollectionItemType, GetContractSafe(contract.CollectionItemType));

							wrappedList.Add(value);
						}
						catch (Exception ex)
						{
							if (IsErrorHandled(list, contract, wrappedList.Count, ex))
								HandleError(reader, initialDepth);
							else
								throw;
						}
						break;
				}
			}

			throw new JsonSerializationException("Unexpected end when deserializing array.");
		}
开发者ID:GregLukosek,项目名称:Crowd,代码行数:48,代码来源:JsonSerializerInternalReader.cs

示例13: ImportFromObject

        protected override object ImportFromObject(ImportContext context, JsonReader reader)
        {
            Debug.Assert(context != null);
            Debug.Assert(reader != null);

            reader.Read();
            
            object obj = Activator.CreateInstance(OutputType);
            INonObjectMemberImporter otherImporter = obj as INonObjectMemberImporter;
            
            while (reader.TokenClass != JsonTokenClass.EndObject)
            {
                string memberName = reader.ReadMember();
               
                PropertyDescriptor property = _properties.Find(memberName, true);
                
                //
                // Skip over the member value and continue with reading if
                // the property was not found or if the property found cannot
                // be set.
                //
                
                if (property == null || property.IsReadOnly)
                {
                    if (otherImporter == null || !otherImporter.Import(context, memberName, reader))
                        reader.Skip();
                    continue;
                }
                
                //
                // Check if the property defines a custom import scheme.
                // If yes, ask it to import the value into the property 
                // and then continue with the next.
                //
                
                if (_importers != null)
                {
                    int index = _properties.IndexOf(property);
                    
                    IObjectMemberImporter importer = _importers[index];
                    
                    if (importer != null)
                    {
                        importer.Import(context, reader, obj);
                        continue;
                    }
                }
                    
                //
                // Import from reader based on the property type and 
                // then set the value of the property.
                //
                
                property.SetValue(obj, context.Import(property.PropertyType, reader));
            }
         
            return ReadReturning(reader, obj);
        }
开发者ID:Ghawken,项目名称:FrontView,代码行数:58,代码来源:ComponentImporter.cs

示例14: ReadJson

        /// <summary>
        /// Reads the JSON representation of the object.
        /// </summary>
        /// <param name="reader">The <see cref="JsonReader"/> to read from.</param>
        /// <param name="objectType">Type of the object.</param>
        /// <param name="existingValue">The existing value of object being read.</param>
        /// <param name="serializer">The calling serializer.</param>
        /// <returns>The object value.</returns>
        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            bool isNullable = ReflectionUtils.IsNullableType(objectType);

            Type t = (isNullable)
                         ? Nullable.GetUnderlyingType(objectType)
                         : objectType;

            ReflectionObject reflectionObject = ReflectionObjectPerType.Get(t);

            if (reader.TokenType == JsonToken.Null)
            {
                if (!isNullable)
                    throw JsonSerializationException.Create(reader, "Cannot convert null value to Vector3.");

                return null;
            }

            object xValue = null;
            object yValue = null;
            object zValue = null;

            ReadAndAssert(reader);

            while (reader.TokenType == JsonToken.PropertyName)
            {
                string propertyName = reader.Value.ToString();
                if (string.Equals(propertyName, XName, StringComparison.OrdinalIgnoreCase))
                {
                    ReadAndAssert(reader);
                    xValue = serializer.Deserialize(reader, reflectionObject.GetType(XName));
                }
                else if (string.Equals(propertyName, YName, StringComparison.OrdinalIgnoreCase))
                {
                    ReadAndAssert(reader);
                    yValue = serializer.Deserialize(reader, reflectionObject.GetType(YName));
                }
                else if (string.Equals(propertyName, ZName, StringComparison.OrdinalIgnoreCase))
                {
                    ReadAndAssert(reader);
                    zValue = serializer.Deserialize(reader, reflectionObject.GetType(ZName));
                }
                else
                {
                    reader.Skip();
                }

                ReadAndAssert(reader);
            }

            return reflectionObject.Creator(xValue, yValue, zValue);
        }
开发者ID:createdbyx,项目名称:Newtonsoft.Json,代码行数:60,代码来源:Vector3Converter.cs

示例15: ReadJson

        /// <summary>
        /// Reads the JSON representation of the object.
        /// </summary>
        /// <param name="reader">The <see cref="JsonReader"/> to read from.</param>
        /// <param name="objectType">Type of the object.</param>
        /// <param name="existingValue">The existing value of object being read.</param>
        /// <param name="serializer">The calling serializer.</param>
        /// <returns>The object value.</returns>
        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            bool isNullable = ReflectionUtils.IsNullableType(objectType);

            Type t = (isNullable)
                         ? Nullable.GetUnderlyingType(objectType)
                         : objectType;

            ReflectionObject reflectionObject = ReflectionObjectPerType.Get(t);

            if (reader.TokenType == JsonToken.Null)
            {
                if (!isNullable)
                    throw JsonSerializationException.Create(reader, "Cannot convert null value to Matrix4x4.");

                return null;
            }

            object[] values = new object[PropNames.Length];

            ReadAndAssert(reader);

            while (reader.TokenType == JsonToken.PropertyName)
            {
                string propertyName = reader.Value.ToString();

                var index = Array.IndexOf(PropNames, propertyName);
                if (index != -1)
                {
                    var name = PropNames[index];
                    ReadAndAssert(reader);
                    values[index] = serializer.Deserialize(reader, reflectionObject.GetType(name));
                }
                else
                {
                    reader.Skip();
                }

                ReadAndAssert(reader);
            }

            var matrix = (Matrix4x4)reflectionObject.Creator();
            matrix.m00 = (float)values[0];
            matrix.m01 = (float)values[1];
            matrix.m02 = (float)values[2];
            matrix.m03 = (float)values[3];
            matrix.m10 = (float)values[4];
            matrix.m11 = (float)values[5];
            matrix.m12 = (float)values[6];
            matrix.m13 = (float)values[7];
            matrix.m20 = (float)values[8];
            matrix.m21 = (float)values[9];
            matrix.m22 = (float)values[10];
            matrix.m23 = (float)values[11];
            matrix.m30 = (float)values[12];
            matrix.m31 = (float)values[13];
            matrix.m32 = (float)values[14];
            matrix.m33 = (float)values[15];
            return matrix;
        }
开发者ID:createdbyx,项目名称:Newtonsoft.Json,代码行数:68,代码来源:Matrix4x4Converter.cs


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