Skip to content

Commit d6ee59a

Browse files
authored
Fix for #9 (#10)
1 parent 0564bae commit d6ee59a

File tree

1 file changed

+23
-3
lines changed

1 file changed

+23
-3
lines changed

src/ReactiveUI.SourceGenerators/ReactiveCommand/ReactiveCommandGenerator.Execute.cs

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using System.Collections.Generic;
88
using System.Collections.Immutable;
99
using System.Diagnostics.CodeAnalysis;
10+
using System.Globalization;
1011
using System.IO;
1112
using System.Linq;
1213
using System.Threading;
@@ -29,7 +30,7 @@ public partial class ReactiveCommandGenerator
2930
{
3031
private const string RxCmd = "ReactiveUI.ReactiveCommand";
3132
private const string RxCmdAttribute = "ReactiveUI.SourceGenerators.ReactiveCommandAttribute";
32-
private const string RxCmdProp = "Command { get; private set; }";
33+
private const string RxCmdProp = " { get; private set; }";
3334

3435
/// <summary>
3536
/// A container for all the logic for <see cref="ReactiveCommandGenerator"/>.
@@ -80,6 +81,7 @@ internal static CompilationUnitSyntax GetSyntax(CommandInfo commandInfo)
8081
{
8182
var outputType = commandExtensionInfo.GetOutputTypeText();
8283
var inputType = commandExtensionInfo.GetInputTypeText();
84+
var commandName = GetGeneratedCommandName(commandExtensionInfo.MethodName);
8385

8486
writer.WriteLine(AttributeList(SingletonSeparatedList(
8587
Attribute(IdentifierName("global::System.CodeDom.Compiler.GeneratedCode"))
@@ -88,7 +90,7 @@ internal static CompilationUnitSyntax GetSyntax(CommandInfo commandInfo)
8890
AttributeArgument(LiteralExpression(SyntaxKind.StringLiteralExpression, Literal(typeof(ReactiveCommandGenerator).Assembly.GetName().Version.ToString())))))));
8991
writer.WriteLine(AttributeList(SingletonSeparatedList(Attribute(IdentifierName("global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage")))));
9092

91-
writer.WriteLine($"{Token(SyntaxKind.PublicKeyword)} {RxCmd}<{inputType}, {outputType}>? {commandExtensionInfo.MethodName}{RxCmdProp}");
93+
writer.WriteLine($"{Token(SyntaxKind.PublicKeyword)} {RxCmd}<{inputType}, {outputType}>? {commandName}{RxCmdProp}");
9294
}
9395

9496
writer.WriteLine();
@@ -101,7 +103,7 @@ internal static CompilationUnitSyntax GetSyntax(CommandInfo commandInfo)
101103
// Add the command initialization
102104
foreach (var commandExtensionInfo in commandInfo.CommandExtensionInfos)
103105
{
104-
var commandName = $"{commandExtensionInfo.MethodName}Command";
106+
var commandName = GetGeneratedCommandName(commandExtensionInfo.MethodName);
105107
var outputType = commandExtensionInfo.GetOutputTypeText();
106108
var inputType = commandExtensionInfo.GetInputTypeText();
107109
if (commandExtensionInfo.ArgumentType == null)
@@ -274,6 +276,8 @@ internal static void GetCommandInfoFromClass(ImmutableArrayBuilder<HierarchyInfo
274276
out var fieldAttributes,
275277
out var propertyAttributes);
276278

279+
token.ThrowIfCancellationRequested();
280+
277281
commandExtensionInfos.Add(new(
278282
methodSymbol.Name,
279283
realReturnType,
@@ -600,5 +604,21 @@ static void GatherForwardedAttributes(
600604
fieldAttributes = fieldAttributesInfo.ToImmutable();
601605
propertyAttributes = propertyAttributesInfo.ToImmutable();
602606
}
607+
608+
private static string GetGeneratedCommandName(string methodName)
609+
{
610+
var commandName = methodName;
611+
612+
if (commandName.StartsWith("m_"))
613+
{
614+
commandName = commandName.Substring(2);
615+
}
616+
else if (commandName.StartsWith("_"))
617+
{
618+
commandName = commandName.TrimStart('_');
619+
}
620+
621+
return $"{char.ToUpper(commandName[0], CultureInfo.InvariantCulture)}{commandName.Substring(1)}Command";
622+
}
603623
}
604624
}

0 commit comments

Comments
 (0)