private NavigatorPosition buildRootPosition(ISourceNode element, string type, IStructureDefinitionSummaryProvider provider) { var rootType = type ?? element.GetResourceTypeIndicator(); if (rootType == null) { if (_settings.ErrorMode == TypedElementSettings.TypeErrorMode.Report) { throw Error.Argument(nameof(type), $"Cannot determine the type of the root element at '{element.Location}', " + $"please supply a type argument."); } else { return(NavigatorPosition.ForRoot(element, null, element.Name)); } } var elementType = provider.Provide(rootType); if (elementType == null) { if (_settings.ErrorMode == TypedElementSettings.TypeErrorMode.Report) { throw Error.Argument(nameof(type), $"Cannot locate type information for type '{rootType}'"); } else { return(NavigatorPosition.ForRoot(element, null, element.Name)); } } return(NavigatorPosition.ForRoot(element, elementType, element.Name)); }
private TypedElementNode(TypedElementNode parent, NavigatorPosition position, string prettyPath) { Current = position; ShortPath = prettyPath; Provider = parent.Provider; ExceptionHandler = parent.ExceptionHandler; _settings = parent._settings; }
private IEnumerable <TypedElementNode> enumerateElements(ElementDefinitionSummaryCache dis, ISourceNode parent, string name) { IEnumerable <ISourceNode> childSet = null; // no name filter: work on all the parent's children if (name == null) { childSet = parent.Children(); } else { var hit = dis.TryGetBySuffixedName(name, out var info); childSet = hit && info.IsChoiceElement ? parent.Children(name + "*") : parent.Children(name); } string lastName = null; int _nameIndex = 0; foreach (var scan in childSet) { var hit = dis.TryGetBySuffixedName(scan.Name, out var info); NavigatorPosition match = info == null ? new NavigatorPosition(scan, null, scan.Name, null) : deriveInstanceType(scan, info); // If we found a type, but we don't know about the specific child, complain if (dis != ElementDefinitionSummaryCache.Empty && !match.IsTracking) { raiseTypeError($"Encountered unknown element '{scan.Name}' while parsing", this, warning: _settings.ErrorMode != TypedElementSettings.TypeErrorMode.Report); // don't include member, unless we are explicitly told to let it pass if (_settings.ErrorMode != TypedElementSettings.TypeErrorMode.Passthrough) { continue; } } if (lastName == scan.Name) { _nameIndex += 1; } else { _nameIndex = 0; lastName = scan.Name; } var prettyPath = hit && !info.IsCollection ? $"{ShortPath}.{match.Name}" : $"{ShortPath}.{match.Name}[{_nameIndex}]"; yield return(new TypedElementNode(this, match, prettyPath)); } }
private ElementDefinitionSummaryCache down(NavigatorPosition current) { if (!current.IsTracking || current.InstanceType == null) { return(ElementDefinitionSummaryCache.Empty); } // If this is a backbone element, the child type is the nested complex type if (current.SerializationInfo.Type[0] is IStructureDefinitionSummary be) { return(ElementDefinitionSummaryCache.ForType(be)); } else { var si = Provider.Provide(current.InstanceType); return(si == null ? ElementDefinitionSummaryCache.Empty : ElementDefinitionSummaryCache.ForType(si)); } }