/// <summary> /// ネームスペースを全部分解して、連結リスト的なものへと収める /// </summary> /// <param name="_ns"></param> /// <returns></returns> static List <NameSpaceNested> GetNameSpaceNestedData(string _ns) { List <NameSpaceNested> nsList = new List <NameSpaceNested>(); { string[] s = _ns.Split('.'); List <string> nls = new List <string>(); nls.AddRange(s); int nNextLevel = 0; NameSpaceNested cut_parent = null; while (nls.Count > 0) { var ns = new NameSpaceNested(); ns.ParentNameSpace = cut_parent; ns.NestLevel = nNextLevel; ns.NameSpace = nls[0]; cut_parent = ns; nls.RemoveAt(0); nNextLevel++; nsList.Add(ns); } } nsList.Sort(); return(nsList); }
//objと自分自身が等価のときはtrueを返す public override bool Equals(object obj) { //objがnullか、型が違うときは、等価でない if (obj == null || this.GetType() != obj.GetType()) { return(false); } //FullNameSpaceで比較する NameSpaceNested c = (NameSpaceNested)obj; return(this.FullNameSpace == c.FullNameSpace); }
// 並べ替え用途 public int CompareTo(object obj) { NameSpaceNested other = obj as NameSpaceNested; if (this.NestLevel < other.NestLevel) { return(-1); } if (this.NestLevel == other.NestLevel) { return(this.FullNameSpace.CompareTo(other.FullNameSpace)); } if (this.NestLevel > other.NestLevel) { return(+1); } return(0); }