XFEExtension.NetCore
2.9.0
See the version list below for details.
dotnet add package XFEExtension.NetCore --version 2.9.0
NuGet\Install-Package XFEExtension.NetCore -Version 2.9.0
<PackageReference Include="XFEExtension.NetCore" Version="2.9.0" />
paket add XFEExtension.NetCore --version 2.9.0
#r "nuget: XFEExtension.NetCore, 2.9.0"
// Install XFEExtension.NetCore as a Cake Addin #addin nuget:?package=XFEExtension.NetCore&version=2.9.0 // Install XFEExtension.NetCore as a Cake Tool #tool nuget:?package=XFEExtension.NetCore&version=2.9.0
XFEExtension (XFEExtension)
描述
XFEExtension是一个C#的DLL库,旨在优化C#代码中常用语句的使用,并提供更简洁的访问方式,同时提供Xunit测试框架,快速搭建服务器/客户端,免费ChatGPTAPI接口,免费通讯服务器,XFE下载器,新增格式等
用途
XFEExtension库适用于各种C#项目,特别适合在需要提高代码可读性的情况下使用。它包含了许多常见操作的拓展方法,使得代码编写更加高效和简便。以下是一些XFEExtension的用途示例:
简化代码访问: XFEExtension提供了更简洁的语法,使得代码中的访问操作更加清晰和易读。
优化性能: 通过使用XFEExtension,您可以执行各种性能优化操作,提高应用程序的效率。
加速开发: 通过减少样板代码,XFEExtension可以加速项目的开发过程,同时提高代码的可维护性。
示例(使用前记得进行相应的引用)
自动实现配置文件的存储
基础用法
//创建配置文件类
static partial class SystemProfile
{
[ProfileProperty]
static string name;
[ProfileProperty]
static int _age;
}
//使用配置文件
class Program
{
static void Main(string[] args)
{
SystemProfile.Name = "Test";//在设置值的时候会自动记录并储存
//SystemProfile.Age = 1;
Console.WriteLine(SystemProfile.Name);
Console.WriteLine(SystemProfile.Age);//下次打开程序会自动读取上次程序退出时储存的值
}
}
设置get和set方法
static partial class SystemProfile
{
[ProfileProperty]
[ProfilePropertyAddGet(@"Console.WriteLine(""获取了Name"")")]
[ProfilePropertyAddGet("return name")]
[ProfilePropertyAddSet(@"Console.WriteLine(""设置了Name"")")]
[ProfilePropertyAddSet("name = value")]
private static string name = string.Empty;
[ProfileProperty]
[ProfilePropertyAddGet(@"Console.WriteLine(""获取了Age"")")]
[ProfilePropertyAddGet("return _age")]
[ProfilePropertyAddSet(@"Console.WriteLine(""设置了Age"")")]
[ProfilePropertyAddSet("_age = value")]
private static int _age;
}
设置初始值
static partial class SystemProfile
{
[ProfileProperty]
private static string name = "John Wick";
[ProfileProperty]
private static int _age = 59;
}
为属性添加注释
static partial class SystemProfile
{
/// <summary>
/// 名称
/// 这段注释会自动添加至自动生成的Name属性上
/// </summary>
[ProfileProperty]
private static string name;
[ProfileProperty]
private static int _age;
}
使用LANDeviceDetector来检测本地局域网内的所有设备
基础用法
var lANDeviceDetector = new LANDeviceDetector();
lANDeviceDetector.DeviceFind += (sender) =>
{
Console.WriteLine($"IP地址:{sender.IPAddress}\t设备名称:{sender.DeviceName}");
};
await lANDeviceDetector.StartDetecting();
自定义扫描频段
var lANDeviceDetector = new LANDeviceDetector("100.73.121.*");//这将扫描100.73.121.1到100.73.121.255的IP地址
lANDeviceDetector.DeviceFind += (sender) =>
{
Console.WriteLine($"IP地址:{sender.IPAddress}\t设备名称:{sender.DeviceName}");
};
await lANDeviceDetector.StartDetecting();
自定义超时
var lANDeviceDetector = new LANDeviceDetector("100.73.121.*", 2000);//这将会设置超时为2000ms
lANDeviceDetector.DeviceFind += (sender) =>
{
Console.WriteLine($"IP地址:{sender.IPAddress}\t设备名称:{sender.DeviceName}");
};
await lANDeviceDetector.StartDetecting();
使用X方法分析对象信息,简化调试流程
在控制台输出(仅适用于C#的控制台应用程序)
var testClass = new TestClass("测试名称", "测试描述", 15);//假如这是你需要分析的某个对象
testClass.X();//这会将该对象的所有信息输出到控制台
在调试信息中输出(使用与所有类型的C#程序)
var testClass = new TestClass("测试名称", "测试描述", 15);//假如这是你需要分析的某个对象
testClass.XL();//这会将该对象的所有信息输出到调试信息输出中
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加密算法示例
// 使用XFEExtension来进行加密操作
string text = "这是一段将要加密的文本";
$"未加密内容:{text}".CW();
string password = "这是一个秘钥";
string encrypt = text.XEAEncrypt(password);//加密
Console.WriteLine("加密内容:" + encrypt);
Console.WriteLine("解密内容:" + encrypt.XEADecrypt(password));//解密
特性操作示例
// 使用XFEExtension来简化特性读取操作
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 = "XFEExtension.NetCore.nuget",
FileSegmentCount = 9 //设置9个线程来加速下载,建议数量不超过15个
};
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 (7)
Showing the top 5 NuGet packages that depend on XFEExtension.NetCore:
Package | Downloads |
---|---|
XFEExtension.NetCore.MemoryEditor
内存读写工具,支持使用基址,内置内存管理器 |
|
XFEExtension.NetCore.XApp.Core
XApp开发支持核心包 |
|
XFEExtension.NetCore.AutoConfig
自动实现配置文件的存储 |
|
XFEExtension.NetCore.XUnit
提供方便快捷的测试,无需编写Main方法,可直接添加特性在类或方法上进行测试 |
|
XFEExtension.NetCore.XFEConsole
XFEConsole是一个可以运行用户进行远程输出的调试辅助工具,需要配合XFE工具箱来使用,当然也可以根据本DLL内的架构搭建一个调试工具 |
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
3.1.4 | 69 | 10/23/2024 |
3.1.3 | 87 | 10/19/2024 |
3.1.2 | 87 | 10/11/2024 |
3.1.1 | 81 | 10/11/2024 |
3.1.0 | 78 | 10/11/2024 |
3.0.7 | 94 | 10/5/2024 |
3.0.6 | 81 | 10/5/2024 |
3.0.5 | 83 | 10/4/2024 |
3.0.4 | 73 | 10/4/2024 |
3.0.3 | 153 | 8/18/2024 |
3.0.2 | 154 | 8/9/2024 |
3.0.1 | 103 | 8/7/2024 |
3.0.0 | 164 | 6/4/2024 |
2.11.0 | 136 | 6/3/2024 |
2.10.3 | 102 | 5/26/2024 |
2.10.2 | 87 | 5/11/2024 |
2.10.1 | 75 | 5/11/2024 |
2.10.0 | 78 | 5/11/2024 |
2.9.1 | 159 | 4/29/2024 |
2.9.0 | 280 | 4/18/2024 |
2.8.5 | 113 | 4/16/2024 |
2.8.4 | 118 | 4/16/2024 |
2.8.3 | 115 | 4/16/2024 |
2.8.2 | 103 | 4/16/2024 |
2.8.0 | 122 | 4/12/2024 |
2.7.1 | 215 | 4/9/2024 |
2.7.0 | 117 | 4/9/2024 |
2.6.5 | 105 | 4/9/2024 |
2.6.4 | 110 | 4/9/2024 |
2.6.3 | 122 | 4/9/2024 |
2.6.2 | 99 | 4/8/2024 |
2.6.1 | 114 | 4/6/2024 |
2.6.0 | 106 | 4/5/2024 |
2.5.0 | 121 | 3/31/2024 |
2.4.1 | 143 | 3/20/2024 |
2.4.0 | 127 | 3/19/2024 |
2.3.3 | 137 | 3/19/2024 |
2.3.2 | 132 | 3/16/2024 |
2.3.1 | 129 | 3/16/2024 |
2.3.0 | 122 | 3/16/2024 |
2.2.2 | 129 | 3/13/2024 |
2.2.1 | 126 | 3/13/2024 |
2.2.0 | 131 | 3/13/2024 |
2.1.0 | 135 | 3/13/2024 |
2.0.1 | 122 | 3/8/2024 |
2.0.0 | 156 | 3/7/2024 |
## 调整
修复原本的CyberCommServer中的一些错误
## 新增
CyberCommServer现支持Http请求
## 严重
无