Exemplo n.º 1
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);
            }
        }
Exemplo n.º 2
0
 public override Type GetObjType(Type propertyType, string name)
 {
     if (IsMultiple)
     {
         if (ObjectType != null)
         {
             return(ObjectType);
         }
         else
         {
             return(ObjectUtil.GetListValueType(propertyType, name, this));
         }
     }
     else
     {
         return(base.GetObjType(propertyType, name));
     }
 }
Exemplo n.º 3
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);
                }
            }
        }