最近、カスタム プリンシパルの作成方法を検索し、答えを得ましたが、理解できないことが 1 つあります。スタック オーバーフローでこの解決策を見つけました
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Security.Principal;
namespace workflow.Authorize
{
interface ICustomPrincipal : IPrincipal
{
int Id { get; set; }
string FirstName { get; set; }
string LastName { get; set; }
}
public class CustomPrincipal : ICustomPrincipal
{
public IIdentity Identity { get; private set; }
public bool IsInRole(string role) {
if(this.Roles.Contains(role))
return true;
else
return false;
}
public CustomPrincipal(string email)
{
this.Identity = new GenericIdentity(email);
}
public int Id { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public string Roles { get; set; }
}
public class CustomPrincipalSerializeModel
{
public int Id { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public string Roles { get; set; }
}
}
しかし、私が理解していないのは、なぜ開発者が ICustomPrincipal インターフェイスを作成し、CustomPrincipal にそれを強制的に継承させたのか、なぜ CustomPrincipal クラスが IPrincipal インターフェイスから直接継承しないのかということです