/// <summary> /// Return the type distance between two type names. /// </summary> /// <param name="typea"></param> /// <param name="typeb"></param> /// <param name="core"></param> /// <returns>Will return int.MaxValue if no match can be found. /// Otherwise will return the distance between two types in class hierarchy. /// Will throw an exception if either type name is undefined. ///</returns> private static int GetTypeDistance(string typea, string typeb, ProtoCore.Core core) { //TODO - cache? Turn into params? var mirror1 = new ClassMirror(typea, core); var mirror2 = new ClassMirror(typeb, core); if (mirror1.ClassNodeID == mirror2.ClassNodeID) { return(0); } var heirarchy = mirror2.GetClassHierarchy(); var dist = 0; while (dist < heirarchy.Count()) { if (heirarchy.ElementAt(dist).ClassName == mirror1.ClassName) { return(dist + 1); } dist++; } //if we can't find a match then dist should indicate that. return(int.MaxValue); }
public IEnumerable <String> GetMembers() { List <string> members = new List <string>(); Validity.Assert(mirrorData != null); ClassMirror type = mirrorData.Class; if (type == null) { return(members); } IEnumerable <ClassMirror> baseClasses = type.GetClassHierarchy(); foreach (var baseClass in baseClasses) { foreach (var method in baseClass.GetFunctions()) { if (!members.Contains(method.MethodName)) { members.Add(method.MethodName); } } foreach (var property in baseClass.GetProperties()) { if (!members.Contains(property.PropertyName)) { members.Add(property.PropertyName); } } } foreach (var method in type.GetFunctions()) { if (!members.Contains(method.MethodName)) { members.Add(method.MethodName); } } foreach (var property in type.GetProperties()) { if (!members.Contains(property.PropertyName)) { members.Add(property.PropertyName); } } return(members); }
/// <summary> /// Does typeb derive from typea /// </summary> /// <param name="typea"></param> /// <param name="typeb"></param> /// <param name="core"></param> /// <returns></returns> private bool DerivesFrom(string typea, string typeb, ProtoCore.Core core) { try { //TODO mirrors can be cached until new types are imported... var mirror1 = new ClassMirror(typea, core); var mirror2 = new ClassMirror(typeb, core); //TODO as we do this check we can cache the type distance... if (mirror2.GetClassHierarchy().Any(x => x.ClassName == mirror1.ClassName)) { //this is a derived type return(true); } return(false); } catch { Debug.WriteLine($"failed to create class mirror for either {typea} or {typeb} during node autocomplete operation "); return(false); } }