public ScopedNavigator(IElementNavigator wrapped) { _wrapped = wrapped.Clone(); if (this.AtResource) { ResourceContext = wrapped.Clone(); } }
public bool MoveToFirstChild(string nameFilter = null) { ScopedNavigator me = null; if (this.AtResource) { me = (ScopedNavigator)this.Clone(); // Is the current position not a contained resource? if (Parent?.ContainedResources().FirstOrDefault() == null) { ResourceContext = _wrapped.Clone(); } } if (!_wrapped.MoveToFirstChild(nameFilter)) { return(false); } // If the current position is a resource, we'll be the new _parentScope if (me != null) { Parent = me; } _cache = new Cache(); return(true); }
public Scope(IElementNavigator container, string uri) { Container = container.Clone(); Path = container.Location; IsBundle = ModelInfo.FhirTypeNameToFhirType(container.Type) == FHIRDefinedType.Bundle; Uri = uri; _children = new Lazy <List <Scope> >(createScopeListForContainer); }
/// <summary>Harvest the value of a child element into a property bag.</summary> /// <param name="nav">An <see cref="IElementNavigator"/> instance.</param> /// <param name="properties">A property bag to store harvested summary information.</param> /// <param name="key">A property key.</param> /// <param name="element">An element name.</param> /// <param name="childElement">A child element name.</param> public static bool HarvestValue(this IElementNavigator nav, IDictionary <string, object> properties, string key, string element, string childElement) { if (nav.Find(element)) { var childNav = nav.Clone(); return(childNav.MoveToFirstChild(childElement) && childNav.HarvestValue(properties, key)); } return(false); }
public static IEnumerable <IElementNavigator> Children(this IElementNavigator navigator, string name = null) { var nav = navigator.Clone(); if (nav.MoveToFirstChild(name)) { do { yield return(nav.Clone()); }while (nav.MoveToNext(name)); } }
public static IEnumerable <object> Values(this IElementNavigator navigator) { var nav = navigator.Clone(); if (nav.MoveToFirstChild()) { do { yield return(nav.Value); }while (nav.MoveToNext()); } }
public ElementNavToTypedElementAdapter(IElementNavigator nav) { if (nav == null) { throw Error.ArgumentNull(nameof(nav)); } Current = nav.Clone(); if (nav is IExceptionSource ies && ies.ExceptionHandler == null) { ies.ExceptionHandler = (o, a) => ExceptionHandler.NotifyOrThrow(o, a); } }
public static void Render(IElementNavigator navigator, int nest = 0) { do { string indent = new string(' ', nest * 4); Debug.WriteLine($"{indent}" + ToString(navigator)); var child = navigator.Clone(); if (child.MoveToFirstChild()) { Render(child, nest + 1); } }while (navigator.MoveToNext()); }
private static ElementNode buildNode(IElementNavigator navigator) { var me = new ElementNode(navigator.Name, navigator.Value, navigator.Type); var childNav = navigator.Clone(); if (childNav.MoveToFirstChild()) { do { me.Add(buildNode(childNav)); } while (childNav.MoveToNext()); } return(me); }
public static IEnumerable <Scope> Harvest(IElementNavigator instance) { var scanner = instance.Clone(); if (ModelInfo.FhirTypeNameToFhirType(scanner.Type) == FHIRDefinedType.Bundle) { return(HarvestBundle(scanner)); } else if (ModelInfo.IsKnownResource(instance.Type)) { return(HarvestResource(instance)); } else { return(Enumerable.Empty <Scope>()); } }
/// <summary>Harvest extension values into a property bag.</summary> /// <param name="nav">An <see cref="IElementNavigator"/> instance.</param> /// <param name="properties">A property bag to store harvested summary information.</param> /// <param name="extensionValueHarvester">Callback function called for each individual extension entry.</param> public static void HarvestExtensions(this IElementNavigator nav, IDictionary <string, object> properties, Action <IElementNavigator, IDictionary <string, object>, string> extensionValueHarvester) { const string extension = "extension"; if (nav.Find(extension)) { do { var childNav = nav.Clone(); if (childNav.MoveToFirstChild("url")) { if (childNav.Value is string url) { extensionValueHarvester(childNav, properties, url); } } // [WMR 20171219] BUG: MoveToNext advances to extension.url (child attribute) instead of the next extension element } while (nav.MoveToNext(extension)); } }
/// <summary>Harvest an array of child element values into a property bag.</summary> /// <param name="nav">An <see cref="IElementNavigator"/> instance.</param> /// <param name="properties">A property bag to store harvested summary information.</param> /// <param name="key">A property key.</param> /// <param name="element">An element name.</param> /// <param name="childElement">A child element name.</param> public static bool HarvestValues(this IElementNavigator nav, IDictionary <string, object> properties, string key, string element, string childElement) { if (nav.Find(element)) { var values = new List <string>(); do { var childNav = nav.Clone(); if (childNav.MoveToFirstChild(childElement)) { HarvestValue(childNav, values); } } while (nav.MoveToNext(element)); if (values.Count > 0) { properties[key] = values.ToArray(); return(true); } } return(false); }
private void validateContact(IElementNavigator patient) { var contact = patient.Clone(); Assert.IsTrue(contact.MoveToFirstChild()); // contact.name Assert.IsTrue(contact.MoveToFirstChild()); // contact.name.family[0] Assert.IsNull(contact.Value); Assert.IsTrue(contact.MoveToNext()); // family[1] Assert.AreEqual("du", contact.Value); Assert.IsTrue(contact.MoveToNext()); // family[2] Assert.IsTrue(contact.MoveToNext()); // family[3] Assert.AreEqual("Marché", contact.Value); Assert.IsFalse(contact.MoveToFirstChild()); Assert.IsTrue(contact.MoveToNext()); // family[4] Assert.IsNull(contact.Value); Assert.IsTrue(contact.MoveToFirstChild()); // family[4].extension Assert.AreEqual("extension", contact.Name); }
public IElementNavigator Clone() { var n = _navigator.Clone(); return(new PathNavigator(n, this.Location)); }
public IElementNavigator Clone() => new ElementNavFhirReader(_current.Clone(), DisallowXsiAttributesOnRoot);
public ScopedNavigator(IElementNavigator wrapped) { _wrapped = wrapped.Clone(); }
public static bool HasChildren(this IElementNavigator navigator) { var nav = navigator.Clone(); return(nav.MoveToFirstChild()); }