示例#1
0
        internal static string GetStringValue(this Enum enumValue)
        {
            var knownEnum = KnownEnums.Resolve(enumValue);

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

            var type = enumValue.GetType();
            var info = type.GetField(enumValue.ToString());
            var da   = info.GetCustomAttribute <EnumMemberAttribute>();

            return(da != null ? da.Value : Enum.GetName(enumValue.GetType(), enumValue));
        }
        internal static string GetStringValue(this Enum enumValue)
        {
            var knownEnum = KnownEnums.Resolve(enumValue);

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

            var type = enumValue.GetType();
            var info = type.GetField(enumValue.ToString());
            var da   = (EnumMemberAttribute[])(info.GetCustomAttributes(typeof(EnumMemberAttribute), false));

            if (da.Length > 0)
            {
                return(da[0].Value);
            }
            else
            {
                return(Enum.GetName(enumValue.GetType(), enumValue));
            }
        }
示例#3
0
文件: Features.cs 项目: lukapor/NEST
 string IUrlParameter.GetString(IConnectionConfigurationValues settings) => KnownEnums.Resolve(_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());
        }
示例#5
0
 public string GetString(IConnectionConfigurationValues settings) => KnownEnums.Resolve(this._enumValue);