Пример #1
0
        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);
                }
            }
        }
Пример #2
0
        private void DeserializeList(object obj, PdList pd, IJsonReader jsonReader)
        {
            var list = (IList)pd.PropertyFabric.CreateInstance(obj);


            var jsonData = jsonReader.ReadNext();

            while (jsonData != null)
            {
                var item = DeserializeListItem(pd, jsonData);
                list.Add(item);
                jsonData = jsonReader.ReadNext();
            }
        }