后台数据表建立
This commit is contained in:
29
20220330_Vote/Ewide.Core/Util/EnumHelper.cs
Normal file
29
20220330_Vote/Ewide.Core/Util/EnumHelper.cs
Normal file
@@ -0,0 +1,29 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Ewide.Core.Util
|
||||
{
|
||||
public static class EnumHelper
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取枚举注释
|
||||
/// </summary>
|
||||
/// <param name="enumValue"></param>
|
||||
/// <returns></returns>
|
||||
public static string GetEnumDescription(this Enum enumValue)
|
||||
{
|
||||
string value = enumValue.ToString();
|
||||
FieldInfo field = enumValue.GetType().GetField(value);
|
||||
object[] objs = field.GetCustomAttributes(typeof(DescriptionAttribute), false); //获取描述属性
|
||||
if (objs == null || objs.Length == 0) //当描述属性没有时,直接返回名称
|
||||
return value;
|
||||
DescriptionAttribute descriptionAttribute = (DescriptionAttribute)objs[0];
|
||||
return descriptionAttribute.Description;
|
||||
}
|
||||
}
|
||||
}
|
||||
28
20220330_Vote/Ewide.Core/Util/RandomHelper.cs
Normal file
28
20220330_Vote/Ewide.Core/Util/RandomHelper.cs
Normal file
@@ -0,0 +1,28 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Ewide.Core.Util
|
||||
{
|
||||
public class RandomHelper
|
||||
{
|
||||
private const string BASECODE = "ABCDEFGHJKLMNPQRSTUVWXYZ0123456789";
|
||||
/// <summary>
|
||||
///生成指定位数的随机码(数字)
|
||||
/// </summary>
|
||||
/// <param name="length"></param>
|
||||
/// <returns></returns>
|
||||
public static string GenerateRandomCode(int length)
|
||||
{
|
||||
var result = new StringBuilder();
|
||||
for (var i = 0; i < length; i++)
|
||||
{
|
||||
var r = new Random(Guid.NewGuid().GetHashCode());
|
||||
result.Append(BASECODE[r.Next(BASECODE.Length)]);
|
||||
}
|
||||
return result.ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user