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); } }
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; } } } }
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; } } }
internal void ReadElementAttribute(Type type, PropertyInfo property, string modelName, object[] propertyAttributes) { object dynamicAttribute = (from attr in propertyAttributes where attr is DynamicElementAttribute select attr).FirstOrDefault(); if (dynamicAttribute != null) { DynamicElementAttribute attribute = dynamicAttribute as DynamicElementAttribute; BaseXmlConfigFactory factory = attribute.PlugInFactory; if (fXmlConfigFactories == null) { fXmlConfigFactories = new Dictionary <string, BaseXmlConfigFactory>(); } if (!fXmlConfigFactories.ContainsKey(factory.Name)) { fXmlConfigFactories.Add(factory.Name, factory); } //factory.AddElements(this, type, property, modelName, attribute); ReflectorObjectPropertyInfo objInfo = new ReflectorObjectPropertyInfo(property, attribute, modelName); var dyn = new ConfigFactoryElementReader(attribute, objInfo, modelName); fMultiElements.Add(dyn); fElementWriter.Add(dyn); } else { //foreach (var attr in propertyAttributes) //{ // if (attr is BaseDictionaryAttribute) // InternalAdd(type, property, attr as NamedAttribute, modelName); // else // { // SimpleElementAttribute eleAttr = attr as SimpleElementAttribute; // if (eleAttr != null) // AddAttribute(eleAttr, type, property, modelName); // } //} var objElemAttrs = (from item in propertyAttributes where item is ObjectElementAttribute select(ObjectElementAttribute) item).ToArray(); if (objElemAttrs.Length == 0) { foreach (var attr in propertyAttributes) { if (attr is BaseDictionaryAttribute) { AddSingleAttrible(type, property, attr as NamedAttribute, modelName); } else { SimpleElementAttribute eleAttr = attr as SimpleElementAttribute; if (eleAttr != null) { AddSingleAttrible(type, property, eleAttr, modelName); } } } } else if (objElemAttrs.Length == 1) { AddSingleAttrible(type, property, objElemAttrs[0], modelName); } else { var multi = new MultipleElementReader(property, modelName, objElemAttrs); fMultiElements.Add(multi); fElementWriter.Add(multi); } } }