22// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33
44using System ;
5+ using McMaster . Extensions . CommandLineUtils . Extensions ;
56using McMaster . Extensions . CommandLineUtils . SourceGeneration ;
67
78namespace McMaster . Extensions . CommandLineUtils . Conventions
@@ -32,33 +33,33 @@ public virtual void Apply(ConventionContext context)
3233 var ( template , shortName , longName ) = GetOptionNames ( optMeta ) ;
3334
3435 // Check for same-class conflicts (options in the same provider with conflicting names)
35- if ( ! string . IsNullOrEmpty ( shortName ) && addedShortOptions . TryGetValue ( shortName , out var existingShort ) )
36+ if ( ! shortName . IsNullOrEmpty ( ) && addedShortOptions . TryGetValue ( shortName , out var existingShort ) )
3637 {
3738 throw new InvalidOperationException (
3839 Strings . OptionNameIsAmbiguous ( shortName , optMeta . PropertyName , optMeta . DeclaringType , existingShort . PropertyName , existingShort . DeclaringType ) ) ;
3940 }
40- if ( ! string . IsNullOrEmpty ( longName ) && addedLongOptions . TryGetValue ( longName , out var existingLong ) )
41+ if ( ! longName . IsNullOrEmpty ( ) && addedLongOptions . TryGetValue ( longName , out var existingLong ) )
4142 {
4243 throw new InvalidOperationException (
4344 Strings . OptionNameIsAmbiguous ( longName , optMeta . PropertyName , optMeta . DeclaringType , existingLong . PropertyName , existingLong . DeclaringType ) ) ;
4445 }
4546
4647 // Check if option already exists from parent command (inherited options)
47- if ( ! string . IsNullOrEmpty ( shortName ) && context . Application . _shortOptions . ContainsKey ( shortName ) )
48+ if ( ! shortName . IsNullOrEmpty ( ) && context . Application . _shortOptions . ContainsKey ( shortName ) )
4849 {
4950 continue ; // Skip - option already registered by parent
5051 }
51- if ( ! string . IsNullOrEmpty ( longName ) && context . Application . _longOptions . ContainsKey ( longName ) )
52+ if ( ! longName . IsNullOrEmpty ( ) && context . Application . _longOptions . ContainsKey ( longName ) )
5253 {
5354 continue ; // Skip - option already registered by parent
5455 }
5556
5657 // Track this option
57- if ( ! string . IsNullOrEmpty ( shortName ) )
58+ if ( ! shortName . IsNullOrEmpty ( ) )
5859 {
5960 addedShortOptions [ shortName ] = optMeta ;
6061 }
61- if ( ! string . IsNullOrEmpty ( longName ) )
62+ if ( ! longName . IsNullOrEmpty ( ) )
6263 {
6364 addedLongOptions [ longName ] = optMeta ;
6465 }
@@ -74,18 +75,18 @@ private static (string template, string? shortName, string? longName) GetOptionN
7475 string ? shortName = meta . ShortName ;
7576 string ? longName = meta . LongName ;
7677
77- if ( string . IsNullOrEmpty ( template ) )
78+ if ( template . IsNullOrEmpty ( ) )
7879 {
7980 // Build template from ShortName/LongName
80- if ( ! string . IsNullOrEmpty ( shortName ) && ! string . IsNullOrEmpty ( longName ) )
81+ if ( ! shortName . IsNullOrEmpty ( ) && ! longName . IsNullOrEmpty ( ) )
8182 {
8283 template = $ "-{ shortName } |--{ longName } ";
8384 }
84- else if ( ! string . IsNullOrEmpty ( longName ) )
85+ else if ( ! longName . IsNullOrEmpty ( ) )
8586 {
8687 template = $ "--{ longName } ";
8788 }
88- else if ( ! string . IsNullOrEmpty ( shortName ) )
89+ else if ( ! shortName . IsNullOrEmpty ( ) )
8990 {
9091 template = $ "-{ shortName } ";
9192 }
@@ -99,17 +100,17 @@ private static (string template, string? shortName, string? longName) GetOptionN
99100 else
100101 {
101102 // Parse short/long names from template if not already set
102- if ( string . IsNullOrEmpty ( shortName ) || string . IsNullOrEmpty ( longName ) )
103+ if ( shortName . IsNullOrEmpty ( ) || longName . IsNullOrEmpty ( ) )
103104 {
104105 var parts = template . Split ( '|' ) ;
105106 foreach ( var part in parts )
106107 {
107108 var trimmed = part . Trim ( ) ;
108- if ( trimmed . StartsWith ( "--" ) && string . IsNullOrEmpty ( longName ) )
109+ if ( trimmed . StartsWith ( "--" ) && longName . IsNullOrEmpty ( ) )
109110 {
110111 longName = trimmed . Substring ( 2 ) . Split ( ' ' , '<' , ':' , '=' ) [ 0 ] ;
111112 }
112- else if ( trimmed . StartsWith ( "-" ) && string . IsNullOrEmpty ( shortName ) )
113+ else if ( trimmed . StartsWith ( "-" ) && shortName . IsNullOrEmpty ( ) )
113114 {
114115 shortName = trimmed . Substring ( 1 ) . Split ( ' ' , '<' , ':' , '=' ) [ 0 ] ;
115116 }
@@ -175,12 +176,12 @@ private void AddOptionFromMetadata(ConventionContext context, CommandOption opti
175176 }
176177
177178 // Register names for duplicate checking
178- if ( ! string . IsNullOrEmpty ( option . ShortName ) )
179+ if ( ! option . ShortName . IsNullOrEmpty ( ) )
179180 {
180181 context . Application . _shortOptions . TryAdd ( option . ShortName , null ! ) ;
181182 }
182183
183- if ( ! string . IsNullOrEmpty ( option . LongName ) )
184+ if ( ! option . LongName . IsNullOrEmpty ( ) )
184185 {
185186 context . Application . _longOptions . TryAdd ( option . LongName , null ! ) ;
186187 }
0 commit comments