Ejemplo n.º 1
0
        public void ReadDynamicDictionary(DynamicDictionaryAttribute attribute, object reader,
                                          object receiver, ReadSettings settings, ObjectPropertyInfo info, object serializerData)
        {
            JsonTextReader jsonReader = reader.Convert <JsonTextReader>();

            AssertRead(jsonReader);
            AssertReadState(jsonReader, JsonToken.StartObject, info.PropertyName);
            IDictionary dict = attribute.GetDictionary(receiver, info);

            var configData = attribute.PlugInFactory.ConfigData;
            //var propertyInfo = info.Convert<ReflectorObjectPropertyInfo>().Property;
            var elementReader = new ConfigFactoryElementReader(attribute, info, info.ModelName);

            while (jsonReader.Read())
            {
                if (jsonReader.TokenType == JsonToken.EndObject)
                {
                    break;
                }
                AssertReadState(jsonReader, JsonToken.PropertyName, info.PropertyName);
                string name = jsonReader.Value.ToString();
                AssertRead(jsonReader);

                AssertReadState(jsonReader, JsonToken.StartObject, info.PropertyName);
                ObjectPropertyInfo subPropertyInfo = elementReader[name];
                Type   objectType     = subPropertyInfo.ObjectType;
                bool   useConstructor = subPropertyInfo.Attribute.Convert <ObjectElementAttribute>().UseConstructor;
                object subObject      = ReadObject(useConstructor, settings, jsonReader,
                                                   objectType, receiver, info.ModelName);
                dict[name] = subObject;
                //dict.Add(name, value);
            }
        }
Ejemplo n.º 2
0
        public void ReadDynamicDictionary(DynamicDictionaryAttribute attribute, object reader,
                                          object receiver, ReadSettings settings, ObjectPropertyInfo info, object serializerData)
        {
            XmlReader xml = reader.Convert <XmlReader>();

            QName       name = info.QName;
            IDictionary dict = attribute.GetDictionary(receiver, info);

            if (xml.IsEmptyElement)
            {
                return;
            }
            var configData = attribute.PlugInFactory.ConfigData;
            //var propertyInfo = info.Convert<ReflectorObjectPropertyInfo>().Property;
            var elementReader = new ConfigFactoryElementReader(attribute, info, info.ModelName);

            while (xml.Read())
            {
                if (xml.NodeType == XmlNodeType.EndElement)
                {
                    QName nodeName = QName.Get(xml);
                    if (nodeName == name)
                    {
                        return;
                    }
                }

                if (xml.NodeType == XmlNodeType.Element)
                {
                    QName nodeName = QName.Get(xml);
                    ObjectPropertyInfo subPropertyInfo;
                    if (elementReader.SupportVersion)
                    {
                        string version = xml.GetAttribute(ToolkitConst.VERSION);
                        subPropertyInfo = elementReader[nodeName, version];
                    }
                    else
                    {
                        subPropertyInfo = elementReader[nodeName];
                    }
                    if (subPropertyInfo != null)
                    {
                        ObjectElementAttribute elementAttr = subPropertyInfo.Attribute.Convert <ObjectElementAttribute>();
                        Type   objectType = elementAttr.ObjectType;
                        object subObject  = elementAttr.UseConstructor ? ObjectUtil.CreateObjectWithCtor(objectType)
                            : ObjectUtil.CreateObject(objectType);
                        Read(reader, subObject, info.ModelName, settings, nodeName, null);
                        SerializerUtil.SetParent(receiver, subObject);
                        dict[nodeName.LocalName] = subObject;
                    }
                }
            }
        }
Ejemplo n.º 3
0
        public void ReadDynamicDictionary(DynamicDictionaryAttribute attribute, object reader,
                                          object receiver, ReadSettings settings, ObjectPropertyInfo info, object serializerData)
        {
            XElementData currentData = reader.Convert <XElementData>();
            XElement     current     = currentData.Current;
            IDictionary  dict        = attribute.GetDictionary(receiver, info);
            var          configData  = attribute.PlugInFactory.ConfigData;
            //var propertyInfo = info.Convert<ReflectorObjectPropertyInfo>().Property;
            var elementReader = new ConfigFactoryElementReader(attribute, info, info.ModelName);

            foreach (XElement child in current.Elements())
            {
                string             nodeName = child.Name.LocalName;
                QName              qName    = child.Name.ToQName();
                ObjectPropertyInfo subPropertyInfo;
                if (elementReader.SupportVersion)
                {
                    var    verAttr = child.Attribute(ToolkitConst.VERSION);
                    string version = verAttr != null ? verAttr.Value : string.Empty;
                    subPropertyInfo = elementReader[nodeName, version];
                }
                else
                {
                    subPropertyInfo = elementReader[nodeName];
                }
                if (subPropertyInfo != null)
                {
                    ObjectElementAttribute elementAttr = subPropertyInfo.Attribute.Convert <ObjectElementAttribute>();
                    Type   objectType = elementAttr.ObjectType;
                    object subObject  = elementAttr.UseConstructor ? ObjectUtil.CreateObjectWithCtor(objectType)
                        : ObjectUtil.CreateObject(objectType);
                    XElementData next = new XElementData {
                        Current = child, Root = currentData.Root
                    };

                    Read(next, subObject, info.ModelName, settings, QName.Get(nodeName), null);
                    SerializerUtil.SetParent(receiver, subObject);
                    dict[nodeName] = subObject;
                }
            }
        }