XFE各类拓展.NetCore
1.7.6
由于命名空间等诸多中文问题,现将项目正式更名为XFEExtension.NetCore
有关兼容问题,仅需将所有的'XFE各类拓展'均替换为'XFEExtension'即可完美兼容
dotnet add package XFE各类拓展.NetCore --version 1.7.6
NuGet\Install-Package XFE各类拓展.NetCore -Version 1.7.6
<PackageReference Include="XFE各类拓展.NetCore" Version="1.7.6" />
paket add XFE各类拓展.NetCore --version 1.7.6
#r "nuget: XFE各类拓展.NetCore, 1.7.6"
// Install XFE各类拓展.NetCore as a Cake Addin #addin nuget:?package=XFE各类拓展.NetCore&version=1.7.6 // Install XFE各类拓展.NetCore as a Cake Tool #tool nuget:?package=XFE各类拓展.NetCore&version=1.7.6
XFEExtension (XFE各类拓展)
描述
XFE各类拓展是一个C#的DLL库,旨在优化C#代码中常用语句的使用,并提供更简洁的访问方式,同时提供Xunit测试框架,快速搭建服务器/客户端,免费ChatGPTAPI接口,免费通讯服务器,XFE下载器,新增格式等
用途
XFE各类拓展库适用于各种C#项目,特别适合在需要提高代码可读性的情况下使用。它包含了许多常见操作的拓展方法,使得代码编写更加高效和简便。以下是一些XFEExtension的用途示例:
简化代码访问: XFE各类拓展提供了更简洁的语法,使得代码中的访问操作更加清晰和易读。
优化性能: 通过使用XFE各类拓展,您可以执行各种性能优化操作,提高应用程序的效率。
加速开发: 通过减少样板代码,XFE各类拓展可以加速项目的开发过程,同时提高代码的可维护性。
示例(使用前记得进行相应的引用)
XFE的ChatGPT使用示例
最简单的用法
//询问GPT并接收回复
var result = await XFEChatGPT.SendAndGetGPTResponse("你好");
Console.WriteLine(result);
一般用法
//使用XFEChatGPT类来进行GPT的交互
XFEChatGPT xFEChatGPT = new XFEChatGPT("你是一个人工智能AI", true);
//订阅事件
xFEChatGPT.XFEChatGPTMessageReceived += (sender, e) =>
{
switch (e.GenerateState)
{
case GenerateState.Start:
Console.Write("【输出开始】ChatGPT:");
break;
case GenerateState.Continue:
Console.Write(e.Message);
break;
case GenerateState.End:
Console.WriteLine("【输出完成】");
break;
case GenerateState.Error:
Console.WriteLine($"【发生错误】{e.Message}");
break;
default:
break;
}
};
//输入询问内容
var askContent = Console.ReadLine();
//发送生成随机ID并询问内容
xFEChatGPT.SendGPTMessage(Guid.NewGuid().ToString(), askContent);
推荐用法
//创建有记忆功能的XFEChatGPT对象
MemorableXFEChatGPT memorableXFEChatGPT = new MemorableXFEChatGPT();
//创建一个新的对话并设置System内容
memorableXFEChatGPT.CreateDialog("新的对话ID", "你是一个由寰宇朽力网络科技开发的人工智能AI", true, true);
//订阅消息接收事件
memorableXFEChatGPT.XFEChatGPTMessageReceived += (sender, e) =>
{
switch (e.GenerateState)
{
case GenerateState.Start:
Console.Write("【输出开始】ChatGPT:");
break;
case GenerateState.Continue:
Console.Write(e.Message);
break;
case GenerateState.End:
Console.WriteLine("【输出完成】");
break;
case GenerateState.Error:
Console.WriteLine($"【发生错误】{e.Message}");
break;
default:
break;
}
};
//读取询问内容
var askContent = Console.ReadLine();
//填写之前创建的对话ID,生成随机的消息ID,并输入刚刚读取的询问内容
memorableXFEChatGPT.AskChatGPT("新的对话ID", Guid.NewGuid().ToString(), askContent);
自动生成实现类
[CreateImpl]
abstract class TestAbstractClass(int num)
{
public int Num { get; set; } = num;
}
class Program
{
static void Main(string[] args)
{
var testAbstractClass = new TestAbstractClassImpl(123);
Console.WriteLine(testAbstractClass.Num);
}
}
IO流拓展操作示例
// 使用XFEExtension来简化文件读取/写入操作
"Hello World!".WriteIn("test.txt");
string txt = "test.txt".ReadOut();
XEA加密算法示例
// 使用XFE各类拓展来进行加密操作
string text = "这是一段将要加密的文本";
$"未加密内容:{text}".CW();
string password = "这是一个秘钥";
string encrypt = text.XEAEncrypt(password);//加密
Console.WriteLine("加密内容:" + encrypt);
Console.WriteLine("解密内容:" + encrypt.XEADecrypt(password));//解密
特性操作示例
// 使用XFE各类拓展来简化特性读取操作
string str = testObject.GetAttribute<string>();
使用XUnit测试框架
[CTest]
class TestClass : XFECode
{
[MTest]
void Test()
{
Assert(true, "断言内容");
}
}
public class Program : XFECode
{
public static void Main(string[] args)
{
Pause();
}
}
快速搭建网络通讯服务器
public class CustomServer
{
CyberCommServer CyberCommServer { get; } = new("http://127.0.0.1:19019/");
public async Task StartServer()
{
CyberCommServer.ServerStarted += CyberCommServer_ServerStarted;
CyberCommServer.ConnectionClosed += CyberCommServer_ConnectionClosed;
CyberCommServer.ClientConnected += CyberCommServer_ClientConnected;
CyberCommServer.MessageReceived += CyberCommServer_MessageReceived;
await CyberCommServer.StartCyberCommServer();
}
private void CyberCommServer_MessageReceived(object? sender, CyberCommServerEventArgs e)
{
e.ReplyMessage("服务器已接收消息");
Console.WriteLine($"收到客户端[{e.IpAddress}]消息:{e.TextMessage}");//明文传输实例
}
private void CyberCommServer_ClientConnected(object? sender, CyberCommServerEventArgs e)
{
Console.WriteLine($"新客户端连接:{e.IpAddress}");
}
private void CyberCommServer_ConnectionClosed(object? sender, CyberCommServerEventArgs e)
{
Console.WriteLine($"客户端[{e.IpAddress}]断开连接");
}
private void CyberCommServer_ServerStarted(object? sender, EventArgs e)
{
Console.WriteLine("服务器已启动");
}
}
快速搭建网络通讯客户端
public class CustomClient
{
CyberCommClient CyberCommClient { get; } = new("http://127.0.0.1:19019/");
public async Task StartClient()
{
CyberCommClient.Connected += CyberCommClient_Connected;
CyberCommClient.ConnectionClosed += CyberCommClient_ConnectionClosed;
CyberCommClient.MessageReceived += CyberCommClient_MessageReceived;
await CyberCommClient.StartCyberCommClient();
}
private void CyberCommClient_MessageReceived(object? sender, CyberCommClientEventArgs e)
{
Console.WriteLine($"收到消息:{e.TextMessage}");//接收明文消息
//此处可以进行消息回复
//e.ReplyMessage();
}
private void CyberCommClient_ConnectionClosed(object? sender, EventArgs e)
{
Console.WriteLine("与服务器断开连接");
}
private void CyberCommClient_Connected(object? sender, EventArgs e)
{
Console.WriteLine("已连接到服务器");
CyberCommClient.SendTextMessage("这是一条测试消息");//以明文消息为示例
}
}
使用XCC网络通讯API接口快速搭建聊天室
XCCNetWork xCCNetWork = new();//创建XCC网络通讯基础
var group = xCCNetWork.CreateGroup("测试群组", "测试人员");//创建网络通讯中的群组,输入群组名,群内名称
#region 订阅事件
xCCNetWork.Connected += (sender, e) =>
{
Console.WriteLine($"群组:{e.Group.GroupId}\t连接成功");
group.SendTextMessage("测试消息");
};
xCCNetWork.ConnectionClosed += (sender, e) =>
{
Console.WriteLine($"群组:{e.Group.GroupId}\t断开连接");
};
xCCNetWork.TextMessageReceived += (sender, e) =>
{
Console.WriteLine($"群组:{e.Group.GroupId}\t收到文本消息:{e.TextMessage}");
};
#endregion
await group.StartXCC();//启动该群组的网络通讯
使用XFE下载器下载文件(支持继续上次下载等操作)
XFEDownloader xFEDownloader = new()
{
DownloadUrl = "https://www.nuget.org/api/v2/package/XFE%E5%90%84%E7%B1%BB%E6%8B%93%E5%B1%95.NetCore/1.2.2",
SavePath = "XFE各类拓展.NetCore.nuget"
};
xFEDownloader.BufferDownloaded += (sender, e) =>
{
Console.WriteLine($"进度:{e.DownloadedBufferSize.FileSize()}/{e.TotalBufferSize?.FileSize()}");
};
await xFEDownloader.Download();
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
-
net8.0
- No dependencies.
NuGet packages (1)
Showing the top 1 NuGet packages that depend on XFE各类拓展.NetCore:
Package | Downloads |
---|---|
XFE各类拓展.NetCore.XUnit
提供方便快捷的测试,无需编写Main方法,可直接添加特性在类或方法上进行测试 |
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated | |
---|---|---|---|
1.7.6 | 155 | 3/7/2024 | |
1.7.5 | 116 | 3/6/2024 | |
1.7.4 | 118 | 3/6/2024 | |
1.7.3 | 88 | 3/6/2024 | |
1.7.2 | 93 | 3/6/2024 | |
1.7.1 | 109 | 3/6/2024 | |
1.7.0 | 94 | 3/5/2024 | |
1.6.3 | 117 | 3/5/2024 | |
1.6.2 | 100 | 2/14/2024 | |
1.6.1 | 136 | 2/13/2024 | |
1.6.0 | 111 | 2/12/2024 | |
1.5.3 | 128 | 2/11/2024 | |
1.5.2 | 126 | 2/10/2024 | |
1.5.1 | 124 | 2/10/2024 | |
1.5.0 | 114 | 2/6/2024 | |
1.4.1 | 131 | 1/7/2024 | |
1.4.0 | 105 | 1/6/2024 | |
1.3.2 | 124 | 1/6/2024 | |
1.3.1 | 115 | 1/5/2024 | |
1.3.0 | 115 | 1/5/2024 | |
1.2.3 | 216 | 12/8/2023 | |
1.2.2 | 110 | 12/5/2023 | |
1.1.1 | 118 | 12/4/2023 | |
1.1.0 | 119 | 12/3/2023 |
## 调整
为配置文件属性添加代码分析器及快速操作的实现
## 新增
无
## 严重
无