/// <summary> /// Загружает в список последовательность Родительских классов /// </summary> /// <param name="list"></param> /// <param name="type"></param> private void LoadingList(List <SearchingType> list, SearchingType type) { list.Add(type); if (type.Parent != null) { LoadingList(list, type.Parent); } }
private string ShowChilds(SearchingType type, string offset = "|<----", params string[] classes) { string output = ""; foreach (var item in type.Childs) { if (classes.Contains(item.Name)) { Console.ForegroundColor = ConsoleColor.Red; output += $"{offset} {item.Name}<---" + Environment.NewLine; Console.ForegroundColor = ConsoleColor.Green; } else { output += $"{offset} {item.Name}" + Environment.NewLine; } output += ShowChilds(item, "| " + offset, classes); } return(output); }
/// <summary> /// Добавляем тип в словарь /// </summary> /// <param name="type"></param> private void AddParentTypeToDictionary(SearchingType type) { SearchingType parentType; Type pt = null; Type t = Type.GetType($"{type.AssemblyQualifier}"); try { pt = t.BaseType; } catch (Exception err) { return; } if (pt == null) { return; } else { if (searchTypes.Keys.Contains(pt.FullName)) { type.Parent = searchTypes[pt.FullName]; searchTypes[pt.FullName].Childs.Add(type); } else { searchTypes.Add(pt.FullName, new SearchingType { Name = pt.Name, FullName = pt.FullName, AssemblyQualifier = pt.AssemblyQualifiedName }); type.Parent = searchTypes[pt.FullName]; searchTypes[pt.FullName].Childs.Add(type); AddParentTypeToDictionary(searchTypes[pt.FullName]); } } }
/// <summary> /// Просматриваем типы достигающие данный тип за один переход /// </summary> /// <param name="type"></param> public string OneLevelAccessors(string type, bool IsFullName = false) { string output = ""; SearchingType t = null; if (IsFullName) { t = searchTypes.Select(p => p.Value) .FirstOrDefault(p => p.FullName == type); } else { t = searchTypes.Select(p => p.Value) .FirstOrDefault(p => p.Name == type); } foreach (var item in t.Prototypes.Distinct()) { output += $"{item.SearchingType.Name}->[{item.RelatedString}]->" + Environment.NewLine; } output += $"------------->{type}" + Environment.NewLine; return(output); }