Esempio n. 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));
        }
Esempio n. 2
0
        /// <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);
        }
Esempio n. 3
0
 /// <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);
 }
Esempio n. 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);
        }