private void Navigate(IFortranObject obj) { this.DoActions(obj, obj.GetType()); var asContainer = (obj as IContainer)?.SubObjects; if (asContainer == null) { return; } for (var i = asContainer.Count - 1; i >= 0; i--) { this.Navigate(asContainer[i]); } }
private void DoActions(IFortranObject obj, Type type) { var actionsForType = _actions[type].ToList(); if (!actionsForType.Any()) { return; } var errorListener = new ErrorListener <TraverserException>(w => this.ErrorListener.Warning(w), e => this.ErrorListener.Error(e)); foreach (var act in actionsForType) { act.Act(obj, errorListener); } }
/// <summary> /// Search the ancestors of an instance of <see cref="IContained"/> for an instance of type <typeparamref name="T"/>. /// </summary> /// <typeparam name="T">The type to search for.</typeparam> /// <param name="contained">The instances whose ancestors are to be searched.</param> /// <returns>The ancestor of type <typeparamref name="T"/>.</returns> public static T AncestorOfType <T>(IContained contained) where T : class, IFortranObject { if (contained == null) { return(null); } IFortranObject current = contained; var currentT = contained as T; while (current != null && currentT == null) { current = (current as IContained)?.Parent; currentT = current as T; } return(currentT); }
public XElement CreateForObject(IFortranObject obj) => this.GetXmlValue(new[] { obj }).Single();
private IEnumerable <XElement> Navigate(IFortranObject obj) => (obj as IContainer)?.SubObjects.GroupBy(this.KeySelector).SelectMany(objsOfType => this.GetValue(objsOfType.Key, objsOfType)) ?? new XElement[] { };
private Type KeySelector(IFortranObject obj) { var objType = obj.GetType(); return(objType.GetInterfaces().SingleOrDefault(inter => _toGroupXmlDictionary.ContainsKey(inter)) ?? objType); }
public XElement ParsedSourcesToXml(IFortranObject source) { throw new NotImplementedException(); }