public UnknownTypeEventArgs(IPropertySerializationInfo property, string ns, string localName) { if (localName == null) { throw new ArgumentNullException(nameof(localName)); } Namespace = ns; LocalName = localName; Property = property; }
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)); }
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); }
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)); }
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; } } }
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(); } } }
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(); } }
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(); } } }
public XmlAddToPropertyDelay(IPropertySerializationInfo property) { Property = property; }
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); } } }
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); } } }
public XmlAddToPropertyDelay(IPropertySerializationInfo property) { Property = property; }
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); } } }
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); }