mirror of
https://github.com/ShrlAlgo/RevitGen.git
synced 2026-03-07 17:28:54 +00:00
整理代码
This commit is contained in:
@@ -10,7 +10,6 @@ namespace RevitGen.Generator
|
||||
[Generator(LanguageNames.CSharp)]
|
||||
public class RevitCommandGenerator : ISourceGenerator
|
||||
{
|
||||
// ★★ 1. 修正常量,使用 RevitCommandAttribute ★★
|
||||
private const string RevitCommandAttributeFullName = "RevitGen.Attributes.RevitCommandAttribute";
|
||||
private const string CommandHandlerAttributeFullName = "RevitGen.Attributes.CommandHandlerAttribute";
|
||||
|
||||
@@ -27,18 +26,15 @@ namespace RevitGen.Generator
|
||||
|
||||
if (!(context.SyntaxReceiver is SyntaxReceiver receiver))
|
||||
{
|
||||
// ... [日志和返回逻辑不变] ...
|
||||
return;
|
||||
}
|
||||
|
||||
log.AppendLine($"// Candidate classes found by SyntaxReceiver: {receiver.CandidateClasses.Count}");
|
||||
if (receiver.CandidateClasses.Count == 0)
|
||||
{
|
||||
// ... [日志和返回逻辑不变] ...
|
||||
return;
|
||||
}
|
||||
|
||||
// ★★ 2. 确保我们查找的是正确的特性符号 ★★
|
||||
var attributeSymbol = context.Compilation.GetTypeByMetadataName(RevitCommandAttributeFullName);
|
||||
if (attributeSymbol == null)
|
||||
{
|
||||
@@ -80,7 +76,6 @@ namespace RevitGen.Generator
|
||||
|
||||
if (commandClasses.Any())
|
||||
{
|
||||
// ... [生成 partial 类和 App 类的逻辑不变] ...
|
||||
foreach (var classSymbol in commandClasses)
|
||||
{
|
||||
var partialClassSource = SourceGenerationHelper.GenerateCommandPartialClass(classSymbol);
|
||||
|
||||
@@ -12,7 +12,6 @@ namespace RevitGen.Generator
|
||||
/// </summary>
|
||||
internal static class SourceGenerationHelper
|
||||
{
|
||||
// 定义我们属性的完整名称,以使用最终确定的、正确的命名方案。
|
||||
private const string RevitCommandAttributeFullName = "RevitGen.Attributes.RevitCommandAttribute";
|
||||
private const string CommandHandlerAttributeFullName = "RevitGen.Attributes.CommandHandlerAttribute";
|
||||
|
||||
|
||||
@@ -17,24 +17,24 @@ namespace RevitGen.Generator
|
||||
public void OnVisitSyntaxNode(SyntaxNode syntaxNode)
|
||||
{
|
||||
// 检查节点是否是一个类声明,并且它带有属性
|
||||
//if (syntaxNode is ClassDeclarationSyntax classDeclarationSyntax &&
|
||||
// classDeclarationSyntax.AttributeLists.Count > 0)
|
||||
//{
|
||||
// // 检查类是否被声明为 partial
|
||||
// foreach (var modifier in classDeclarationSyntax.Modifiers)
|
||||
// {
|
||||
// if (modifier.ValueText == "partial")
|
||||
// {
|
||||
// CandidateClasses.Add(classDeclarationSyntax);
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
if (syntaxNode is ClassDeclarationSyntax classDeclarationSyntax &&
|
||||
classDeclarationSyntax.AttributeLists.Count > 0)
|
||||
{
|
||||
// 检查类是否被声明为 partial
|
||||
foreach (var modifier in classDeclarationSyntax.Modifiers)
|
||||
{
|
||||
if (modifier.ValueText == "partial")
|
||||
{
|
||||
CandidateClasses.Add(classDeclarationSyntax);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
//if (syntaxNode is ClassDeclarationSyntax classDeclarationSyntax &&
|
||||
// classDeclarationSyntax.AttributeLists.Count > 0)
|
||||
//{
|
||||
// CandidateClasses.Add(classDeclarationSyntax);
|
||||
//}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,5 @@
|
||||
using System;
|
||||
using System.Drawing;
|
||||
|
||||
using Autodesk.Revit.Attributes;
|
||||
using Autodesk.Revit.DB;
|
||||
using Autodesk.Revit.DB;
|
||||
using Autodesk.Revit.UI;
|
||||
using Autodesk.Revit.UI.Selection;
|
||||
|
||||
using RevitGen.Attributes;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user