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


C# JsonSerializer.Populate方法代码示例

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


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

示例1: ReadJson

		public override object ReadJson(JsonReader reader, Type objectType, object existingValue,
										JsonSerializer serializer)
		{
			if (reader.TokenType == JsonToken.StartArray)
			{
				var list = new List<ShardsSegment>();
				serializer.Populate(reader, list);
				return list.First();
			}

			var o = new ShardsSegment();
			serializer.Populate(reader, o);
			return o;
		}
开发者ID:modulexcite,项目名称:Transformalize,代码行数:14,代码来源:ShardsSegmentConverter.cs

示例2: ReadJson

        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            if (reader.TokenType == JsonToken.Null)
                return null;

            var keyType = objectType.GetGenericArguments()[0];
            var keyValueType = keyType.BaseType.GetGenericArguments()[0];
            var valueType = objectType.GetGenericArguments()[1];
            var intermediateDictionaryType = typeof(Dictionary<,>).MakeGenericType(typeof(string), valueType);
            var intermediateDictionary = (IDictionary)Activator.CreateInstance(intermediateDictionaryType);
            serializer.Populate(reader, intermediateDictionary);

            var valueProperty = keyType.GetProperty("Value");
            var finalDictionary = (IDictionary)Activator.CreateInstance(objectType);
            foreach (DictionaryEntry pair in intermediateDictionary)
            {
                object value;
                if (keyValueType == typeof(Guid))
                    value = Guid.Parse(pair.Key.ToString());
                else
                    value = Convert.ChangeType(pair.Key, keyValueType, null);

                var key = Activator.CreateInstance(keyType);
                valueProperty.SetValue(key, value, null);
                finalDictionary.Add(key, pair.Value);
            }
            return finalDictionary;
        }
开发者ID:LenFon,项目名称:Bifrost,代码行数:28,代码来源:ConceptDictionaryConverter.cs

示例3: ReadJson

		public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
		{
			var dict = new Dictionary<string, Dictionary<string, Dictionary<string, IndexSettings>>>();
			serializer.Populate(reader, dict);
			var response = new IndexSettingsResponse();
			if (!dict.HasAny() || !dict.First().Value.HasAny() || !dict.First().Value.First().Value.HasAny())
				return response;
			response.Nodes = dict.ToDictionary(k => k.Key, v => v.Value.First().Value.First().Value);
			return response;
		}
开发者ID:modulexcite,项目名称:Transformalize,代码行数:10,代码来源:IndexSettingsResponseConverter.cs

示例4: ReadJson

		public override object ReadJson(JsonReader reader, Type objectType, object existingValue,
										JsonSerializer serializer)
		{
			reader.Read();
			if (reader.TokenType != JsonToken.PropertyName)
				return null;

			var key = reader.Value as string;
			reader.Read();
			switch (key)
			{
				case "delete":
					var deleteItem = new BulkDeleteResponseItem();
					serializer.Populate(reader, deleteItem);
					if (deleteItem != null)
						deleteItem.Operation = key;
					reader.Read();
					return deleteItem;
				case "update":
					var updateItem = new BulkUpdateResponseItem();
					serializer.Populate(reader, updateItem);
					if (updateItem != null)
						updateItem.Operation = key;
					reader.Read();
					return updateItem;
				case "index":
					var indexItem = new BulkIndexResponseItem();
					serializer.Populate(reader, indexItem);
					if (indexItem != null)
						indexItem.Operation = key;
					reader.Read();
					return indexItem;
				case "create":
					var createItem = new BulkCreateResponseItem();
					serializer.Populate(reader, createItem);
					if (createItem != null)
						createItem.Operation = key;
					reader.Read();
					return createItem;
			}
			return null;
		}
开发者ID:modulexcite,项目名称:Transformalize,代码行数:42,代码来源:BulkOperationResponseItemConverter.cs

示例5: ReadJson

 /// <summary>
 ///     Reads the JSON representation of the object.
 /// </summary>
 /// <param name="reader">
 ///     The <see cref="T:Newtonsoft.Json.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)
 {
     if (reader.TokenType == JsonToken.Null)
         return null;
     object obj = Container.Resolve(objectType);
     if (obj == null)
         throw new JsonSerializationException("No object created.");
     serializer.Populate(reader, obj);
     return obj;
 }
开发者ID:holinov,项目名称:ZenEveCalc,代码行数:23,代码来源:AutofacCreationConverter.cs

示例6: ReadJson

		public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
		{
			if (reader.TokenType != JsonToken.StartObject) return null;
			reader.Read();
			if (reader.TokenType != JsonToken.PropertyName) return null;
			var prop = reader.Value;
			if ((string) reader.Value != "filter") return null;
			reader.Read();
			var agg = new FilterAggregator();
			serializer.Populate(reader, agg);
			return agg;
		}
开发者ID:modulexcite,项目名称:Transformalize,代码行数:12,代码来源:FilterAggregatorConverter.cs

示例7: ReadJson

        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            if (reader.TokenType == JsonToken.StartObject)
            {
                var denormalizedReference = new DenormalizedReference();
                serializer.Populate(reader, denormalizedReference);

                var referenceInstace = _generator.CreateClassProxyWithTarget(
                    denormalizedReference.ReferenceInstanceType,
                    new Type[] { typeof(IDynamicProxy) },
                    InstanceCreator.Create(denormalizedReference.ReferenceInstanceType),
                    new ReferenceInterceptor(denormalizedReference.Id, denormalizedReference.ReferenceInstanceType));

                return referenceInstace;
            }
            return null;
        }
开发者ID:vlko,项目名称:vlko,代码行数:17,代码来源:ReferenceConverter.cs

示例8: ReadJson

 /// <summary>
 ///     Reads the JSON representation of the object.
 /// </summary>
 /// <param name="reader">
 ///     The <see cref="T:Newtonsoft.Json.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)
 {
     if (reader.TokenType == JsonToken.Null)
         return null;
     using (var scope=Container.BeginScope())
     {
         object obj = scope.Resolve(objectType);
         if (obj == null)
             throw new JsonSerializationException("No object created.");
         serializer.Populate(reader, obj);
         /*RefrenceHacks.SkipRefrences = true;
         scope.Scope.InjectUnsetProperties(obj);
         RefrenceHacks.SkipRefrences = false;*/
         return obj;
     }
 }
开发者ID:holinov,项目名称:Zen.Core,代码行数:29,代码来源:AutofacCreationConverter.cs

示例9: ReadJson

		public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
		{
			JObject o = JObject.Load(reader);
			var result = existingValue as Dictionary<string, AnalyzerBase> ?? new Dictionary<string, AnalyzerBase>();

			foreach (var childProperty in o.Children<JProperty>())
			{
				var propertyName = childProperty.Name;
				var typeProperty = ((JObject)childProperty.Value).Property("type");
				typeProperty.Remove();

				var typePropertyValue = typeProperty.Value.ToString();
				Language language;
				if (Enum.TryParse(typePropertyValue, true, out language))
				{
					typePropertyValue = "Language";
				}

				var itemType = Type.GetType("Nest." + typePropertyValue + "Analyzer", false, true);
				AnalyzerBase item;
				if (itemType == typeof(LanguageAnalyzer))
				{
					item = new LanguageAnalyzer(language);
					serializer.Populate(childProperty.Value.CreateReader(), item);
				}
				else if (itemType != null)
				{
					item = serializer.Deserialize(childProperty.Value.CreateReader(), itemType) as AnalyzerBase;
				}
				else
				{
					continue;
				}

				result[propertyName] = item;
			}
			return result;
		}
开发者ID:modulexcite,项目名称:Transformalize,代码行数:38,代码来源:AnalyzerCollectionConverter.cs

示例10: PopulateDictionary

        public void PopulateDictionary()
        {
            Dictionary<string, string> p = new Dictionary<string, string>();

            JsonSerializer serializer = new JsonSerializer();
            serializer.Populate(new StringReader(@"{""Name"":""James""}"), p);

            Assert.AreEqual(1, p.Count);
            Assert.AreEqual("James", p["Name"]);
        }
开发者ID:TheHunter,项目名称:Newtonsoft.Json,代码行数:10,代码来源:PopulateTests.cs

示例11: PopulateListOfPeople

        public void PopulateListOfPeople()
        {
            List<Person> p = new List<Person>();

            JsonSerializer serializer = new JsonSerializer();
            serializer.Populate(new StringReader(@"[{""Name"":""James""},{""Name"":""Jim""}]"), p);

            Assert.AreEqual(2, p.Count);
            Assert.AreEqual("James", p[0].Name);
            Assert.AreEqual("Jim", p[1].Name);
        }
开发者ID:TheHunter,项目名称:Newtonsoft.Json,代码行数:11,代码来源:PopulateTests.cs

示例12: ReadJson

		public override object ReadJson(JsonReader reader, Type objectType, object existingValue,
										JsonSerializer serializer)
		{
			JObject o = JObject.Load(reader);
			var result = new IndexSettings();
			var dictionary = new Dictionary<string, object>();
			serializer.Populate(o.CreateReader(), dictionary);
			result.Settings = dictionary;
			result.AsExpando = DynamicDictionary.Create(dictionary);
			foreach (var rootProperty in o.Children<JProperty>())
			{
				if (rootProperty.Name.Equals("analysis", StringComparison.InvariantCultureIgnoreCase))
				{
					result.Analysis = serializer.Deserialize<AnalysisSettings>(rootProperty.Value.CreateReader());
					result.Settings.Remove(rootProperty.Name);
				}
				else if (rootProperty.Name.Equals("warmers", StringComparison.InvariantCultureIgnoreCase))
				{
					foreach (var jWarmer in rootProperty.Value.Children<JProperty>())
					{
						result.Warmers[jWarmer.Name] = serializer.Deserialize<WarmerMapping>(jWarmer.Value.CreateReader());
					}
					result.Settings.Remove(rootProperty.Name);
				}
				else if (rootProperty.Name.Equals("similarity", StringComparison.InvariantCultureIgnoreCase))
				{
					result.Similarity = serializer.Deserialize<SimilaritySettings>(rootProperty.Value.CreateReader());
					result.Settings.Remove(rootProperty.Name);
				}
			}
			return result;
		}
开发者ID:modulexcite,项目名称:Transformalize,代码行数:32,代码来源:IndexSettingsConverter.cs


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