XFE Git
XFE Studio Git
Git 首页 全局搜索
XFE 主站 文档 NuGet

XFEExtension

【DLL】XFE各类拓展是一个C#的DLL库,旨在优化C#代码中常用语句的使用,并提供更简洁的访问方式,同时提供Xunit测试框架,快速搭建服务器/客户端,免费ChatGPTAPI接口,免费通讯服务器,XFE下载器,新增格式等

公开
关注 0 Fork 0 Star 0
UTF-8
using XFEExtension.NetCore.FormatExtension;

namespace XFEExtension.NetCore.XFEChatGPT.ChatGPTInnerClass.HelperClass;

/// <summary>
/// API密钥
/// </summary>
/// <param name="aPiKey">秘钥</param>
/// <param name="description">描述</param>
public class ApiKey(string aPiKey, string description)
{
    private static readonly char[] Separator = ['{', '}'];
    /// <summary>
    /// APIKEY
    /// </summary>
    public string Key { get; set; } = aPiKey;
    /// <summary>
    /// APIKey的描述
    /// </summary>
    public string Description { get; set; } = description;
    /// <summary>
    /// 转换为字符串
    /// </summary>
    /// <returns></returns>
    public override string ToString() => $"{{[+-{Description}-+][+-{Key}-+]}}";

    /// <summary>
    /// 将字符串转换为ApiKey的List
    /// </summary>
    /// <param name="keyString"></param>
    /// <returns></returns>
    public static List<ApiKey> ToApiKey(string keyString)
    {
        var keyGroup = keyString.Split(Separator);
        List<ApiKey> apiKeys = [];
        apiKeys.AddRange(from key in keyGroup select key.Split(XFEDictionary.EntrySeparator, StringSplitOptions.RemoveEmptyEntries) into oneKey where oneKey.Length == 2 select new ApiKey(oneKey[1], oneKey[0]));
        return apiKeys;
    }
}