11using System ;
2- using System . Diagnostics ;
2+ using System . Collections . Generic ;
33using System . Linq ;
44using Bing . Helpers ;
55using Bing . Security . Claims ;
@@ -36,11 +36,7 @@ public static T FindClaimValue<T>(this ICurrentUser currentUser, string claimTyp
3636 /// 获取用户标识
3737 /// </summary>
3838 /// <param name="currentUser">当前用户</param>
39- public static Guid GetUserId ( this ICurrentUser currentUser )
40- {
41- Debug . Assert ( currentUser . UserId != null , "currentUser.UserId != null" ) ;
42- return Conv . ToGuid ( currentUser . UserId ) ;
43- }
39+ public static Guid GetUserId ( this ICurrentUser currentUser ) => Conv . ToGuid ( currentUser . UserId ) ;
4440
4541 /// <summary>
4642 /// 获取用户标识
@@ -97,6 +93,8 @@ public static string GetPhoneNumber(this ICurrentUser currentUser)
9793 return result ;
9894 }
9995
96+ #region Application(应用程序)
97+
10098 /// <summary>
10199 /// 获取应用程序标识
102100 /// </summary>
@@ -122,6 +120,10 @@ public static string GetPhoneNumber(this ICurrentUser currentUser)
122120 /// <param name="currentUser">当前用户</param>
123121 public static string GetApplicationName ( this ICurrentUser currentUser ) => currentUser . FindClaim ( BingClaimTypes . ApplicationName ) ? . Value ;
124122
123+ #endregion
124+
125+ #region Tenant(租户)
126+
125127 /// <summary>
126128 /// 获取租户标识
127129 /// </summary>
@@ -147,10 +149,42 @@ public static string GetPhoneNumber(this ICurrentUser currentUser)
147149 /// <param name="currentUser">当前用户</param>
148150 public static string GetTenantName ( this ICurrentUser currentUser ) => currentUser . FindClaim ( BingClaimTypes . TenantName ) ? . Value ;
149151
152+ #endregion
153+
154+ #region Role(角色)
155+
156+ /// <summary>
157+ /// 获取角色标识列表
158+ /// </summary>
159+ /// <param name="currentUser">当前用户</param>
160+ public static List < Guid > GetRoleIds ( this ICurrentUser currentUser ) => GetRoleIds < Guid > ( currentUser ) ;
161+
162+ /// <summary>
163+ /// 获取角色标识列表
164+ /// </summary>
165+ /// <typeparam name="T">类型</typeparam>
166+ /// <param name="currentUser">当前用户</param>
167+ public static List < T > GetRoleIds < T > ( this ICurrentUser currentUser )
168+ {
169+ var result = currentUser . FindClaimValue ( BingClaimTypes . RoleIds ) ;
170+ return Conv . ToList < T > ( string . IsNullOrWhiteSpace ( result )
171+ ? currentUser . FindClaimValue ( BingClaimTypes . Role )
172+ : result ) ;
173+ }
174+
175+ /// <summary>
176+ /// 获取角色编码列表
177+ /// </summary>
178+ /// <param name="currentUser">当前用户</param>
179+ public static string [ ] GetRoleCodes ( this ICurrentUser currentUser ) => currentUser . FindClaims ( BingClaimTypes . RoleCodes ) ? . Select ( x => x . Value ) . ToArray ( ) ;
180+
150181 /// <summary>
151182 /// 获取角色名称列表
152183 /// </summary>
153184 /// <param name="currentUser">当前用户</param>
154185 public static string [ ] GetRoleNames ( this ICurrentUser currentUser ) => currentUser . FindClaims ( BingClaimTypes . RoleNames ) ? . Select ( x => x . Value ) . ToArray ( ) ;
186+
187+ #endregion
188+
155189 }
156190}
0 commit comments