C# 标准库
EasyBot 将 C# 标准库(System 命名空间)映射到了插件运行环境中的 dotnet 命名空间。通过 dotnet 命名空间,你可以访问 System 命名空间的所有内容。
基本用法
控制台输出
// 对应 System.Console.WriteLine
dotnet.Console.WriteLine("Hello World!");
// 格式化输出
dotnet.Console.WriteLine("用户 {0} 发送了消息: {1}", userName, message);
// 输出到错误流
dotnet.logger.error.WriteLine("这是一个错误消息");
字符串操作
// 对应 System.String 的静态方法
const result = dotnet.String.Format("Hello {0}!", "World");
const isEmpty = dotnet.String.IsNullOrEmpty(someString);
const isWhitespace = dotnet.String.IsNullOrWhiteSpace(someString);
// 字符串连接
const joined = dotnet.String.Join(", ", ["apple", "banana", "orange"]);
数学运算
// 对应 System.Math
const max = dotnet.Math.Max(10, 20);
const min = dotnet.Math.Min(10, 20);
const abs = dotnet.Math.Abs(-5);
const sqrt = dotnet.Math.Sqrt(16);
const pow = dotnet.Math.Pow(2, 3);
const round = dotnet.Math.Round(3.14159, 2);
日期时间
// 对应 System.DateTime
const now = dotnet.DateTime.Now;
const utcNow = dotnet.DateTime.UtcNow;
const today = dotnet.DateTime.Today;
// 创建特定日期
const specificDate = new dotnet.DateTime(2024, 1, 1);
// 日期格式化
const formatted = now.ToString("yyyy-MM-dd HH:mm:ss");