Beispiel #1
0
        public static string DefaultStringify(object valueType)
        {
            var s = valueType as string;

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

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

            var pns = valueType as IEnumerable <object>;

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

            var e = valueType as Enum;

            if (e != null)
            {
                return(KnownEnums.Resolve(e));
            }
            if (valueType is bool)
            {
                return(((bool)valueType) ? "true" : "false");
            }
            return(valueType.ToString());
        }
Beispiel #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));
            }

            var e = o as Enum;

            if (e != null)
            {
                return(KnownEnums.Resolve(e));
            }
            if (o is bool)
            {
                return(((bool)o) ? "true" : "false");
            }
            return(o.ToString());
        }
        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));
        }
        public string Stringify(object valueType)
        {
            if (valueType == null)
            {
                return(null);
            }
            var s = valueType as string;

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

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

            var pns = valueType 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 = valueType as Enum;

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

            var pn = valueType as PropertyNameMarker;

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

            var pp = valueType as PropertyPathMarker;

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

            return(valueType.ToString());
        }