<commit_before>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Threading.Tasks;

namespace Wodsoft.ComBoost.Security
{
    public abstract class GeneralSecurityProvider : ISecurityProvider
    {
        public string ConvertRoleToString(object role)
        {
            if (role == null)
                throw new ArgumentNullException(nameof(role));
            if (role is IRoleName)
                return ((IRoleName)role).RoleName;
            Type type = role.GetType();
            if (type.GetTypeInfo().IsValueType)
            {
                string name = type.FullName + "-";
                name += role.ToString();
                return name;
            }
            throw new NotSupportedException("不支持将该对象转换为字符串。");
        }

        public Task<IPermission> GetPermissionAsync(string identity)
        {
            return GetPermissionByIdentity(identity);
        }

        public Task<IPermission> GetPermissionAsync(IDictionary<string, string> properties)
        {
            if (properties.ContainsKey("username"))
                return GetPermissionByUsername(properties["username"]);
            else if (properties.ContainsKey("identity"))
                return GetPermissionByIdentity(properties["identity"]);
            else if (properties.ContainsKey("id"))
                return GetPermissionByIdentity(properties["id"]);
            else
                throw new NotSupportedException("不支持的属性。");
        }

        protected abstract Task<IPermission> GetPermissionByIdentity(string identity);

        protected abstract Task<IPermission> GetPermissionByUsername(string username);
    }
}
<commit_msg>更改为虚方法<commit_after>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Threading.Tasks;

namespace Wodsoft.ComBoost.Security
{
    public abstract class GeneralSecurityProvider : ISecurityProvider
    {
        public string ConvertRoleToString(object role)
        {
            if (role == null)
                throw new ArgumentNullException(nameof(role));
            if (role is IRoleName)
                return ((IRoleName)role).RoleName;
            Type type = role.GetType();
            if (type.GetTypeInfo().IsValueType)
            {
                string name = type.FullName + "-";
                name += role.ToString();
                return name;
            }
            throw new NotSupportedException("不支持将该对象转换为字符串。");
        }

        public virtual Task<IPermission> GetPermissionAsync(string identity)
        {
            return GetPermissionByIdentity(identity);
        }

        public virtual Task<IPermission> GetPermissionAsync(IDictionary<string, string> properties)
        {
            if (properties.ContainsKey("username"))
                return GetPermissionByUsername(properties["username"]);
            else if (properties.ContainsKey("identity"))
                return GetPermissionByIdentity(properties["identity"]);
            else if (properties.ContainsKey("id"))
                return GetPermissionByIdentity(properties["id"]);
            else
                throw new NotSupportedException("不支持的属性。");
        }

        protected abstract Task<IPermission> GetPermissionByIdentity(string identity);

        protected abstract Task<IPermission> GetPermissionByUsername(string username);
    }
}

{'fraction_non_alphanumeric': 0.08881098451650599, 'fraction_numerical': 0.0, 'mean_word_length': 2.3018322082931535, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4635678', 'n_tokens_mistral': 840, 'n_tokens_neox': 831, 'n_words': 176}