添加项目文件。
This commit is contained in:
49
common/Tnb.CollectiveOAuth/Enums/AuthResponseStatus.cs
Normal file
49
common/Tnb.CollectiveOAuth/Enums/AuthResponseStatus.cs
Normal file
@@ -0,0 +1,49 @@
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace JNPF.Extras.CollectiveOAuth.Enums;
|
||||
|
||||
/// <summary>
|
||||
/// 授权响应状态.
|
||||
/// </summary>
|
||||
public enum AuthResponseStatus
|
||||
{
|
||||
/// <summary>
|
||||
/// 2000:正常;
|
||||
/// other:调用异常,具体异常内容见<c>msg</c>.
|
||||
/// </summary>
|
||||
[Description("Success")]
|
||||
SUCCESS = 2000,
|
||||
|
||||
[Description("Failure")]
|
||||
FAILURE = 5000,
|
||||
|
||||
[Description("Not Implemented")]
|
||||
NOT_IMPLEMENTED = 5001,
|
||||
|
||||
[Description("Parameter incomplete")]
|
||||
PARAMETER_INCOMPLETE = 5002,
|
||||
|
||||
[Description("Unsupported operation")]
|
||||
UNSUPPORTED = 5003,
|
||||
|
||||
[Description("AuthDefaultSource cannot be null")]
|
||||
NO_AUTH_SOURCE = 5004,
|
||||
|
||||
[Description("Unidentified platform")]
|
||||
UNIDENTIFIED_PLATFORM = 5005,
|
||||
|
||||
[Description("Illegal redirect uri")]
|
||||
ILLEGAL_REDIRECT_URI = 5006,
|
||||
|
||||
[Description("Illegal request")]
|
||||
ILLEGAL_REQUEST = 5007,
|
||||
|
||||
[Description("Illegal code")]
|
||||
ILLEGAL_CODE = 5008,
|
||||
|
||||
[Description("Illegal state")]
|
||||
ILLEGAL_STATUS = 5009,
|
||||
|
||||
[Description("The refresh token is required; it must not be null")]
|
||||
REQUIRED_REFRESH_TOKEN = 5010,
|
||||
}
|
||||
63
common/Tnb.CollectiveOAuth/Enums/AuthToutiaoErrorCode.cs
Normal file
63
common/Tnb.CollectiveOAuth/Enums/AuthToutiaoErrorCode.cs
Normal file
@@ -0,0 +1,63 @@
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace JNPF.Extras.CollectiveOAuth.Enums;
|
||||
|
||||
/// <summary>
|
||||
/// 今日头条授权登录时的异常状态码.
|
||||
/// <para>@author wei.fu (wei.fu@rthinkingsoft.cn).</para>
|
||||
/// <para>@since 1.8.</para>
|
||||
/// </summary>
|
||||
public enum AuthToutiaoErrorCode
|
||||
{
|
||||
/// <summary>
|
||||
/// 0:正常
|
||||
/// other:调用异常,具体异常内容见<c>desc</c>.
|
||||
/// </summary>
|
||||
[Description("接口调用成功")]
|
||||
EC0 = 0,
|
||||
|
||||
[Description("API配置错误,未传入Client Key")]
|
||||
EC1 = 1,
|
||||
|
||||
[Description("API配置错误,Client Key错误,请检查是否和开放平台的ClientKey一致")]
|
||||
EC2 = 2,
|
||||
|
||||
[Description("没有授权信息")]
|
||||
EC3 = 3,
|
||||
|
||||
[Description("响应类型错误")]
|
||||
EC4 = 4,
|
||||
|
||||
[Description("授权类型错误")]
|
||||
EC5 = 5,
|
||||
|
||||
[Description("client_secret错误")]
|
||||
EC6 = 6,
|
||||
|
||||
[Description("authorize_code过期")]
|
||||
EC7 = 7,
|
||||
|
||||
[Description("指定url的scheme不是https")]
|
||||
EC8 = 8,
|
||||
|
||||
[Description("接口内部错误,请联系头条技术")]
|
||||
EC9 = 9,
|
||||
|
||||
[Description("access_token过期")]
|
||||
EC10 = 10,
|
||||
|
||||
[Description("缺少access_token")]
|
||||
EC11 = 11,
|
||||
|
||||
[Description("参数缺失")]
|
||||
EC12 = 12,
|
||||
|
||||
[Description("url错误")]
|
||||
EC13 = 13,
|
||||
|
||||
[Description("域名与登记域名不匹配")]
|
||||
EC21 = 21,
|
||||
|
||||
[Description("未知错误,请联系头条技术")]
|
||||
EC999 = 999,
|
||||
}
|
||||
16
common/Tnb.CollectiveOAuth/Enums/AuthUserGender.cs
Normal file
16
common/Tnb.CollectiveOAuth/Enums/AuthUserGender.cs
Normal file
@@ -0,0 +1,16 @@
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace JNPF.Extras.CollectiveOAuth.Enums;
|
||||
|
||||
/// <summary>
|
||||
/// 授权用户性别.
|
||||
/// </summary>
|
||||
public enum AuthUserGender
|
||||
{
|
||||
[Description("男")]
|
||||
MALE = 1,
|
||||
[Description("女")]
|
||||
FEMALE = 0,
|
||||
[Description("未知")]
|
||||
UNKNOWN = -1
|
||||
}
|
||||
229
common/Tnb.CollectiveOAuth/Enums/EnumHelper/ArrayExtensions.cs
Normal file
229
common/Tnb.CollectiveOAuth/Enums/EnumHelper/ArrayExtensions.cs
Normal file
@@ -0,0 +1,229 @@
|
||||
namespace JNPF.Extras.CollectiveOAuth.Enums;
|
||||
|
||||
/// <summary>
|
||||
/// 数组,队列对象的列表类.
|
||||
/// </summary>
|
||||
public static class ArrayExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// 扩展 Dictionary 根据Value反向查找Key的方法.
|
||||
/// </summary>
|
||||
public static T1 Get<T1, T2>(this IEnumerable<KeyValuePair<T1, T2>> list, T2 t2)
|
||||
{
|
||||
foreach (KeyValuePair<T1, T2> obj in list)
|
||||
if (obj.Value.Equals(t2)) return obj.Key;
|
||||
return default(T1);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 扩展数组方法 可以在前或者后插入一个对象.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">对象.</typeparam>
|
||||
/// <param name="list"></param>
|
||||
/// <param name="obj">要插入的对象.</param>
|
||||
/// <param name="place">位置 after/before.</param>
|
||||
/// <returns></returns>
|
||||
public static IEnumerable<T> Inject<T>(this IEnumerable<T> list, T obj, ArrayInjectPlace place = ArrayInjectPlace.Top)
|
||||
{
|
||||
T[] list2 = new T[list.Count() + 1];
|
||||
int index = 0;
|
||||
foreach (T t in list)
|
||||
{
|
||||
list2[place == ArrayInjectPlace.Bottom ? index : index + 1] = t;
|
||||
}
|
||||
list2[place == ArrayInjectPlace.Bottom ? list.Count() : 0] = obj;
|
||||
return list2;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 将数组合并成为一个字符串.
|
||||
/// </summary>
|
||||
public static string Join<T>(this IEnumerable<T> list, char? c = ',')
|
||||
{
|
||||
return list.Join(c.ToString());
|
||||
}
|
||||
|
||||
public static string Join<T>(this IEnumerable<T> list, string split)
|
||||
{
|
||||
return string.Join(split, list);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 按指定条件过滤数组.
|
||||
/// </summary>
|
||||
/// <param name="ac">默认为过滤重复.</param>
|
||||
public static IEnumerable<T> Filter<T>(this IEnumerable<T> list, ArrayFilterRule filterRule = ArrayFilterRule.NoRepeater)
|
||||
{
|
||||
List<T> list2 = new List<T>();
|
||||
foreach (T t in list)
|
||||
{
|
||||
if (!list2.Contains(t)) list2.Add(t);
|
||||
}
|
||||
return list2;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 合并数组 并且去除重复项.
|
||||
/// </summary>
|
||||
/// <param name="converter">要比较的字段.</param>
|
||||
public static List<T> Merge<T, TOutput>(this IEnumerable<T> objList, Converter<T, TOutput> converter, params IEnumerable<T>[] objs)
|
||||
{
|
||||
List<T> list = objList.ToList();
|
||||
foreach (var obj in objs)
|
||||
{
|
||||
list.AddRange(obj.ToList().FindAll(t => !list.Exists(t1 => converter(t1).Equals(converter(t)))));
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取数组的索引项。 如果超出则返回类型的默认值.
|
||||
/// </summary>
|
||||
public static T GetIndex<T>(this IEnumerable<T> list, int index)
|
||||
{
|
||||
if (list == null || index >= list.Count() || index < 0) return default(T);
|
||||
return list.ToArray()[index];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 把数组所有元素,按照“参数=参数值”的模式用“&”字符拼接成字符串.
|
||||
/// </summary>
|
||||
/// <typeparam name="TKey"></typeparam>
|
||||
/// <typeparam name="TValue"></typeparam>
|
||||
/// <param name="list"></param>
|
||||
public static string ToQueryString<TKey, TValue>(this IEnumerable<KeyValuePair<TKey, TValue>> list)
|
||||
{
|
||||
return list.ToList().ConvertAll(t => string.Format("{0}={1}", t.Key, t.Value)).Join("&");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 除去数组中的空值和指定名称的参数并以字母a到z的顺序排序.
|
||||
/// </summary>
|
||||
/// <param name="filter">过滤规则 默认做为空判断</param>
|
||||
public static IEnumerable<KeyValuePair<TKey, TValue>> Filter<TKey, TValue>(this IEnumerable<KeyValuePair<TKey, TValue>> list, Func<TKey, TValue, bool> filter = null)
|
||||
{
|
||||
if (filter == null)
|
||||
{
|
||||
filter = (key, value) =>
|
||||
{
|
||||
return !string.IsNullOrEmpty(key.ToString()) && value != null;
|
||||
};
|
||||
}
|
||||
foreach (var item in list)
|
||||
{
|
||||
if (filter(item.Key, item.Value))
|
||||
yield return new KeyValuePair<TKey, TValue>(item.Key, item.Value);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 不包含指定的Key.
|
||||
/// </summary>
|
||||
public static IEnumerable<KeyValuePair<TKey, TValue>> Filter<TKey, TValue>(this IEnumerable<KeyValuePair<TKey, TValue>> list, params TKey[] filter)
|
||||
{
|
||||
return list.Filter((key, value) =>
|
||||
{
|
||||
return !string.IsNullOrEmpty(key.ToString()) && value != null && !filter.Contains(key);
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 按照Key从小大大拍列.
|
||||
/// </summary>
|
||||
/// <typeparam name="TKey"></typeparam>
|
||||
/// <typeparam name="TValue"></typeparam>
|
||||
/// <param name="list"></param>
|
||||
public static void Sort<TKey, TValue>(this IEnumerable<KeyValuePair<TKey, TValue>> list)
|
||||
{
|
||||
list = list.ToList().OrderBy(t => t.Key);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取父级的继承树(最多支持32级)
|
||||
/// 包括自己.
|
||||
/// </summary>
|
||||
/// <typeparam name="TValue">主键类型.</typeparam>
|
||||
/// <param name="obj">要查找的数组对象</param>
|
||||
/// <param name="id">当前对象的主键值</param>
|
||||
/// <param name="value">主键字段</param>
|
||||
/// <param name="parent">父级字段</param>
|
||||
/// <returns></returns>
|
||||
public static List<T> GetParent<T, TValue>(this List<T> obj, TValue id, Func<T, TValue> value, Func<T, TValue> parent)
|
||||
{
|
||||
int count = 0;
|
||||
T t = obj.Find(m => value.Invoke(m).Equals(id));
|
||||
List<T> list = new List<T>();
|
||||
while (t != null)
|
||||
{
|
||||
if (count > 32) break;
|
||||
list.Add(t);
|
||||
t = obj.Find(m => value.Invoke(m).Equals(parent.Invoke(t)));
|
||||
count++;
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取子集列表(包括自己).
|
||||
/// </summary>
|
||||
public static void GetChild<T, TValue>(this List<T> obj, TValue id, Func<T, TValue> value, Func<T, TValue> parent, ref List<T> list)
|
||||
{
|
||||
if (list == null) list = new List<T>();
|
||||
var objT = obj.Find(t => value.Invoke(t).Equals(id));
|
||||
if (objT != null)
|
||||
{
|
||||
list.Add(objT);
|
||||
foreach (T t in obj.FindAll(m => parent.Invoke(m).Equals(id)))
|
||||
{
|
||||
obj.GetChild(value.Invoke(t), value, parent, ref list);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取树形结构的子集执行方法.
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <typeparam name="TValue"></typeparam>
|
||||
/// <param name="obj">当前对象</param>
|
||||
/// <param name="id">当前父节点</param>
|
||||
/// <param name="value">获取主键的委托</param>
|
||||
/// <param name="parent">获取父值的委托</param>
|
||||
/// <param name="action">委托执行的方法 int 为当前的深度</param>
|
||||
/// <param name="depth">当前的深度</param>
|
||||
public static void GetTree<T, TValue>(this List<T> obj, TValue id, Func<T, TValue> value, Func<T, TValue> parent, Action<T, int> action, int depth = 0)
|
||||
{
|
||||
foreach (T t in obj.FindAll(m => parent.Invoke(m).Equals(id)))
|
||||
{
|
||||
action.Invoke(t, depth + 1);
|
||||
obj.GetTree(value.Invoke(t), value, parent, action, depth + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 数组过滤规则.
|
||||
/// </summary>
|
||||
public enum ArrayFilterRule
|
||||
{
|
||||
/// <summary>
|
||||
/// 过滤重复.
|
||||
/// </summary>
|
||||
NoRepeater
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 插入数组的位置.
|
||||
/// </summary>
|
||||
public enum ArrayInjectPlace
|
||||
{
|
||||
/// <summary>
|
||||
/// 在顶部插入.
|
||||
/// </summary>
|
||||
Top,
|
||||
|
||||
/// <summary>
|
||||
/// 在尾部追加.
|
||||
/// </summary>
|
||||
Bottom
|
||||
}
|
||||
209
common/Tnb.CollectiveOAuth/Enums/EnumHelper/EnumExtensions.cs
Normal file
209
common/Tnb.CollectiveOAuth/Enums/EnumHelper/EnumExtensions.cs
Normal file
@@ -0,0 +1,209 @@
|
||||
using System.Collections.Concurrent;
|
||||
using System.ComponentModel;
|
||||
using System.Reflection;
|
||||
|
||||
namespace JNPF.Extras.CollectiveOAuth.Enums;
|
||||
|
||||
/// <summary>
|
||||
/// 枚举拓展类.
|
||||
/// </summary>
|
||||
public static class EnumExtensions
|
||||
{
|
||||
private static ConcurrentDictionary<Enum, string> _concurrentDictionary = new ConcurrentDictionary<Enum, string>();
|
||||
private static ConcurrentDictionary<Type, Dictionary<string, string>> _concurrentDicDictionary = new ConcurrentDictionary<Type, Dictionary<string, string>>();
|
||||
|
||||
/// <summary>
|
||||
/// 锁对象.
|
||||
/// </summary>
|
||||
private static object objLock = new object();
|
||||
|
||||
/// <summary>
|
||||
/// 获取枚举的Code信息(Code).
|
||||
/// </summary>
|
||||
public static int GetCode(this Enum @this)
|
||||
{
|
||||
return Convert.ToInt32(@this);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取枚举的描述信息(Descripion).
|
||||
/// 支持位域,如果是位域组合值,多个按分隔符组合.
|
||||
/// </summary>
|
||||
public static string GetDesc(this Enum @this)
|
||||
{
|
||||
return _concurrentDictionary.GetOrAdd(@this, (key) =>
|
||||
{
|
||||
var type = key.GetType();
|
||||
var field = type.GetField(key.ToString());
|
||||
|
||||
// 如果field为null则应该是组合位域值,
|
||||
return field == null ? key.GetDescriptions() : GetDescription(field);
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取枚举的说明.
|
||||
/// </summary>
|
||||
/// <param name="em">枚举对象.</param>
|
||||
/// <param name="split">位枚举的分割符号(仅对位枚举有作用).</param>
|
||||
public static string GetDescriptions(this Enum em, string split = ",")
|
||||
{
|
||||
var names = em.ToString().Split(',');
|
||||
string[] res = new string[names.Length];
|
||||
var type = em.GetType();
|
||||
for (int i = 0; i < names.Length; i++)
|
||||
{
|
||||
var field = type.GetField(names[i].Trim());
|
||||
if (field == null) continue;
|
||||
res[i] = GetDescription(field);
|
||||
}
|
||||
|
||||
return string.Join(split, res);
|
||||
}
|
||||
|
||||
private static string GetDescription(FieldInfo field)
|
||||
{
|
||||
var att = Attribute.GetCustomAttribute(field, typeof(DescriptionAttribute), false);
|
||||
return att == null ? field.Name : ((DescriptionAttribute)att).Description;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 把枚举转换成为列表.
|
||||
/// </summary>
|
||||
public static List<EnumObject> ToList(this Type type)
|
||||
{
|
||||
List<EnumObject> list = new List<EnumObject>();
|
||||
foreach (object obj in Enum.GetValues(type))
|
||||
{
|
||||
list.Add(new EnumObject((Enum)obj));
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 构造UTable枚举json样式 eg.{"Resource":{"value":0,"name":"Resource","text":"自有资源"},"New":{"value":1,"name":"New","text":"业务费用"}}.
|
||||
/// </summary>
|
||||
/// <param name="type"></param>
|
||||
/// <returns></returns>
|
||||
public static Dictionary<string, EnumModel> GetEnumList(this Type type)
|
||||
{
|
||||
Dictionary<string, EnumModel> list = new Dictionary<string, EnumModel>();
|
||||
foreach (object obj in Enum.GetValues(type))
|
||||
{
|
||||
list.Add(((Enum)obj).ToString(), new EnumModel((Enum)obj));
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取枚举值+描述.
|
||||
/// </summary>
|
||||
/// <param name="enumType">Type,该参数的格式为typeof(需要读的枚举类型).</param>
|
||||
/// <returns>键值对.</returns>
|
||||
public static Dictionary<string, string> GetEnumItemValueDesc(Type enumType)
|
||||
{
|
||||
Dictionary<string, string> dic = new Dictionary<string, string>();
|
||||
Type typeDescription = typeof(DescriptionAttribute);
|
||||
FieldInfo[] fields = enumType.GetFields();
|
||||
string strText = string.Empty;
|
||||
string strValue = string.Empty;
|
||||
foreach (FieldInfo field in fields)
|
||||
{
|
||||
if (field.FieldType.IsEnum)
|
||||
{
|
||||
strValue = ((int)enumType.InvokeMember(field.Name, BindingFlags.GetField, null, null, null)).ToString();
|
||||
object[] arr = field.GetCustomAttributes(typeDescription, true);
|
||||
if (arr.Length > 0)
|
||||
{
|
||||
DescriptionAttribute aa = (DescriptionAttribute)arr[0];
|
||||
strText = aa.Description;
|
||||
}
|
||||
else
|
||||
{
|
||||
strText = field.Name;
|
||||
}
|
||||
dic.Add(strValue, strText);
|
||||
}
|
||||
}
|
||||
|
||||
return dic;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取枚举类型键值对.
|
||||
/// </summary>
|
||||
/// <param name="em"></param>
|
||||
/// <returns></returns>
|
||||
public static Dictionary<string, string> GetEunItemValueAndDesc(Type em)
|
||||
{
|
||||
return _concurrentDicDictionary.GetOrAdd(em, (key) =>
|
||||
{
|
||||
var type = key.GetType();
|
||||
if (_concurrentDicDictionary.ContainsKey(key))
|
||||
return _concurrentDicDictionary[key];
|
||||
else
|
||||
return GetEnumItemValueDesc(em);
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取枚举项+描述.
|
||||
/// </summary>
|
||||
/// <param name="enumType">Type,该参数的格式为typeof(需要读的枚举类型).</param>
|
||||
/// <returns>键值对.</returns>
|
||||
public static Dictionary<string, string> GetEnumItemDesc(Type enumType)
|
||||
{
|
||||
Dictionary<string, string> dic = new Dictionary<string, string>();
|
||||
FieldInfo[] fieldinfos = enumType.GetFields();
|
||||
foreach (FieldInfo field in fieldinfos)
|
||||
{
|
||||
if (field.FieldType.IsEnum)
|
||||
{
|
||||
object[] objs = field.GetCustomAttributes(typeof(DescriptionAttribute), false);
|
||||
dic.Add(field.Name, ((DescriptionAttribute)objs[0]).Description);
|
||||
}
|
||||
}
|
||||
return dic;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取枚举项描述信息 例如GetEnumDesc(Days.Sunday)
|
||||
/// </summary>
|
||||
/// <param name="en">枚举项 如Days.Sunday</param>
|
||||
/// <returns></returns>
|
||||
public static string GetEnumDesc(this Enum en)
|
||||
{
|
||||
Type type = en.GetType();
|
||||
MemberInfo[] memInfo = type.GetMember(en.ToString());
|
||||
if (memInfo != null && memInfo.Length > 0)
|
||||
{
|
||||
object[] attrs = memInfo[0].GetCustomAttributes(typeof(DescriptionAttribute), false);
|
||||
if (attrs != null && attrs.Length > 0)
|
||||
return ((DescriptionAttribute)attrs[0]).Description;
|
||||
}
|
||||
|
||||
return en.ToString();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 将注释转换成枚举值,匹配不上返回Null.
|
||||
/// </summary>
|
||||
/// <param name="type"></param>
|
||||
/// <param name="strDescription"></param>
|
||||
/// <returns></returns>
|
||||
public static int? GetEnumValByDescription(this Type type, string strDescription)
|
||||
{
|
||||
int? enumVal = null;
|
||||
foreach (object obj in Enum.GetValues(type))
|
||||
{
|
||||
Enum nEnum = (Enum)obj;
|
||||
if (nEnum.GetDesc() == strDescription)
|
||||
{
|
||||
enumVal = (int)Convert.ChangeType(nEnum, typeof(int));
|
||||
}
|
||||
}
|
||||
|
||||
return enumVal;
|
||||
}
|
||||
}
|
||||
24
common/Tnb.CollectiveOAuth/Enums/EnumHelper/EnumModel.cs
Normal file
24
common/Tnb.CollectiveOAuth/Enums/EnumHelper/EnumModel.cs
Normal file
@@ -0,0 +1,24 @@
|
||||
namespace JNPF.Extras.CollectiveOAuth.Enums;
|
||||
|
||||
/// <summary>
|
||||
/// 枚举模型.
|
||||
/// </summary>
|
||||
public struct EnumModel
|
||||
{
|
||||
/// <summary>
|
||||
/// 构造函数.
|
||||
/// </summary>
|
||||
/// <param name="um"></param>
|
||||
public EnumModel(Enum um)
|
||||
{
|
||||
this.value = (int)Convert.ChangeType(um, typeof(int));
|
||||
this.name = um.ToString();
|
||||
this.text = um.GetDesc();
|
||||
}
|
||||
|
||||
public int value { get; set; }
|
||||
|
||||
public string name { get; set; }
|
||||
|
||||
public string text { get; set; }
|
||||
}
|
||||
35
common/Tnb.CollectiveOAuth/Enums/EnumHelper/EnumObject.cs
Normal file
35
common/Tnb.CollectiveOAuth/Enums/EnumHelper/EnumObject.cs
Normal file
@@ -0,0 +1,35 @@
|
||||
namespace JNPF.Extras.CollectiveOAuth.Enums;
|
||||
|
||||
public struct EnumObject
|
||||
{
|
||||
public EnumObject(Enum um, string picture = null)
|
||||
{
|
||||
this.ID = (int)Convert.ChangeType(um, typeof(int));
|
||||
this.Name = um.ToString();
|
||||
this.Description = um.GetDesc();
|
||||
this.Picture = picture;
|
||||
}
|
||||
|
||||
public EnumObject(int id, string name)
|
||||
{
|
||||
this.ID = id;
|
||||
this.Name = this.Description = name;
|
||||
this.Picture = null;
|
||||
}
|
||||
|
||||
public EnumObject(int id, string name, string description, string picture)
|
||||
{
|
||||
this.ID = id;
|
||||
this.Name = name;
|
||||
this.Description = description;
|
||||
this.Picture = picture;
|
||||
}
|
||||
|
||||
public int ID;
|
||||
|
||||
public string Name;
|
||||
|
||||
public string Description;
|
||||
|
||||
public string Picture;
|
||||
}
|
||||
Reference in New Issue
Block a user