diff --git a/RevitGen.Generator/RevitCommandGenerator.cs b/RevitGen.Generator/RevitCommandGenerator.cs index b0509a9..d30b16b 100644 --- a/RevitGen.Generator/RevitCommandGenerator.cs +++ b/RevitGen.Generator/RevitCommandGenerator.cs @@ -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); diff --git a/RevitGen.Generator/SourceGenerationHelper.cs b/RevitGen.Generator/SourceGenerationHelper.cs index 96e1fb3..cd2975e 100644 --- a/RevitGen.Generator/SourceGenerationHelper.cs +++ b/RevitGen.Generator/SourceGenerationHelper.cs @@ -12,7 +12,6 @@ namespace RevitGen.Generator /// internal static class SourceGenerationHelper { - // 定义我们属性的完整名称,以使用最终确定的、正确的命名方案。 private const string RevitCommandAttributeFullName = "RevitGen.Attributes.RevitCommandAttribute"; private const string CommandHandlerAttributeFullName = "RevitGen.Attributes.CommandHandlerAttribute"; diff --git a/RevitGen.Generator/SyntaxReceiver.cs b/RevitGen.Generator/SyntaxReceiver.cs index d5704e6..e213aa0 100644 --- a/RevitGen.Generator/SyntaxReceiver.cs +++ b/RevitGen.Generator/SyntaxReceiver.cs @@ -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) + classDeclarationSyntax.AttributeLists.Count > 0) { - CandidateClasses.Add(classDeclarationSyntax); + // 检查类是否被声明为 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); + //} } } } \ No newline at end of file diff --git a/RevitGenTest/RevitAddin.cs b/RevitGenTest/RevitAddin.cs index 8f8c5e2..bbea316 100644 --- a/RevitGenTest/RevitAddin.cs +++ b/RevitGenTest/RevitAddin.cs @@ -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;