Пример #1
0
        public void WriteDictionary(object writer, IDictionary receiver, BaseDictionaryAttribute attribute,
                                    string modelName, WriteSettings settings, QName root, object serializerData)
        {
            var info = new DictionaryListObjectPropertyInfo(receiver, attribute, root);

            attribute.WriteObject(this, writer, receiver, settings, info, serializerData);
        }
Пример #2
0
        public static void ReadObject(IObjectSerializer serializer, object reader,
                                      object receiver, string modelName, ReadSettings settings, QName root,
                                      BaseObjectAttribute attribute, object serializerData, SerializerOptions options)
        {
            if (receiver is IDictionary)
            {
                BaseDictionaryAttribute attr = attribute as BaseDictionaryAttribute;
                options.CheckReadDictionary(serializer, attr);
                if (attr == null)
                {
                    attr = GetDictionaryAttribute(receiver, root);
                }

                serializer.ReadDictionary(reader, receiver.Convert <IDictionary>(), attr,
                                          modelName, settings, root, serializerData);
            }
            else if (receiver is IList)
            {
                SimpleElementAttribute attr = attribute as SimpleElementAttribute;
                options.CheckReadList(serializer, attr);
                if (attr == null)
                {
                    Type valueType = ObjectUtil.GetListValueType(receiver.GetType(), "", null);
                    attr = GetElementAttribute(receiver, valueType);
                }
                serializer.ReadList(reader, receiver.Convert <IList>(), attr, modelName,
                                    settings, root, serializerData);
            }
            else
            {
                options.CheckReadObject(serializer);
                serializer.ReadObject(reader, receiver, modelName, settings, root, serializerData);
            }
        }
Пример #3
0
        public void CheckWriteDictionary(IObjectSerializer serializer, BaseDictionaryAttribute attribute)
        {
            if (!WriteDictionary)
            {
                throw new ToolkitException(string.Format(ObjectUtil.SysCulture,
                                                         "{0}不支持字典内容写到指定格式数据的操作", serializer), serializer);
            }

            CheckAttribute(serializer, attribute, CheckDictionaryAttribute);
        }
Пример #4
0
        public void CheckReadDictionary(IObjectSerializer serializer, BaseDictionaryAttribute attribute)
        {
            if (!ReadDictionary)
            {
                throw new ToolkitException(string.Format(ObjectUtil.SysCulture,
                                                         "{0}不支持读取数据存储到字典的操作", serializer), serializer);
            }

            CheckAttribute(serializer, attribute, CheckDictionaryAttribute);
        }
        public void WriteDictionary(object writer, IDictionary receiver, BaseDictionaryAttribute attribute,
                                    string modelName, WriteSettings settings, QName root, object serializerData)
        {
            var info = new DictionaryListObjectPropertyInfo(receiver, attribute, root);

            foreach (string key in receiver.Keys)
            {
                SetValue(writer, info, key, receiver[key], settings);
            }
        }
Пример #6
0
        public void WriteDictionary(object writer, IDictionary receiver, BaseDictionaryAttribute attribute,
                                    string modelName, WriteSettings settings, QName root, object serializerData)
        {
            SerializerUtil.CheckSimpleDictionary(attribute, this);

            DataRow row = writer.Convert <DataRow>();
            DataColumnCollection cols = row.Table.Columns;
            var info = new DictionaryListObjectPropertyInfo(receiver, attribute, root);
            DictionaryAttribute dictAttr = attribute.Convert <DictionaryAttribute>();

            foreach (DataColumn column in cols)
            {
                string columnName = column.ColumnName;

                SetValue(writer, columnName, receiver[columnName], info, settings);
            }
        }
        public void ReadDictionary(object reader, IDictionary receiver, BaseDictionaryAttribute attribute,
                                   string modelName, ReadSettings settings, QName root, object serializerData)
        {
            SerializerUtil.CheckSimpleDictionary(attribute, this);

            QueryStringBuilder builder = reader.Convert <QueryStringBuilder>();
            var info = new DictionaryListObjectPropertyInfo(receiver, attribute, root);
            DictionaryAttribute dictAttr = attribute.Convert <DictionaryAttribute>();

            foreach (string key in builder.AllKeys)
            {
                var    value    = builder[key];
                string strValue = value.ToString();
                receiver[key] = SerializerUtil.GetPropertyObject(receiver, settings,
                                                                 info, strValue, dictAttr.AutoTrim);
            }
        }
Пример #8
0
        public void ReadDictionary(object reader, IDictionary receiver, BaseDictionaryAttribute attribute,
                                   string modelName, ReadSettings settings, QName root, object serializerData)
        {
            SerializerUtil.CheckSimpleDictionary(attribute, this);

            DataRow row = reader.Convert <DataRow>();
            DataColumnCollection cols = row.Table.Columns;
            var info = new DictionaryListObjectPropertyInfo(receiver, attribute, root);
            DictionaryAttribute dictAttr = attribute.Convert <DictionaryAttribute>();

            foreach (DataColumn column in cols)
            {
                string columnName = column.ColumnName;

                receiver[columnName] = SerializerUtil.GetPropertyObject(receiver, settings,
                                                                        info, GetValue(reader, columnName), dictAttr.AutoTrim);
            }
        }
Пример #9
0
 public void WriteDictionary(object writer, IDictionary receiver, BaseDictionaryAttribute attribute,
                             string modelName, WriteSettings settings, QName root, object serializerData)
 {
     throw new NotImplementedException();
 }
Пример #10
0
 public void ReadDictionary(object reader, IDictionary receiver, BaseDictionaryAttribute attribute,
                            string modelName, ReadSettings settings, QName root, object serializerData)
 {
     throw new NotSupportedException();
 }
Пример #11
0
        public static void WriteObject(IObjectSerializer serializer, object writer,
                                       object receiver, string modelName, WriteSettings settings, QName root,
                                       BaseObjectAttribute attribute, object serializerData, SerializerOptions options)
        {
            Type type = receiver.GetType();

            if (receiver is IDictionary)
            {
                BaseDictionaryAttribute attr = attribute as BaseDictionaryAttribute;
                options.CheckWriteDictionary(serializer, attr);
                if (attr == null)
                {
                    attr = GetDictionaryAttribute(receiver, root);
                }
                serializer.WriteDictionary(writer, receiver.Convert <IDictionary>(), attr,
                                           modelName, settings, root, serializerData);
            }
            else if (type.IsArray || receiver is IList)
            {
                SimpleElementAttribute attr = attribute as SimpleElementAttribute;
                options.CheckWriteList(serializer, attr);
                if (attr == null)
                {
                    Type valueType;
                    if (type.IsArray)
                    {
                        Array arr = receiver as Array;
                        if (arr.Length == 0)
                        {
                            return;
                        }
                        var enumerator = arr.GetEnumerator();
                        enumerator.MoveNext();
                        valueType = enumerator.Current.GetType();
                    }
                    else
                    {
                        valueType = ObjectUtil.GetListValueType(type, "", null);
                    }
                    attr = GetElementAttribute(receiver, valueType);
                }
                serializer.WriteList(writer, receiver.Convert <IEnumerable>(), attr,
                                     modelName, settings, root, serializerData);
            }
            else
            {
                options.CheckWriteObject(serializer);
                ITkTypeConverter converter = TkTypeDescriptor.GetSimpleConverter(type);
                if (converter != null)
                {
                    SimpleElementAttribute simpleAttr = new SimpleElementAttribute
                    {
                        LocalName    = root.LocalName,
                        NamespaceUri = root.Namespace
                    };
                    var info = new SimpleObjectPropertyInfo(receiver, type, simpleAttr, converter);
                    serializer.WriteElement(simpleAttr, writer, receiver, settings, info, serializerData);
                }
                else
                {
                    serializer.WriteObject(writer, receiver, modelName, settings, root, serializerData);
                }
            }
        }
Пример #12
0
 public static void CheckSimpleDictionary(BaseDictionaryAttribute attribute, object sender)
 {
     TkDebug.Assert(attribute is DictionaryAttribute, string.Format(ObjectUtil.SysCulture,
                                                                    "{0}仅支持DictionaryAttribute,即Value值为简单对象", sender), sender);
 }