Ejemplo n.º 1
0
        internal static string GetStringValue(this Enum enumValue)
        {
            var knownEnum = KnownEnums.Resolve(enumValue);

            if (knownEnum != KnownEnums.UnknownEnum)
            {
                return(knownEnum);
            }

            //TODO measure performance and cache
            var type = enumValue.GetType();
            var info = type.GetField(enumValue.ToString());
            var da   = (EnumMemberAttribute[])(info.GetCustomAttributes(typeof(EnumMemberAttribute), false));

            return(da.Length > 0 ? da[0].Value : Enum.GetName(enumValue.GetType(), enumValue));
        }
Ejemplo n.º 2
0
        public string Stringify(object o)
        {
            var s = o as string;

            if (s != null)
            {
                return(s);
            }
            var ss = o as string[];

            if (ss != null)
            {
                return(string.Join(",", ss));
            }

            var pns = o as IEnumerable <object>;

            if (pns != null)
            {
                return(string.Join(",", pns.Select(
                                       oo =>
                {
                    if (oo is PropertyNameMarker)
                    {
                        return this.Infer.PropertyName(oo as PropertyNameMarker);
                    }
                    if (oo is PropertyPathMarker)
                    {
                        return this.Infer.PropertyPath(oo as PropertyPathMarker);
                    }
                    return oo.ToString();
                })
                                   ));
            }

            var e = o as Enum;

            if (e != null)
            {
                return(KnownEnums.Resolve(e));
            }
            if (o is bool)
            {
                return(((bool)o) ? "true" : "false");
            }

            var pn = o as PropertyNameMarker;

            if (pn != null)
            {
                return(this.Infer.PropertyName(pn));
            }

            var pp = o as PropertyPathMarker;

            if (pp != null)
            {
                return(this.Infer.PropertyPath(pp));
            }

            return(o.ToString());
        }