7
7
using System . Collections . Generic ;
8
8
using System . Collections . Immutable ;
9
9
using System . Diagnostics . CodeAnalysis ;
10
+ using System . Globalization ;
10
11
using System . IO ;
11
12
using System . Linq ;
12
13
using System . Threading ;
@@ -29,7 +30,7 @@ public partial class ReactiveCommandGenerator
29
30
{
30
31
private const string RxCmd = "ReactiveUI.ReactiveCommand" ;
31
32
private const string RxCmdAttribute = "ReactiveUI.SourceGenerators.ReactiveCommandAttribute" ;
32
- private const string RxCmdProp = "Command { get; private set; }" ;
33
+ private const string RxCmdProp = " { get; private set; }" ;
33
34
34
35
/// <summary>
35
36
/// A container for all the logic for <see cref="ReactiveCommandGenerator"/>.
@@ -80,6 +81,7 @@ internal static CompilationUnitSyntax GetSyntax(CommandInfo commandInfo)
80
81
{
81
82
var outputType = commandExtensionInfo . GetOutputTypeText ( ) ;
82
83
var inputType = commandExtensionInfo . GetInputTypeText ( ) ;
84
+ var commandName = GetGeneratedCommandName ( commandExtensionInfo . MethodName ) ;
83
85
84
86
writer . WriteLine ( AttributeList ( SingletonSeparatedList (
85
87
Attribute ( IdentifierName ( "global::System.CodeDom.Compiler.GeneratedCode" ) )
@@ -88,7 +90,7 @@ internal static CompilationUnitSyntax GetSyntax(CommandInfo commandInfo)
88
90
AttributeArgument ( LiteralExpression ( SyntaxKind . StringLiteralExpression , Literal ( typeof ( ReactiveCommandGenerator ) . Assembly . GetName ( ) . Version . ToString ( ) ) ) ) ) ) ) ) ;
89
91
writer . WriteLine ( AttributeList ( SingletonSeparatedList ( Attribute ( IdentifierName ( "global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage" ) ) ) ) ) ;
90
92
91
- writer . WriteLine ( $ "{ Token ( SyntaxKind . PublicKeyword ) } { RxCmd } <{ inputType } , { outputType } >? { commandExtensionInfo . MethodName } { RxCmdProp } ") ;
93
+ writer . WriteLine ( $ "{ Token ( SyntaxKind . PublicKeyword ) } { RxCmd } <{ inputType } , { outputType } >? { commandName } { RxCmdProp } ") ;
92
94
}
93
95
94
96
writer . WriteLine ( ) ;
@@ -101,7 +103,7 @@ internal static CompilationUnitSyntax GetSyntax(CommandInfo commandInfo)
101
103
// Add the command initialization
102
104
foreach ( var commandExtensionInfo in commandInfo . CommandExtensionInfos )
103
105
{
104
- var commandName = $ " { commandExtensionInfo . MethodName } Command" ;
106
+ var commandName = GetGeneratedCommandName ( commandExtensionInfo . MethodName ) ;
105
107
var outputType = commandExtensionInfo . GetOutputTypeText ( ) ;
106
108
var inputType = commandExtensionInfo . GetInputTypeText ( ) ;
107
109
if ( commandExtensionInfo . ArgumentType == null )
@@ -274,6 +276,8 @@ internal static void GetCommandInfoFromClass(ImmutableArrayBuilder<HierarchyInfo
274
276
out var fieldAttributes ,
275
277
out var propertyAttributes ) ;
276
278
279
+ token . ThrowIfCancellationRequested ( ) ;
280
+
277
281
commandExtensionInfos . Add ( new (
278
282
methodSymbol . Name ,
279
283
realReturnType ,
@@ -600,5 +604,21 @@ static void GatherForwardedAttributes(
600
604
fieldAttributes = fieldAttributesInfo . ToImmutable ( ) ;
601
605
propertyAttributes = propertyAttributesInfo . ToImmutable ( ) ;
602
606
}
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
+ }
603
623
}
604
624
}
0 commit comments