private void SetValue(IXmlCursor cursor, object oldValue, ref T value) { object obj = value; accessor.SetValue(cursor, parentObject, references, true, oldValue, ref obj); value = (T)(obj ?? default(T)); }
public virtual void SetValue(IXmlCursor cursor, IDictionaryAdapter parentObject, XmlReferenceManager references, bool hasCurrent, object oldValue, ref object newValue) { var hasValue = null != newValue; var isNillable = this.IsNillable; var isReference = this.IsReference; var clrType = hasValue ? newValue.GetComponentType() : this.clrType; if (hasValue || isNillable) { if (hasCurrent) { Coerce(cursor, clrType, !hasValue && cursor.IsAttribute); // TODO: Refactor. (NB: && isNillable is emplied) } else { cursor.Create(clrType); } } else if (!hasCurrent) { // No node exists + no value to assign + and not nillable = no work to do return; } object token = null; if (isReference) { if (!references.OnAssigningValue(cursor, oldValue, ref newValue, out token)) { return; } } var givenValue = newValue; if (hasValue) { serializer.SetValue(cursor, parentObject, this, oldValue, ref newValue); } else if (isNillable) { cursor.IsNil = true; } else { cursor.Remove(); cursor.RemoveAllNext(); } if (isReference) { references.OnAssignedValue(cursor, givenValue, newValue, token); } }
public override void SetValue(IXmlCursor cursor, IDictionaryAdapter parentObject, XmlReferenceManager references, bool hasCurrent, object oldValue, ref object newValue) { if (newValue == null && IsCollection) { base.RemoveCollectionItems(cursor, references, oldValue); } else { base.SetValue(cursor, parentObject, references, hasCurrent, oldValue, ref newValue); } }
private void Coerce(IXmlCursor cursor, Type clrType, bool replace) { if (replace) { cursor.Remove(); cursor.MoveNext(); cursor.Create(ClrType); } else { cursor.Coerce(clrType); } }
public XmlCollectionAdapter( IXmlNode parentNode, IDictionaryAdapter parentObject, IXmlCollectionAccessor accessor) { items = new List <XmlCollectionItem <T> >(); this.accessor = accessor; this.cursor = accessor.SelectCollectionItems(parentNode, true); this.parentNode = parentNode; this.parentObject = parentObject; this.references = XmlAdapter.For(parentObject).References; while (cursor.MoveNext()) { items.Add(new XmlCollectionItem <T>(cursor.Save())); } }
public static void SetReference(this IXmlCursor cursor, string id) { cursor.SetAttribute(XRef.Ref, id); }
public static void SetId(this IXmlCursor node, string id) { node.SetAttribute(XRef.Id, id); }
private void Coerce(IXmlCursor cursor, Type clrType, bool replace) { if (replace) { cursor.Remove(); cursor.MoveNext(); cursor.Create(ClrType); } else cursor.Coerce(clrType); }
public virtual void SetValue(IXmlCursor cursor, IDictionaryAdapter parentObject, XmlReferenceManager references, bool hasCurrent, object oldValue, ref object newValue) { var hasValue = null != newValue; var isNillable = this.IsNillable; var isReference = this.IsReference; var clrType = hasValue ? newValue.GetComponentType() : this.clrType; if (hasValue || isNillable) { if (hasCurrent) Coerce(cursor, clrType, !hasValue && cursor.IsAttribute); // TODO: Refactor. (NB: && isNillable is emplied) else cursor.Create(clrType); } else if (!hasCurrent) { // No node exists + no value to assign + and not nillable = no work to do return; } object token = null; if (isReference) if (!references.OnAssigningValue(cursor, oldValue, ref newValue, out token)) return; var givenValue = newValue; if (hasValue) serializer.SetValue(cursor, parentObject, this, oldValue, ref newValue); else if (isNillable) cursor.IsNil = true; else { cursor.Remove(); cursor.RemoveAllNext(); } if (isReference) references.OnAssignedValue(cursor, givenValue, newValue, token); }