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


C# JsonDictionaryContract.InvokeOnDeserialized方法代码示例

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


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

示例1: PopulateDictionary

    private object PopulateDictionary(IWrappedDictionary dictionary, JsonReader reader, JsonDictionaryContract contract, string id)
    {
      if (id != null)
        Serializer.ReferenceResolver.AddReference(this, id, dictionary.UnderlyingDictionary);

      contract.InvokeOnDeserializing(dictionary.UnderlyingDictionary, Serializer.Context);

      int initialDepth = reader.Depth;

      do
      {
        switch (reader.TokenType)
        {
          case JsonToken.PropertyName:
            object keyValue = reader.Value;
            try
            {
              if (contract.DictionaryKeyContract == null)
                contract.DictionaryKeyContract = GetContractSafe(contract.DictionaryKeyType);
              
              try
              {
                keyValue = EnsureType(reader, keyValue, CultureInfo.InvariantCulture, contract.DictionaryKeyContract, contract.DictionaryKeyType);
              }
              catch (Exception ex)
              {
                throw CreateSerializationException(reader, "Could not convert string '{0}' to dictionary key type '{1}'. Create a TypeConverter to convert from the string to the key type object.".FormatWith(CultureInfo.InvariantCulture, reader.Value, contract.DictionaryKeyType), ex);
              }

              if (contract.DictionaryValueContract == null)
                contract.DictionaryValueContract = GetContractSafe(contract.DictionaryValueType);

              JsonConverter dictionaryValueConverter = GetConverter(contract.DictionaryValueContract, null);

              if (!ReadForType(reader, contract.DictionaryValueContract, dictionaryValueConverter != null, false))
                throw CreateSerializationException(reader, "Unexpected end when deserializing object.");

              dictionary[keyValue] = CreateValueNonProperty(reader, contract.DictionaryValueType, contract.DictionaryValueContract, dictionaryValueConverter);
            }
            catch (Exception ex)
            {
              if (IsErrorHandled(dictionary, contract, keyValue, reader.Path, ex))
                HandleError(reader, initialDepth);
              else
                throw;
            }
            break;
          case JsonToken.Comment:
            break;
          case JsonToken.EndObject:
            contract.InvokeOnDeserialized(dictionary.UnderlyingDictionary, Serializer.Context);

            return dictionary.UnderlyingDictionary;
          default:
            throw CreateSerializationException(reader, "Unexpected token when deserializing object: " + reader.TokenType);
        }
      } while (reader.Read());

      throw CreateSerializationException(reader, "Unexpected end when deserializing object.");
    }
开发者ID:bladefist,项目名称:Newtonsoft.Json,代码行数:60,代码来源:JsonSerializerInternalReader.cs

示例2: PopulateDictionary

        private object PopulateDictionary(IWrappedDictionary dictionary, JsonReader reader, JsonDictionaryContract contract, string id)
        {
            if (id != null)
            Serializer.ReferenceResolver.AddReference(id, dictionary.UnderlyingDictionary);

              contract.InvokeOnDeserializing(dictionary.UnderlyingDictionary, Serializer.Context);

              int initialDepth = reader.Depth;

              do
              {
            switch (reader.TokenType)
            {
              case JsonToken.PropertyName:
            object keyValue = EnsureType(reader.Value, contract.DictionaryKeyType);
            CheckedRead(reader);

            try
            {
              dictionary[keyValue] = CreateValue(reader, contract.DictionaryValueType, GetContractSafe(contract.DictionaryValueType), null, null);
            }
            catch (Exception ex)
            {
              if (IsErrorHandled(dictionary, contract, keyValue, ex))
                HandleError(reader, initialDepth);
              else
                throw;
            }
            break;
              case JsonToken.EndObject:
            contract.InvokeOnDeserialized(dictionary.UnderlyingDictionary, Serializer.Context);

            return dictionary.UnderlyingDictionary;
              default:
            throw new JsonSerializationException("Unexpected token when deserializing object: " + reader.TokenType);
            }
              } while (reader.Read());

              throw new JsonSerializationException("Unexpected end when deserializing object.");
        }
开发者ID:AndyStewart,项目名称:docsharp,代码行数:40,代码来源:JsonSerializerInternalReader.cs

示例3: PopulateDictionary

    private object PopulateDictionary(IWrappedDictionary wrappedDictionary, JsonReader reader, JsonDictionaryContract contract, JsonProperty containerProperty, string id)
    {
      object dictionary = wrappedDictionary.UnderlyingDictionary;

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

      contract.InvokeOnDeserializing(dictionary, Serializer.Context);

      int initialDepth = reader.Depth;

      if (contract.KeyContract == null)
        contract.KeyContract = GetContractSafe(contract.DictionaryKeyType);

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

      JsonConverter dictionaryValueConverter = contract.ItemConverter ?? GetConverter(contract.ItemContract, null, contract, containerProperty);

      bool finished = false;
      do
      {
        switch (reader.TokenType)
        {
          case JsonToken.PropertyName:
            object keyValue = reader.Value;
            try
            {
              try
              {
                keyValue = EnsureType(reader, keyValue, CultureInfo.InvariantCulture, contract.KeyContract, contract.DictionaryKeyType);
              }
              catch (Exception ex)
              {
                throw JsonSerializationException.Create(reader, "Could not convert string '{0}' to dictionary key type '{1}'. Create a TypeConverter to convert from the string to the key type object.".FormatWith(CultureInfo.InvariantCulture, reader.Value, contract.DictionaryKeyType), ex);
              }

              if (!ReadForType(reader, contract.ItemContract, dictionaryValueConverter != null))
                throw JsonSerializationException.Create(reader, "Unexpected end when deserializing object.");

              object itemValue;
              if (dictionaryValueConverter != null && dictionaryValueConverter.CanRead)
                itemValue = dictionaryValueConverter.ReadJson(reader, contract.DictionaryValueType, null, GetInternalSerializer());
              else
                itemValue = CreateValueInternal(reader, contract.DictionaryValueType, contract.ItemContract, null, contract, containerProperty, null);

              wrappedDictionary[keyValue] = itemValue;
            }
            catch (Exception ex)
            {
              if (IsErrorHandled(dictionary, contract, keyValue, reader.Path, ex))
                HandleError(reader, true, initialDepth);
              else
                throw;
            }
            break;
          case JsonToken.Comment:
            break;
          case JsonToken.EndObject:
            finished = true;
            break;
          default:
            throw JsonSerializationException.Create(reader, "Unexpected token when deserializing object: " + reader.TokenType);
        }
      } while (!finished && reader.Read());

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

      contract.InvokeOnDeserialized(dictionary, Serializer.Context);
      return dictionary;
    }
开发者ID:draptik,项目名称:RepoSync,代码行数:72,代码来源:JsonSerializerInternalReader.cs

示例4: PopulateDictionary

 private object PopulateDictionary(IWrappedDictionary wrappedDictionary, JsonReader reader, JsonDictionaryContract contract, JsonProperty containerProperty, string id)
 {
   object underlyingDictionary = wrappedDictionary.UnderlyingDictionary;
   if (id != null)
     this.AddReference(reader, id, underlyingDictionary);
   contract.InvokeOnDeserializing(underlyingDictionary, this.Serializer.Context);
   int depth = reader.Depth;
   if (contract.KeyContract == null)
     contract.KeyContract = this.GetContractSafe(contract.DictionaryKeyType);
   if (contract.ItemContract == null)
     contract.ItemContract = this.GetContractSafe(contract.DictionaryValueType);
   JsonConverter jsonConverter = contract.ItemConverter ?? this.GetConverter(contract.ItemContract, (JsonConverter) null, (JsonContainerContract) contract, containerProperty);
   bool flag = false;
   do
   {
     switch (reader.TokenType)
     {
       case JsonToken.PropertyName:
         object keyValue = reader.Value;
         try
         {
           try
           {
             keyValue = this.EnsureType(reader, keyValue, CultureInfo.InvariantCulture, contract.KeyContract, contract.DictionaryKeyType);
           }
           catch (Exception ex)
           {
             throw JsonSerializationException.Create(reader, StringUtils.FormatWith("Could not convert string '{0}' to dictionary key type '{1}'. Create a TypeConverter to convert from the string to the key type object.", (IFormatProvider) CultureInfo.InvariantCulture, reader.Value, (object) contract.DictionaryKeyType), ex);
           }
           if (!this.ReadForType(reader, contract.ItemContract, jsonConverter != null))
             throw JsonSerializationException.Create(reader, "Unexpected end when deserializing object.");
           object obj = jsonConverter == null || !jsonConverter.CanRead ? this.CreateValueInternal(reader, contract.DictionaryValueType, contract.ItemContract, (JsonProperty) null, (JsonContainerContract) contract, containerProperty, (object) null) : jsonConverter.ReadJson(reader, contract.DictionaryValueType, (object) null, (JsonSerializer) this.GetInternalSerializer());
           wrappedDictionary[keyValue] = obj;
           goto case JsonToken.Comment;
         }
         catch (Exception ex)
         {
           if (this.IsErrorHandled(underlyingDictionary, (JsonContract) contract, keyValue, reader.Path, ex))
           {
             this.HandleError(reader, true, depth);
             goto case JsonToken.Comment;
           }
           else
             throw;
         }
       case JsonToken.Comment:
         continue;
       case JsonToken.EndObject:
         flag = true;
         goto case JsonToken.Comment;
       default:
         throw JsonSerializationException.Create(reader, "Unexpected token when deserializing object: " + (object) reader.TokenType);
     }
   }
   while (!flag && reader.Read());
   if (!flag)
     this.ThrowUnexpectedEndException(reader, (JsonContract) contract, underlyingDictionary, "Unexpected end when deserializing object.");
   contract.InvokeOnDeserialized(underlyingDictionary, this.Serializer.Context);
   return underlyingDictionary;
 }
开发者ID:Zeludon,项目名称:FEZ,代码行数:60,代码来源:JsonSerializerInternalReader.cs

示例5: PopulateDictionary

        private IDictionary PopulateDictionary(IWrappedDictionary dictionary, JsonReader reader, JsonDictionaryContract contract, string id)
        {
            if (id != null)
            _serializer.ReferenceResolver.AddReference(id, dictionary.UnderlyingDictionary);

              contract.InvokeOnDeserializing(dictionary.UnderlyingDictionary);

              do
              {
            switch (reader.TokenType)
            {
              case JsonToken.PropertyName:
            object keyValue = EnsureType(reader.Value, contract.DictionaryKeyType);
            CheckedRead(reader);

            dictionary.Add(keyValue, CreateValue(reader, contract.DictionaryValueType, null, null));
            break;
              case JsonToken.EndObject:
            contract.InvokeOnDeserialized(dictionary.UnderlyingDictionary);

            return dictionary;
              default:
            throw new JsonSerializationException("Unexpected token when deserializing object: " + reader.TokenType);
            }
              } while (reader.Read());

              throw new JsonSerializationException("Unexpected end when deserializing object.");
        }
开发者ID:BGCX262,项目名称:zulu-omoto-pos-client-svn-to-git,代码行数:28,代码来源:JsonSerializerReader.cs


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