优化生成器事务调用,项目结构

This commit is contained in:
ShrlAlgo
2025-09-04 15:53:29 +08:00
parent b021bded67
commit 8251f80f0b
5 changed files with 25 additions and 41 deletions

View File

@@ -1,10 +1,10 @@
using Microsoft.CodeAnalysis;
using System.Collections.Generic;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using Microsoft.CodeAnalysis;
namespace RevitGen.Generator
{
/// <summary>
@@ -34,7 +34,7 @@ namespace RevitGen.Generator
}
var attributeData = classSymbol.GetAttributes().First(ad => ad.AttributeClass?.ToDisplayString() == RevitCommandAttributeFullName);
var transactionMode = GetAttributeProperty(attributeData, "TransactionMode", 1);
var usingTransaction = GetAttributeProperty(attributeData, "UsingTransaction", true);
var source = new StringBuilder();
source.AppendLine("// <auto-generated/>");
@@ -46,7 +46,7 @@ namespace RevitGen.Generator
source.AppendLine(" using System.ComponentModel;");
source.AppendLine();
source.AppendLine($" [Transaction((TransactionMode){transactionMode})]");
source.AppendLine($" [Transaction(TransactionMode.Manual)]");
source.AppendLine($" public partial class {className} : IExternalCommand");
source.AppendLine(" {");
source.AppendLine(" private ExternalCommandData _commandData;");
@@ -66,7 +66,7 @@ namespace RevitGen.Generator
source.AppendLine();
source.AppendLine(" try");
source.AppendLine(" {");
if (transactionMode == 1)
if (usingTransaction)
{
source.AppendLine($" using (var trans = new Transaction(this.Document, \"{className}\"))");
source.AppendLine(" {");
@@ -170,7 +170,8 @@ namespace RevitGen.Generator
source.AppendLine();
var commandsWithData = commandClasses.Select(c => new {
var commandsWithData = commandClasses.Select(c => new
{
Symbol = c,
Attribute = c.GetAttributes().First(ad => ad.AttributeClass?.ToDisplayString() == RevitCommandAttributeFullName)
}).ToList();