XFEExtension
【DLL】XFE各类拓展是一个C#的DLL库,旨在优化C#代码中常用语句的使用,并提供更简洁的访问方式,同时提供Xunit测试框架,快速搭建服务器/客户端,免费ChatGPTAPI接口,免费通讯服务器,XFE下载器,新增格式等
XFEstudio/XFEExtension
更新了TODO待办任务提醒的处理方式和相关配置
在README.md文件中,增加了对XFEExtension库和XUnit测试框架的描述,以及如何在csproj文件中设置配置和使用TODO待办任务提醒的示例代码。在XFEExtension.NetCore.Analyzer.Test.csproj文件中,修改了TodoListWarningLevel的值,并将TodoList的值设为false。在AnalyzerReleases.Shipped.md和AnalyzerReleases.Unshipped.md文件中,添加了新的规则,用于处理TODO待办任务提醒的诊断。在ProfileExtensionDiagnostics.cs文件中,移除了PropertyOrFieldNotStaticId相关的代码,并在SupportedDiagnostics中移除了对应的引用。在TodoCommentAnalyzerDiagnostics.cs文件中,添加了对正则表达式的引用,修改了对TODO待办任务提醒的处理方式,现在可以根据TODO后的数字来设置警告等级,并对应修改了警告等级的获取方式。在GeneratorOptions.cs文件中,修改了EnableTodoList和TodoListWarningLevel的名称和类型,并对应修改了在GetOptions方法中的处理方式。在XFEExtension.NetCore.csproj文件中,更新了包的版本号,并在发布说明中添加了对新功能的描述。
47b7145
代码差异
@@ -2,7 +2,7 @@
## 描述
XFEExtension是一个C#的DLL库,旨在优化C#代码中常用语句的使用,并提供更简洁的访问方式,同时提供Xunit测试框架,快速搭建服务器/客户端,免费ChatGPTAPI接口,免费通讯服务器,XFE下载器,新增格式等
XFEExtension是一个C#的DLL库,旨在优化C#代码中常用语句的使用,并提供更简洁的访问方式,同时提供XUnit测试框架,快速搭建服务器/客户端,免费ChatGPTAPI接口,免费通讯服务器,XFE下载器,新增格式等
## 用途
@@ -14,10 +14,43 @@ XFEExtension库适用于各种C#项目,特别适合在需要提高代码可读
- **加速开发:** 通过减少样板代码,XFEExtension可以加速项目的开发过程,同时提高代码的可维护性。
---
## 设置csproj文件配置
```xml
<PropertyGroup>
//设置是否启用自动配置文件
<AutoProfile>true</AutoProfile>
//设置是否启用自动路径
<AutoPath>true</AutoPath>
//设置是否启用TODO待办任务提醒
<TodoList>true</TodoList>
//设置待办任务的提示级别
<TodoListWarningLevel>3</TodoListWarningLevel>
</PropertyGroup>
```
---
# 示例(使用前记得进行相应的引用)
---
## TODO待办任务提醒
```csharp
//TODO: 这是一个待办任务,使用默认提示级别
//TODO:1 这是一个待办任务,使用提示级别
//TODO:3 这是一个待办任务,使用错误提示级别
//提示级别:0-隐藏,1-提示,2-警告,3-错误
```
---
## 自动实现配置文件的存储
#### 基础用法
@@ -6,7 +6,8 @@
<Nullable>enable</Nullable>
<OutputType>Exe</OutputType>
<AutoPath>false</AutoPath>
<TodoListWarningLevel>Info</TodoListWarningLevel>
<TodoListWarningLevel>1</TodoListWarningLevel>
<TodoList>false</TodoList>
<AutoProfile>false</AutoProfile>
</PropertyGroup>
@@ -5,4 +5,12 @@
Rule ID | Category | Severity | Notes
--------|----------|----------|-------
XFE0002 | XFEExtension.NetCore.Analyzer.Diagnostics | Error | ProfileExtensionDiagnostics, [Documentation](https://www.xfegzs.com/codespace/diagnostics/XFE0002.html)
XFW0001 | XFEExtension.NetCore.Analyzer.Diagnostics | Warning | ProfileExtensionDiagnostics, [Documentation](https://www.xfegzs.com/codespace/diagnostics/XFW0001.html)
XFW0001 | XFEExtension.NetCore.Analyzer.Diagnostics | Warning | ProfileExtensionDiagnostics, [Documentation](https://www.xfegzs.com/codespace/diagnostics/XFW0001.html)
## Release 2.10.4
### New Rules
Rule ID | Category | Severity | Notes
--------|----------|----------|-------
TODO | XFEExtension.NetCore.Analyzer.Diagnostics | `Dynamic` | TodoCommentAnalyzerDiagnostics, [Documentation](https://www.xfegzs.com/codespace/diagnostics/TODO.html)
@@ -7,5 +7,4 @@ Rule ID | Category | Severity | Notes
--------|----------|----------|-------
TODO | XFEExtension.NetCore.Analyzer.Diagnostics | `Dynamic` | TodoCommentAnalyzerDiagnostics, [Documentation](https://www.xfegzs.com/codespace/diagnostics/TODO.html)
XFE0002 | XFEExtension.NetCore.Analyzer.Diagnostics | Error | ProfileExtensionDiagnostics, [Documentation](https://www.xfegzs.com/codespace/diagnostics/XFE0002.html)
XFE0003 | XFEExtension.NetCore.Analyzer.Diagnostics | Error | ProfileExtensionDiagnostics, [Documentation](https://www.xfegzs.com/codespace/diagnostics/XFE0003.html)
XFW0001 | XFEExtension.NetCore.Analyzer.Diagnostics | Warning | ProfileExtensionDiagnostics, [Documentation](https://www.xfegzs.com/codespace/diagnostics/XFW0001.html)
@@ -12,7 +12,6 @@ namespace XFEExtension.NetCore.Analyzer.Diagnostics
public class ProfileExtensionDiagnostics : DiagnosticAnalyzer
{
public const string AddGetNoResultErrorId = "XFE0002";
public const string PropertyOrFieldNotStaticId = "XFE0003";
public const string AddSetNoSetResultWarningId = "XFW0001";
public static readonly DiagnosticDescriptor AddGetNoResultError = new DiagnosticDescriptor(AddGetNoResultErrorId,
@@ -33,16 +32,7 @@ namespace XFEExtension.NetCore.Analyzer.Diagnostics
"设置了自定义的Set方法但是没有对实际字段进行操作.",
"https://www.xfegzs.com/codespace/diagnostics/XFW0001.html");
public static readonly DiagnosticDescriptor PropertyOrFieldNotStatic = new DiagnosticDescriptor(PropertyOrFieldNotStaticId,
"配置属性或字段不是静态的",
"配置类的{0}不是静态的:'{1}'",
"XFEExtension.NetCore.Analyzer.Diagnostics",
DiagnosticSeverity.Error,
true,
"配置类的属性或字段不是静态的.",
"https://www.xfegzs.com/codespace/diagnostics/XFE0003.html");
public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics => ImmutableArray.Create(AddGetNoResultError, AddSetNoSetResultWarning, PropertyOrFieldNotStatic);
public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics => ImmutableArray.Create(AddGetNoResultError, AddSetNoSetResultWarning);
public override void Initialize(AnalysisContext context)
{
@@ -4,6 +4,7 @@ using Microsoft.CodeAnalysis.Diagnostics;
using System;
using System.Collections.Immutable;
using System.Linq;
using System.Text.RegularExpressions;
namespace XFEExtension.NetCore.Analyzer.Diagnostics
{
@@ -20,7 +21,7 @@ namespace XFEExtension.NetCore.Analyzer.Diagnostics
"TODO��������",
"��������{0}",
"XFEExtension.NetCore.Analyzer.Diagnostics",
(DiagnosticSeverity)Enum.Parse(typeof(DiagnosticSeverity),GeneratorOptions.TodoListWarningLevel.ToString()),
GetSeverityFromInt(GeneratorOptions.TodoListWarningLevel),
true,
"TODO�Ĵ�������.",
"https://www.xfegzs.com/codespace/diagnostics/TODO.html");
@@ -37,22 +38,46 @@ namespace XFEExtension.NetCore.Analyzer.Diagnostics
private void AnalyzeSyntaxTree(SyntaxTreeAnalysisContext context)
{
if (!GeneratorOptions.EnableTodoList)
if (!GeneratorOptions.TodoList)
return;
var root = context.Tree.GetRoot(context.CancellationToken);
var todoComments = root.DescendantTrivia().Where(trivia => trivia.IsKind(SyntaxKind.SingleLineCommentTrivia) && trivia.ToString().Contains("TODO:"));
foreach (var todoComment in todoComments)
{
var descriptor = new DiagnosticDescriptor(TodoCommentId,
"TODO��������",
"��������{0}",
"XFEExtension.NetCore.Analyzer.Diagnostics",
(DiagnosticSeverity)Enum.Parse(typeof(DiagnosticSeverity),GeneratorOptions.TodoListWarningLevel.ToString()),
true,
"TODO�Ĵ�������.",
"https://www.xfegzs.com/codespace/diagnostics/TODO.html");
var diagnostic = Diagnostic.Create(descriptor, todoComment.GetLocation(), todoComment.ToString().Replace("//", "").Replace("TODO:", ""));
context.ReportDiagnostic(diagnostic);
var match = Regex.Match(todoComment.ToString(), @"//TODO:\s*(\d)?\s*(.*)");
if (match.Success)
{
var level = match.Groups[1].Value != "" ? int.Parse(match.Groups[1].Value) : GeneratorOptions.TodoListWarningLevel;
var task = match.Groups[2].Value;
var descriptor = new DiagnosticDescriptor(TodoCommentId,
"TODO��������",
"��������{0}",
"XFEExtension.NetCore.Analyzer.Diagnostics",
GetSeverityFromInt(level),
true,
"TODO�Ĵ�������.",
"https://www.xfegzs.com/codespace/diagnostics/TODO.html");
var diagnostic = Diagnostic.Create(descriptor, todoComment.GetLocation(), task);
context.ReportDiagnostic(diagnostic);
}
}
}
private static DiagnosticSeverity GetSeverityFromInt(int level)
{
switch (level)
{
case 0:
return DiagnosticSeverity.Hidden;
case 1:
return DiagnosticSeverity.Info;
case 2:
return DiagnosticSeverity.Warning;
case 3:
return DiagnosticSeverity.Error;
default:
return DiagnosticSeverity.Warning;
}
}
}
@@ -7,8 +7,8 @@ namespace XFEExtension.NetCore.Analyzer
public static bool AutoProfile { get; set; } = true;
public static bool AutoPath { get; set; } = true;
public static bool AutoImplement { get; set; } = true;
public static bool EnableTodoList { get; set; } = true;
public static string TodoListWarningLevel { get; set; } = "Warning";
public static bool TodoList { get; set; } = true;
public static int TodoListWarningLevel { get; set; } = 2;
public static void GetOptions(GeneratorExecutionContext context)
{
if (context.AnalyzerConfigOptions.GlobalOptions.TryGetValue("build_property.AutoProfile", out var autoProfile))
@@ -17,10 +17,11 @@ namespace XFEExtension.NetCore.Analyzer
AutoPath = autoPath.ToLower() == "true";
if (context.AnalyzerConfigOptions.GlobalOptions.TryGetValue("build_property.AutoImplement", out var autoImplement))
AutoImplement = autoImplement.ToLower() == "true";
if (context.AnalyzerConfigOptions.GlobalOptions.TryGetValue("build_property.EnableTodoList", out var enableTodoList))
EnableTodoList = enableTodoList.ToLower() == "true";
if (context.AnalyzerConfigOptions.GlobalOptions.TryGetValue("build_property.TodoList", out var todoList))
TodoList = todoList.ToLower() == "true";
if (context.AnalyzerConfigOptions.GlobalOptions.TryGetValue("build_property.TodoListWarningLevel", out var todoListWarningLevel))
TodoListWarningLevel = todoListWarningLevel;
if (int.TryParse(todoListWarningLevel, out var warningLevel))
TodoListWarningLevel = warningLevel;
}
}
}
@@ -19,11 +19,22 @@
<PackageTags>XFE;拓展;GPT;Server;服务器;测试;XFEExtension</PackageTags>
<PackageReleaseNotes>## 调整
更新了GPT的模型,现在新增GPT-4o模型
无
## 新增
无
现在TODO任务可以单独提醒,并可以让用户自己设置警告等级
在README.md文件中,增加了对XFEExtension库和XUnit测试框架的描述,以及如何在csproj文件中设置配置和使用TODO待办任务提醒的示例代码。
在AnalyzerReleases.Shipped.md和AnalyzerReleases.Unshipped.md文件中,添加了新的规则,用于处理TODO待办任务提醒的诊断。
在ProfileExtensionDiagnostics.cs文件中,移除了PropertyOrFieldNotStaticId相关的代码,并在SupportedDiagnostics中移除了对应的引用。
在TodoCommentAnalyzerDiagnostics.cs文件中,添加了对正则表达式的引用,修改了对TODO待办任务提醒的处理方式,现在可以根据TODO后的数字来设置警告等级,并对应修改了警告等级的获取方式。
在GeneratorOptions.cs文件中,修改了EnableTodoList和TodoListWarningLevel的名称和类型,并对应修改了在GetOptions方法中的处理方式。在XFEExtension.NetCore.csproj文件中,更新了包的版本号,并在发布说明中添加了对新功能的描述。
## 严重
@@ -32,7 +43,7 @@
<PackageRequireLicenseAcceptance>True</PackageRequireLicenseAcceptance>
<PackageLicenseFile>LICENSE</PackageLicenseFile>
<AssemblyOriginatorKeyFile>..\XFEstudio.pfx</AssemblyOriginatorKeyFile>
<Version>2.10.3</Version>
<Version>2.10.4</Version>
<Authors>XFEstudio</Authors>
</PropertyGroup>