public void GetCollectionItems( IXmlNode parentNode, IDictionaryAdapter parentObject, XmlReferenceManager references, IList values ) { var cursor = SelectCollectionItems(parentNode, false); while (cursor.MoveNext()) { object value; if (IsReference) { IXmlNode node = cursor; value = null; object token; if (references.OnGetStarting(ref node, ref value, out token)) { value = serializer.GetValue(node, parentObject, this); references.OnGetCompleted(node, value, token); } } else { value = serializer.GetValue(cursor, parentObject, this); } values.Add(value); } }
public void UnionWith(XmlReferenceManager other) { var visited = null as HashSet <Entry>; foreach (var otherEntry in other.entriesByValue) { Entry thisEntry; if (entriesByValue.TryGetValue(otherEntry.Key, out thisEntry)) { if (visited == null) { visited = new HashSet <Entry>(ReferenceEqualityComparer <Entry> .Instance); } else if (visited.Contains(thisEntry)) { continue; } visited.Add(thisEntry); foreach (var otherValue in otherEntry.Value.Values) { var otherTarget = otherValue.Value.Target; if (otherTarget == null || otherTarget == otherEntry.Key || entriesByValue.ContainsKey(otherTarget)) { continue; } AddValueCore(thisEntry, otherValue.Type, otherTarget, false); } } } }
public object GetValue( IXmlNode node, IDictionaryAdapter parentObject, XmlReferenceManager references, bool nodeExists, bool orStub ) { object value; if ((nodeExists || orStub) && IsReference) { value = null; object token; if (references.OnGetStarting(ref node, ref value, out token)) { value = GetValueCore(node, parentObject, nodeExists, orStub); references.OnGetCompleted(node, value, token); } } else { value = GetValueCore(node, parentObject, nodeExists, orStub); } return(value); }
protected void RemoveCollectionItems(IXmlNode parentNode, XmlReferenceManager references, object value) { var collection = value as ICollectionProjection; if (collection != null) { collection.Clear(); return; } var itemType = clrType.GetCollectionItemType(); var accessor = GetCollectionAccessor(itemType); var cursor = accessor.SelectCollectionItems(parentNode, true); var isReference = IsReference; var items = value as IEnumerable; if (items != null) { foreach (var item in items) { if (!cursor.MoveNext()) { break; } if (isReference) { references.OnAssigningNull(cursor, item); } } } cursor.Reset(); cursor.RemoveAllNext(); }
public override object GetPropertyValue( IXmlNode parentNode, IDictionaryAdapter parentObject, XmlReferenceManager references, bool orStub ) { return(GetPropertyValueCore(parentNode, parentObject, references, orStub) ?? GetDefaultPropertyValue(parentNode, parentObject, references, orStub)); }
private object GetDefaultPropertyValue( IXmlNode parentNode, IDictionaryAdapter parentObject, XmlReferenceManager references, bool orStub ) { return(defaultAccessor != null ? defaultAccessor.GetPropertyValue(parentNode, parentObject, references, orStub) : null); }
private object GetPropertyValueCore( IXmlNode parentNode, IDictionaryAdapter parentObject, XmlReferenceManager references, bool orStub ) { return(SelectsNodes ? base.GetPropertyValue(parentNode, parentObject, references, orStub) : Evaluate(parentNode)); }
/// <summary> /// Initializes a new instance of the <see cref="XmlAdapter"/> class /// that represents a child object in a larger object graph. /// </summary> public XmlAdapter(IXmlNode node, XmlReferenceManager references) { if (node == null) { throw Error.ArgumentNull("node"); } if (references == null) { throw Error.ArgumentNull("references"); } this.node = node; this.references = references; }
public virtual void SetPropertyValue( IXmlNode parentNode, IDictionaryAdapter parentObject, XmlReferenceManager references, object oldValue, ref object value ) { var cursor = IsCollection ? SelectCollectionNode(parentNode, true) : SelectPropertyNode(parentNode, true); SetValue(cursor, parentObject, references, cursor.MoveNext(), oldValue, ref value); }
public override void SetPropertyValue( IXmlNode parentNode, IDictionaryAdapter parentObject, XmlReferenceManager references, object oldValue, ref object value ) { if (SelectsNodes) { base.SetPropertyValue(parentNode, parentObject, references, oldValue, ref value); } else { throw Error.XPathNotCreatable(path); } }
public virtual object GetPropertyValue( IXmlNode parentNode, IDictionaryAdapter parentObject, XmlReferenceManager references, bool orStub ) { if (orStub) { orStub &= serializer.CanGetStub; } var cursor = IsCollection ? SelectCollectionNode(parentNode, orStub) : SelectPropertyNode(parentNode, orStub); return(GetValue(cursor, parentObject, references, cursor.MoveNext(), orStub)); }
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); } }
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())); } }
private void InitializePrimary(DictionaryAdapterMeta meta, IDictionaryAdapter dictionaryAdapter) { RequireXmlMeta(meta); primaryXmlMeta = meta.GetXmlMeta(); if (node == null) { node = GetBaseNode(); } if (!node.IsReal) { node.Realized += HandleNodeRealized; } if (references == null) { references = new XmlReferenceManager(node, DefaultXmlReferenceFormat.Instance); } InitializeReference(this); }
public void UnionWith(XmlReferenceManager other) { var visited = null as HashSet <Entry>; foreach (var keyValue in other.entriesByValue.Keys) { Entry thisEntry; if (entriesByValue.TryGetValue(keyValue, out thisEntry)) { if (visited == null) { visited = new HashSet <Entry>(ReferenceEqualityComparer <Entry> .Instance); } else if (visited.Contains(thisEntry)) { continue; } visited.Add(thisEntry); var otherEntry = other.entriesByValue[keyValue]; foreach (var otherItem in otherEntry.Values) { if (otherItem.Value == keyValue) { continue; } if (entriesByValue.ContainsKey(otherItem.Value)) { continue; } AddValueCore(thisEntry, otherItem.Type, otherItem.Value, false); } } } }
public virtual object GetPropertyValue(IXmlNode parentNode, IDictionaryAdapter parentObject, XmlReferenceManager references, bool orStub) { if (orStub) orStub &= serializer.CanGetStub; var cursor = IsCollection ? SelectCollectionNode(parentNode, orStub) : SelectPropertyNode (parentNode, orStub); return GetValue(cursor, parentObject, references, cursor.MoveNext(), orStub); }
public void UnionWith(XmlReferenceManager other) { var visited = null as HashSet<Entry>; foreach (var otherEntry in other.entriesByValue) { Entry thisEntry; if (entriesByValue.TryGetValue(otherEntry.Key, out thisEntry)) { if (visited == null) visited = new HashSet<Entry>(ReferenceEqualityComparer<Entry>.Instance); else if (visited.Contains(thisEntry)) continue; visited.Add(thisEntry); foreach (var otherValue in otherEntry.Value.Values) { var otherTarget = otherValue.Value.Target; if (otherTarget == null || otherTarget == otherEntry.Key || entriesByValue.ContainsKey(otherTarget)) { continue; } AddValueCore(thisEntry, otherValue.Type, otherTarget, false); } } } }
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 void SetUp() { OriginalXml = GetXmlText(); Document = Xml(OriginalXml); OriginalXml = Document.OuterXml; Namespaces = new XmlContextBase(); Node = new SysXmlNode(Document.DocumentElement, typeof(object), Namespaces); Manager = new XmlReferenceManager(Node, DefaultXmlReferenceFormat.Instance); }
protected void RemoveCollectionItems(IXmlNode parentNode, XmlReferenceManager references, object value) { var collection = value as ICollectionProjection; if (collection != null) { collection.Clear(); return; } var itemType = clrType.GetCollectionItemType(); var accessor = GetCollectionAccessor(itemType); var cursor = accessor.SelectCollectionItems(parentNode, true); var isReference = IsReference; var items = value as IEnumerable; if (items != null) { foreach (var item in items) { if (!cursor.MoveNext()) break; if (isReference) references.OnAssigningNull(cursor, item); } } cursor.Reset(); cursor.RemoveAllNext(); }
public void GetCollectionItems(IXmlNode parentNode, IDictionaryAdapter parentObject, XmlReferenceManager references, IList values) { var cursor = SelectCollectionItems(parentNode, false); while (cursor.MoveNext()) { object value; if (IsReference) { IXmlNode node = cursor; value = null; object token; if (references.OnGetStarting(ref node, ref value, out token)) { value = serializer.GetValue(node, parentObject, this); references.OnGetCompleted(node, value, token); } } else { value = serializer.GetValue(cursor, parentObject, this); } values.Add(value); } }
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 virtual void SetPropertyValue(IXmlNode parentNode, IDictionaryAdapter parentObject, XmlReferenceManager references, object oldValue, ref object value) { var cursor = IsCollection ? SelectCollectionNode(parentNode, true) : SelectPropertyNode (parentNode, true); SetValue(cursor, parentObject, references, cursor.MoveNext(), oldValue, ref value); }
public object GetValue(IXmlNode node, IDictionaryAdapter parentObject, XmlReferenceManager references, bool nodeExists, bool orStub) { object value; if ((nodeExists || orStub) && IsReference) { value = null; object token; if (references.OnGetStarting(ref node, ref value, out token)) { value = GetValueCore(node, parentObject, nodeExists, orStub); references.OnGetCompleted(node, value, token); } } else { value = GetValueCore(node, parentObject, nodeExists, orStub); } return value; }
public void UnionWith(XmlReferenceManager other) { var visited = null as HashSet<Entry>; foreach (var keyValue in other.entriesByValue.Keys) { Entry thisEntry; if (entriesByValue.TryGetValue(keyValue, out thisEntry)) { if (visited == null) visited = new HashSet<Entry>(ReferenceEqualityComparer<Entry>.Instance); else if (visited.Contains(thisEntry)) continue; visited.Add(thisEntry); var otherEntry = other.entriesByValue[keyValue]; foreach (var otherItem in otherEntry.Values) { if (otherItem.Value == keyValue) continue; if (entriesByValue.ContainsKey(otherItem.Value)) continue; AddValueCore(thisEntry, otherItem.Type, otherItem.Value, false); } } } }