コード例 #1
0
        /// <summary>
        /// Get MMO style path (based on label)
        /// </summary>
        /// <param name="child"></param>
        /// <returns></returns>
        public static string GetMmoPath(this IPsbChild child)
        {
            if (child?.Parent == null)
            {
                if (child is PsbDictionary dic)
                {
                    return(dic["label"].ToString());
                }

                return("");
            }

            List <string> paths = new List <string>();

            while (child != null)
            {
                if (child is PsbDictionary current)
                {
                    if (current.ContainsKey("label"))
                    {
                        paths.Add(current["label"].ToString());
                    }
                    else
                    {
                        paths.Add(current.GetName());
                    }
                }

                child = child.Parent;
            }

            paths.Reverse();
            return(string.Join("/", paths));
        }
コード例 #2
0
ファイル: PsbHelper.cs プロジェクト: jszhtian/FreeMote
        /// <summary>
        /// Get it's Name in <see cref="PsbDictionary"/>
        /// </summary>
        /// <param name="c"></param>
        /// <returns></returns>
        public static string GetName(this IPsbChild c)
        {
            var source = c?.Parent as PsbDictionary;
            var result = source?.FirstOrDefault(pair => Equals(pair.Value, c));

            return(result?.Value == null ? null : result.Value.Key);
        }
コード例 #3
0
ファイル: PsbResCollector.cs プロジェクト: jszhtian/FreeMote
 /// <summary>
 /// Get related name on depth 3
 /// </summary>
 /// <param name="c"></param>
 /// <returns></returns>
 private static string GetPartName(this IPsbChild c)
 {
     while (c != null)
     {
         if (c.Parent?.Parent?.Parent == null)
         {
             return(c.GetName());
         }
         c = c.Parent;
     }
     return(null);
 }
コード例 #4
0
        /// <summary>
        /// Get name in <see cref="PsbDictionary"/>
        /// </summary>
        /// <param name="c"></param>
        /// <returns></returns>
        public static string GetName(this IPsbChild c)
        {
            if (c?.Parent is PsbDictionary dic)
            {
                var result = dic.FirstOrDefault(pair => Equals(pair.Value, c));
                return(result.Value == null ? null : result.Key);
            }

            if (c?.Parent is PsbCollection col)
            {
                var result = col.Value.IndexOf(c);
                if (result < 0)
                {
                    return(null);
                }

                return($"[{result}]");
            }

            return(null);
        }