Ejemplo n.º 1
0
        private void DeserializeNodeToCollection(IEnumerable <XElement> valueNodes, XmlDeserializeContext context, Action <int, object> action)
        {
            int i = 0;

            foreach (XElement item in valueNodes)
            {
                object itemData = null;

                string elementID = item.Attribute("v").Value;

                if (item.AttributeWithAlterName("isRef", "r", false) == true)
                {
                    XElement objectElement = GetObjectElementByID(context.RootElement, item.AttributeWithAlterName("value", "v", 0));
                    itemData = DeserializeNodeToObject(objectElement, false, context);
                }
                else
                {
                    Type type = context.GetTypeInfo(item.AttributeWithAlterName("ownerTypeID", "oti", string.Empty));

                    itemData = item.AttributeWithAlterName("value", "v", TypeCreator.GetTypeDefaultValue(type));

                    itemData = DataConverter.ChangeType(itemData, type);
                }

                action(i, itemData);

                i++;
            }
        }
Ejemplo n.º 2
0
        private void DeserializeNodesToProperties(XElement parent, object graph, XmlDeserializeContext context)
        {
            TypeFields tf = TypeFields.GetTypeFields(graph.GetType());

            foreach (KeyValuePair <TypeFieldInfo, ExtendedFieldInfo> kp in tf.Fields)
            {
                ExtendedFieldInfo efi = kp.Value;

                if (efi.IsNotSerialized == false && OnFieldCanXElementSerialize(efi))
                {
                    System.Type realType = efi.FieldInfo.FieldType;

                    var propertiesElement = from property in parent.Descendants("F")
                                            where (property.AttributeWithAlterName("name", "n", string.Empty) == efi.AlternateFieldName ||
                                                   property.AttributeWithAlterName("name", "n", string.Empty) == efi.FieldInfo.Name) &&
                                            context.TypeContext[property.AttributeWithAlterName("ownerTypeID", "oti", -1)] == kp.Key.ObjectType
                                            select property;

                    if (propertiesElement.FirstOrDefault() == null)
                    {
                        propertiesElement = from property in parent.Descendants("Field")
                                            where (property.AttributeWithAlterName("name", "n", string.Empty) == efi.AlternateFieldName ||
                                                   property.AttributeWithAlterName("name", "n", string.Empty) == efi.FieldInfo.Name) &&
                                            context.TypeContext[property.AttributeWithAlterName("ownerTypeID", "oti", -1)] == kp.Key.ObjectType
                                            select property;
                    }

                    XElement propertyElement = propertiesElement.FirstOrDefault();

                    if (propertyElement != null)
                    {
                        object data = null;

                        if (propertyElement.AttributeWithAlterName("isRef", "r", false) == true)
                        {
                            XElement objectElement = GetObjectElementByID(context.RootElement, propertyElement.AttributeWithAlterName("value", "v", 0));

                            if (objectElement != null)
                            {
                                bool ignoreError = propertyElement.Attribute("ide", false);

                                if (ignoreError == false)
                                {
                                    XElementFieldSerializeAttribute attr = AttributeHelper.GetCustomAttribute <XElementFieldSerializeAttribute>(efi.FieldInfo);

                                    if (attr != null)
                                    {
                                        ignoreError = attr.IgnoreDeserializeError;
                                    }
                                }

                                data = DeserializeNodeToObject(objectElement, ignoreError, context);

                                SetValueToObject(efi.FieldInfo, graph, data);
                            }
                        }
                        else
                        {
                            data = propertyElement.AttributeWithAlterName("value", "v", TypeCreator.GetTypeDefaultValue(realType));

                            if (Convertible(realType, data))
                            {
                                SetValueToObject(efi.FieldInfo, graph, ConvertData(efi.FieldInfo, data));
                            }
                        }
                    }
                }
            }

            DeserializeXmlSerilizableList(parent, graph, context);
        }