private void DetectXmlAttributes(Type type) { if (_types.ContainsKey(type)) { return; } var classDescription = new ClassDescription(); _types.Add(type, classDescription); foreach (var pi in ReflectionUtils.FindProperiesWithAttribute <JsonSerialize>(type)) { if (ReflectionUtils.DoesThePropertyImplementTheInterface(pi.PropertyInfo.PropertyType, typeof(IList <byte>))) { var pd = new PdByteArray(pi.PropertyInfo, pi.AttributeInstance); classDescription.Attributes.Add(pi.PropertyInfo.Name, pd); } else if (ReflectionUtils.DoesThePropertyImplementTheInterface(pi.PropertyInfo.PropertyType, typeof(IDictionary))) { var pd = new PdDictionary(pi.PropertyInfo, pi.AttributeInstance); classDescription.Nodes.Add(pi.PropertyInfo.Name, pd); // Исследуем элемент словаря DetectXmlAttributes(pd.ItemFabric.Type); } else if (ReflectionUtils.DoesThePropertyImplementTheInterface(pi.PropertyInfo.PropertyType, typeof(IList))) { var pd = new PdList(pi.PropertyInfo, pi.AttributeInstance); classDescription.Nodes.Add(pi.PropertyInfo.Name, pd); // Исследуем элемент листа DetectXmlAttributes(pd.ItemFabric.Type); } else if (ReflectionUtils.IsSimpleType(pi.PropertyInfo.PropertyType) || (ReflectionUtils.IsNullableType(pi.PropertyInfo.PropertyType))) { classDescription.Attributes.Add(pi.PropertyInfo.Name, new PdSimple(pi.PropertyInfo, pi.AttributeInstance)); } else { var pd = new PdClass(pi.PropertyInfo, pi.AttributeInstance); classDescription.Nodes.Add(pi.PropertyInfo.Name, pd); // Исследуем член класса DetectXmlAttributes(pd.PropertyFabric.Type); } } }
private void DeserializeDict(object obj, PdDictionary pd, IJsonReader jsonReader) { var dict = (IDictionary)pd.PropertyFabric.CreateInstance(obj); var jsonData = jsonReader.ReadNext(); while (jsonData != null) { var key = pd.KeyFabric.StringToObject(jsonData.Name); var item = DeserializeListItem(pd, jsonData); dict.Add(key, item); jsonData = jsonReader.ReadNext(); } }
private void SerializeDict(object obj, PdDictionary pdDict, IJsonWriter jsonWriter) { var dict = pdDict.PropertyFabric.GetValue <IDictionary>(obj); if (dict == null) { jsonWriter.Write(pdDict.NodeName, null); } else { using (var jw = jsonWriter.WriteArray(pdDict.NodeName)) { foreach (var key in dict.Keys) { var keyStr = pdDict.KeyFabric.GetValueAsString(key); SerializeListItem(pdDict, dict[key], keyStr, jw); } } } }