Example #1
0
        private void InternalReadElement(XElementData reader, object receiver, ReadSettings settings,

                                         QName root, ObjectElementInfo elements, string modelName)
        {
            foreach (var item in reader.Current.Elements())
            {
                QName name = item.Name.ToQName();
                ObjectPropertyInfo element = elements.GetObjectPerpertyInfo(name,
                                                                            () => reader.Current.Attribute(ToolkitConst.VERSION).Value);
                if (element != null)
                {
                    XElementData next = new XElementData {
                        Current = item, Root = reader.Root
                    };
                    element.Attribute.ReadObject(this, next, receiver, settings, element, null);
                }
                else
                {
                    element = SerializerUtil.CustomRead(receiver, name.LocalName, modelName,
                                                        () => reader.Current.Attribute(ToolkitConst.VERSION).Value);
                    if (element != null)
                    {
                        element.Attribute.ReadObject(this, reader, receiver, settings, element, null);
                    }
                }
            }
        }
Example #2
0
        //private void InternalWriteXml(object writer, object receiver, string modelName,
        //    WriteSettings settings, PrefixTable prefixTable)
        //{
        //}

        private void InternalReadElement(XmlReader reader, object receiver, ReadSettings settings,
                                         QName root, ObjectElementInfo elements, string modelName)
        {
            while (reader.Read())
            {
                XmlNodeType nodeType = reader.NodeType;
                if (nodeType == XmlNodeType.EndElement)
                {
                    QName name = QName.Get(reader);
                    if (name == root)
                    {
                        break;
                    }
                }
                if (nodeType == XmlNodeType.Element)
                {
                    QName name = QName.Get(reader);
                    ObjectPropertyInfo element = elements.GetObjectPerpertyInfo(name,
                                                                                () => reader.GetAttribute(ToolkitConst.VERSION));
                    if (element != null)
                    {
                        element.Attribute.ReadObject(this, reader, receiver, settings, element, null);
                    }
                    else
                    {
                        element = SerializerUtil.CustomRead(receiver, name.LocalName, modelName,
                                                            () => reader.GetAttribute(ToolkitConst.VERSION));
                        if (element != null)
                        {
                            element.Attribute.ReadObject(this, reader, receiver, settings, element, null);
                        }
                    }
                }
            }
        }
Example #3
0
        private static void WriteChildElement(ObjectElementInfo elements, object obj,
                                              Func <object, IElementWriter, object> getValueFunc, Action <ObjectPropertyInfo, object> writeAction,
                                              Action <bool> nullAction, Action <IList> listAction)
        {
            var propertyList = elements.CreateOrderPropertyInfoList();

            foreach (var item in propertyList)
            {
                object value = getValueFunc(obj, item);
                if (value == null)
                {
                    if (nullAction != null)
                    {
                        nullAction(true);
                    }
                    continue;
                }
                ObjectPropertyInfo property;
                if (item.IsSingle)
                {
                    property = item.Content;
                }
                else
                {
                    if (item.IsValueMulitple)
                    {
                        IList list = value as IList;
                        if (list.Count == 0)
                        {
                            continue;
                        }
                        property = item.Get(list[0].GetType());
                    }
                    else
                    {
                        property = item.Get(value.GetType());
                    }
                }
                SimpleElementAttribute attribute = property.Attribute as SimpleElementAttribute;
                if (item.IsSingle)
                {
                    if (attribute == null)
                    {
                        writeAction(property, value);
                    }
                    else
                    {
                        WriteElement(attribute.IsMultiple, value, item,
                                     (propList, objectType) => property, writeAction, nullAction, listAction);
                    }
                }
                else
                {
                    //AssertElementAttribute(property, attribute);
                    WriteElement(attribute.IsMultiple, value, item,
                                 (propList, objectType) => propList.Get(objectType.GetType()),
                                 writeAction, nullAction, listAction);
                }
            }
        }
Example #4
0
 public static void WriteChildElement(IObjectSerializer serializer, object writer,
                                      ObjectElementInfo elements, WriteSettings settings, object obj,
                                      Func <object, IElementWriter, object> getValueFunc, object prefixTable)
 {
     WriteChildElement(elements, obj, getValueFunc,
                       (propertyInfo, objValue) => propertyInfo.Attribute.WriteObject(serializer,
                                                                                      writer, objValue, settings, propertyInfo, prefixTable), null, null);
 }
Example #5
0
 internal ObjectInfo()
 {
     fAttributes = new DictionaryList <ObjectPropertyInfo>();
     fElements   = new ObjectElementInfo();
 }
Example #6
0
 public TagElementAttribute()
 {
     fChildElements = new ObjectElementInfo();
 }
Example #7
0
 public static void CheckElementRequired(ObjectElementInfo elements, Object receiver)
 {
     elements.CheckRequired(receiver);
 }