예제 #1
0
        public UnknownTypeEventArgs(IPropertySerializationInfo property, string ns, string localName)
        {
            if (localName == null)
            {
                throw new ArgumentNullException(nameof(localName));
            }

            Namespace = ns;
            LocalName = localName;
            Property  = property;
        }
예제 #2
0
 protected override bool IsPropertyElement(XmlReader reader, IPropertySerializationInfo p)
 {
     if (string.IsNullOrEmpty(reader.Prefix))
     {
         if (string.IsNullOrEmpty(p.Namespace) && reader.LocalName == p.ElementName)
         {
             return(true);
         }
     }
     return(base.IsPropertyElement(reader, p));
 }
예제 #3
0
        public void BlockOpposite(object value, IPropertySerializationInfo property)
        {
            if (property == null || property.Opposite == null)
            {
                return;
            }
            var pair = new ObjectPropertyPair()
            {
                Object = value, Property = property.Opposite
            };

            blockedProperties.Add(pair);
        }
예제 #4
0
        public bool IsOppositeSet(object instance, IPropertySerializationInfo property)
        {
            if (property == null || property.Opposite == null)
            {
                return(false);
            }
            var pair = new ObjectPropertyPair()
            {
                Object = instance, Property = property
            };

            return(blockedProperties.Contains(pair));
        }
예제 #5
0
 protected override ITypeSerializationInfo GetElementTypeInfo(XmlReader reader, IPropertySerializationInfo property)
 {
     string attr = reader.GetAttribute(TypeField, XMLSchemaInstanceNamespace);
     if (attr != null)
     {
         int separator = attr.IndexOf(':');
         if (separator == -1) return GetTypeInfo(string.Empty, attr);
         var prefix = attr.Substring(0, separator);
         var localName = attr.Substring(separator + 1);
         return GetTypeInfo(reader.LookupNamespace(prefix), localName);
     }
     else
     {
         if (property.PropertyType.IsCollection)
         {
             return property.PropertyType.CollectionItemType;
         }
         else
         {
             return property.PropertyType;
         }
     }
 }
예제 #6
0
 public override void Serialize(object obj, XmlWriter writer, IPropertySerializationInfo property, bool writeInstance, XmlIdentificationMode identificationMode, XmlSerializationContext context)
 {
     var modelElement = obj as IModelElement;
     if (modelElement == null)
     {
         base.Serialize(obj, writer, property, writeInstance, identificationMode, context);
     }
     else
     {
         var model = modelElement.Model;
         var modelContext = context as ModelSerializationContext;
         if (modelContext == null || model == modelContext.Model)
         {
             base.Serialize(obj, writer, property, writeInstance, identificationMode, context);
         }
         else
         {
             writer.WriteStartAttribute("href");
             WriteIdentifiedObject(writer, obj, property.IdentificationMode, GetSerializationInfo(obj.GetType(), false), context);
             writer.WriteEndAttribute();
         }
     }
 }
예제 #7
0
        public override void Serialize(object obj, XmlWriter writer, IPropertySerializationInfo property, bool writeInstance, XmlIdentificationMode identificationMode, XmlSerializationContext context)
        {
            var modelElement         = obj as IModelElement;
            var useBaseSerialization = true;

            if (modelElement != null)
            {
                var modelSerializationContext = context as ModelSerializationContext;
                if (modelSerializationContext != null && modelSerializationContext.Model != null)
                {
                    useBaseSerialization = !modelSerializationContext.Model.SerializeAsReference(modelElement);
                }
            }
            if (useBaseSerialization)
            {
                base.Serialize(obj, writer, property, writeInstance, identificationMode, context);
            }
            else
            {
                writer.WriteStartAttribute("href");
                WriteIdentifiedObject(writer, obj, XmlIdentificationMode.Identifier, GetSerializationInfo(obj.GetType(), false), context);
                writer.WriteEndAttribute();
            }
        }
예제 #8
0
        public override void Serialize(object obj, XmlWriter writer, IPropertySerializationInfo property, bool writeInstance, XmlIdentificationMode identificationMode, XmlSerializationContext context)
        {
            var modelElement = obj as IModelElement;

            if (modelElement == null)
            {
                base.Serialize(obj, writer, property, writeInstance, identificationMode, context);
            }
            else
            {
                var model        = modelElement.Model;
                var modelContext = context as ModelSerializationContext;
                if (modelContext == null || model == modelContext.Model)
                {
                    base.Serialize(obj, writer, property, writeInstance, identificationMode, context);
                }
                else
                {
                    writer.WriteStartAttribute("href");
                    WriteIdentifiedObject(writer, obj, property.IdentificationMode, GetSerializationInfo(obj.GetType(), false), context);
                    writer.WriteEndAttribute();
                }
            }
        }
예제 #9
0
 public XmlAddToPropertyDelay(IPropertySerializationInfo property)
 {
     Property = property;
 }
예제 #10
0
        protected override ITypeSerializationInfo GetElementTypeInfo(XmlReader reader, IPropertySerializationInfo property)
        {
            string attr = reader.GetAttribute(TypeField, XMLSchemaInstanceNamespace);

            if (attr != null)
            {
                int separator = attr.IndexOf(':');
                if (separator == -1)
                {
                    return(GetTypeInfo(reader.LookupNamespace(string.Empty), attr));
                }
                var prefix    = attr.Substring(0, separator);
                var localName = attr.Substring(separator + 1);
                return(GetTypeInfo(reader.LookupNamespace(prefix), localName));
            }
            else
            {
                if (property.PropertyType.IsCollection)
                {
                    return(property.PropertyType.CollectionItemType);
                }
                else
                {
                    return(property.PropertyType);
                }
            }
        }
예제 #11
0
        private void ReadElementFromProperty(XmlReader reader, object obj, XmlSerializationContext context, IPropertySerializationInfo p)
        {
            var href = reader.GetAttribute("href");

            if (href == null)
            {
                if (p.PropertyType.IsStringConvertible || (p.PropertyType.IsCollection && p.PropertyType.CollectionItemType.IsStringConvertible))
                {
                    string content = reader.ReadElementContentAsString();
                    if (p.PropertyType.IsCollection)
                    {
                        p.AddToCollection(obj, p.PropertyType.CollectionItemType.ConvertFromString(content), context);
                    }
                    else
                    {
                        p.SetValue(obj, p.ConvertFromString(content), context);
                    }
                }
                else
                {
                    object current = DeserializeInternal(reader, p, context);
                    if (p.PropertyType.IsCollection)
                    {
                        p.AddToCollection(obj, current, context);
                    }
                    else
                    {
                        p.SetValue(obj, current, context);
                    }
                }
            }
            else
            {
                if (p.PropertyType.IsCollection)
                {
                    EnqueueAddToPropertyDelay(p, obj, href, context);
                }
                else
                {
                    EnqueueSetPropertyDelay(p, obj, href, context);
                }
            }
        }
예제 #12
0
 public XmlAddToPropertyDelay(IPropertySerializationInfo property)
 {
     Property = property;
 }
예제 #13
0
 private void ReadElementFromProperty(XmlReader reader, object obj, XmlSerializationContext context, IPropertySerializationInfo p)
 {
     var href = reader.GetAttribute("href");
     if (href == null)
     {
         if (p.PropertyType.IsStringConvertible || (p.PropertyType.IsCollection && p.PropertyType.CollectionItemType.IsStringConvertible))
         {
             string content = reader.ReadElementContentAsString();
             if (p.PropertyType.IsCollection)
             {
                 p.AddToCollection(obj, p.PropertyType.CollectionItemType.ConvertFromString(content), context);
             }
             else
             {
                 p.SetValue(obj, p.ConvertFromString(content), context);
             }
         }
         else
         {
             object current = DeserializeInternal(reader, p, context);
             if (p.PropertyType.IsCollection)
             {
                 p.AddToCollection(obj, current, context);
             }
             else
             {
                 p.SetValue(obj, current, context);
             }
         }
     }
     else
     {
         if (p.PropertyType.IsCollection)
         {
             EnqueueAddToPropertyDelay(p, obj, href, context);
         }
         else
         {
             EnqueueSetPropertyDelay(p, obj, href, context);
         }
     }
 }
예제 #14
0
 protected override bool IsPropertyElement(XmlReader reader, IPropertySerializationInfo p)
 {
     if (string.IsNullOrEmpty(reader.Prefix))
     {
         if (string.IsNullOrEmpty(p.Namespace) && reader.LocalName == p.ElementName)
         {
             return true;
         }
     }
     return base.IsPropertyElement(reader, p);
 }