示例#1
0
 /// <summary>
 /// 将值为int类型的枚举的结果转化为string类型
 /// </summary>
 /// <param name="values"></param>
 /// <returns></returns>
 public static string EnumIntToString(this Enum values)
 {
     if (Enum.GetUnderlyingType(values.GetType()) != typeof(int))
     {
         return(null);
     }
     return((values.ConvertTo <int>()).ToString());
 }
示例#2
0
 public static string GetDescription(this Enum value, bool showValue)
 {
     if (showValue)
     {
         return(string.Format("{0} ({1})", value.GetDescription(), value.ConvertTo <int>()));
     }
     else
     {
         return(value.GetDescription());
     }
 }
示例#3
0
        public static string GetDescription(this Enum value, Type resourceType)
        {
            if (resourceType != null)
            {
                PropertyInfo property = resourceType.GetProperty(value.ConvertTo <string>());
                if (property != null)
                {
                    return(property.GetValue(null, null).ConvertTo <string>());
                }
            }

            return(value.GetDescription());
        }
示例#4
0
        public string GetUrl(Enum types)
        {
            switch (types.ConvertTo <AmazonFeedTypes>())
            {
            case AmazonFeedTypes.EBook:
                return(BaseUrl + "/gp/bestsellers/books/ref=sv_b_2");

            case AmazonFeedTypes.Electronic:
                return(BaseUrl + "/gp/movers-and-shakers/electronics/ref=zg_bsms_nav_b_1_b");

            default:
                return(string.Empty);
            }
        }
示例#5
0
 public static SelectListItem GetSelectListItem <T>(Enum id)
     where T : BaseClass, IName
 {
     return(GetSelectListItem <T>(id.ConvertTo <int>()));
 }
示例#6
0
        private Boolean?HasPermission <T>(LocalUserPrincipalModel principal, Enum permission)
        {
            // Get the interface to which permissions are applied
            Type runtimeType = typeof(T).IsInterface ? typeof(T) : typeof(T).GetInterfaces().Except(typeof(T).GetInterfaces().SelectMany(iface => iface.GetInterfaces())).FirstOrDefault();

            if (runtimeType == null && typeof(T).BaseType.GetGenericArguments().Length != 0 && typeof(T).BaseType.GetGenericArguments()[0].GetInterfaces().Any(iface => iface == typeof(IModel)))
            {
                runtimeType = typeof(T).BaseType.GetGenericArguments()[0].IsInterface ? typeof(T).BaseType.GetGenericArguments()[0] : typeof(T).BaseType.GetGenericArguments()[0].GetInterfaces().Except(typeof(T).BaseType.GetGenericArguments()[0].GetInterfaces().SelectMany(iface => iface.GetInterfaces())).FirstOrDefault();
            }

            // Get the permission set for the specified type (this will be null for types linked to an unlicensed module)
            String            typeName      = String.Format("{0}.{1}", runtimeType.Namespace, runtimeType.Name.Substring(1, runtimeType.Name.Length - 6));
            UserPermissionSet permissionSet = principal.PermissionSets.FirstOrDefault(ps => String.Equals(ps.FullName, typeName, StringComparison.OrdinalIgnoreCase));

            if (permissionSet == null)
            {
                return(false);
            }

            // Get the permission information that matches the specified permission (this will be null for types that do not support the specified permission)
            UserPermissionType permissionType = permissionSet.Permissions.FirstOrDefault(pt => String.Equals(pt.Type, permission.GetType().Name, StringComparison.OrdinalIgnoreCase) && pt.Number == permission.ConvertTo <Int32>());

            if (permissionType == null)
            {
                return(false);
            }

            // Return the permission setting
            return(permissionType.Value);
        }