示例#1
0
        public void ReadObjectDictionary(ObjectDictionaryAttribute attribute, object reader,
                                         object receiver, ReadSettings settings, ObjectPropertyInfo info, object serializerData)
        {
            DataTable table = serializerData.Convert <DataTable>();

            if (table.Rows.Count != 1)
            {
                return;
            }
            DataRow     row  = table.Rows[0];
            IDictionary dict = attribute.GetDictionary(receiver, info);

            foreach (DataColumn column in table.Columns)
            {
                //dict[column.ColumnName] = row[column];
                object rowValue = row[column];
                string xml      = rowValue == DBNull.Value ? null : rowValue.ToString();
                if (string.IsNullOrEmpty(xml))
                {
                    dict[column.ColumnName] = null;
                }
                else
                {
                    Type   objectType = info.ObjectType;
                    object subObject  = attribute.UseConstructor ?
                                        ObjectUtil.CreateObjectWithCtor(objectType) : ObjectUtil.CreateObject(objectType);
                    subObject.ReadXml(info.ModelName, xml, settings, QName.ToolkitNoNS);
                    dict[column.ColumnName] = subObject;
                }
            }
        }
示例#2
0
        private object ReadObject(bool usector, ReadSettings settings, JsonTextReader jsonReader,
                                  Type objectType, object receiver, string modelName)
        {
            object subObject = usector ? ObjectUtil.CreateObjectWithCtor(objectType)
                : ObjectUtil.CreateObject(objectType);

            //InternalRead(jsonReader, subObject, modelName, settings);
            //允许递归调用,内嵌的如果不是对象,是数组或者Dictionary,都支持了
            Read(jsonReader, subObject, modelName, settings, null, null);
            SerializerUtil.SetParent(receiver, subObject);
            return(subObject);
        }
示例#3
0
        public void ReadObjectElement(ObjectElementAttribute attribute, object reader,
                                      object receiver, ReadSettings settings, ObjectPropertyInfo info, object serializerData)
        {
            Type   objectType = info.ObjectType;
            object subObject  = attribute.UseConstructor ? ObjectUtil.CreateObjectWithCtor(objectType)
                : ObjectUtil.CreateObject(objectType);

            Read(reader, subObject, info.ModelName, settings, info.QName, null);
            SerializerUtil.SetParent(receiver, subObject);

            SerializerUtil.AddElementValue(attribute, receiver, info, subObject);
        }
示例#4
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;
                    }
                }
            }
        }
示例#5
0
        private static object ReadObject(bool usector, ReadSettings settings, DataRow row,
                                         Type objectType, object receiver, IObjectSerializer datarowSerializer, string modelName)
        {
            object subObject = usector ? ObjectUtil.CreateObjectWithCtor(objectType)
                : ObjectUtil.CreateObject(objectType);
            object rowReader = datarowSerializer.CreateCustomReader(row);

            datarowSerializer.ReadObject(rowReader, subObject, modelName, settings, QName.Toolkit, null);
            SerializerUtil.SetParent(receiver, subObject);

            return(subObject);
        }
示例#6
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;
                }
            }
        }
示例#7
0
        public void ReadObjectDictionary(ObjectDictionaryAttribute 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);
            Type        objectType = info.ObjectType;

            if (xml.IsEmptyElement)
            {
                return;
            }

            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);
                    object subObject = attribute.UseConstructor ? ObjectUtil.CreateObjectWithCtor(objectType)
                        : ObjectUtil.CreateObject(objectType);
                    Read(reader, subObject, info.ModelName, settings, nodeName, null);
                    SerializerUtil.SetParent(receiver, subObject);

                    //string nodeValue = ReadString(xml);
                    //object objValue = SerializerUtil.GetPropertyObject(receiver, settings,
                    //    info, nodeValue, objectType);
                    dict[nodeName.LocalName] = subObject;
                }
            }
        }
示例#8
0
        public void ReadObjectDictionary(ObjectDictionaryAttribute 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);
            Type         objectType  = info.ObjectType;

            foreach (XElement child in current.Elements())
            {
                string nodeName  = child.Name.LocalName;
                object subObject = attribute.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;
            }
        }
示例#9
0
        public void ReadObjectElement(ObjectElementAttribute attribute, object reader, object receiver,
                                      ReadSettings settings, ObjectPropertyInfo info, object serializerData)
        {
            if (attribute.IsMultiple)
            {
                throw new NotSupportedException();
            }

            string xml = GetValue(reader, info.LocalName);

            if (string.IsNullOrEmpty(xml))
            {
                SerializerUtil.AddElementValue(attribute, receiver, info, null);
            }
            else
            {
                Type   objectType = info.ObjectType;
                object subObject  = attribute.UseConstructor ? ObjectUtil.CreateObjectWithCtor(objectType)
                    : ObjectUtil.CreateObject(objectType);
                subObject.ReadXml(xml, settings, QName.ToolkitNoNS);
                SerializerUtil.AddElementValue(attribute, receiver, info, subObject);
                SerializerUtil.SetParent(receiver, subObject);
            }
        }