@@ -13,8 +13,6 @@ namespace NClap.Types
1313 /// </summary>
1414 internal abstract class CollectionArgumentTypeBase : ArgumentTypeBase , ICollectionArgumentType
1515 {
16- private const char ElementSeparatorChar = ',' ;
17-
1816 private readonly IArgumentType _elementArgumentType ;
1917
2018 /// <summary>
@@ -73,16 +71,29 @@ public override IEnumerable<string> GetCompletions(ArgumentCompletionContext con
7371 throw new ArgumentNullException ( nameof ( valueToComplete ) ) ;
7472 }
7573
76- var tokens = valueToComplete . Split ( ElementSeparatorChar ) ;
74+ string [ ] tokens ;
75+ if ( context . ParseContext . ElementSeparators . Any ( ) )
76+ {
77+ tokens = valueToComplete . Split (
78+ context . ParseContext . ElementSeparators . ToArray ( ) ,
79+ StringSplitOptions . None ) ;
80+ }
81+ else
82+ {
83+ tokens = new [ ] { valueToComplete } ;
84+ }
85+
7786 Debug . Assert ( tokens . Length >= 1 ) ;
7887
7988 var currentTokenIndex = tokens . Length - 1 ;
8089 var currentToken = tokens [ currentTokenIndex ] ;
8190
8291 tokens [ currentTokenIndex ] = string . Empty ;
8392
93+ var preferredSeparator = GetPreferredElementSeparatorOrDefault ( context . ParseContext ) ?? string . Empty ;
94+
8495 return _elementArgumentType . GetCompletions ( context , currentToken )
85- . Select ( completion => string . Join ( ElementSeparatorChar . ToString ( ) , tokens ) + completion ) ;
96+ . Select ( completion => string . Join ( preferredSeparator , tokens ) + completion ) ;
8697 }
8798
8899 /// <summary>
@@ -109,7 +120,17 @@ public override IEnumerable<string> GetCompletions(ArgumentCompletionContext con
109120 /// <returns>The parsed object.</returns>
110121 protected override object Parse ( ArgumentParseContext context , string stringToParse )
111122 {
112- var elementStrings = stringToParse . Split ( ElementSeparatorChar ) ;
123+ string [ ] elementStrings ;
124+ if ( context . ElementSeparators . Any ( ) )
125+ {
126+ elementStrings = stringToParse . Split (
127+ context . ElementSeparators . ToArray ( ) ,
128+ StringSplitOptions . None ) ;
129+ }
130+ else
131+ {
132+ elementStrings = new [ ] { stringToParse } ;
133+ }
113134
114135 var parsedElements = elementStrings . Select ( elementString =>
115136 {
@@ -136,5 +157,14 @@ protected override object Parse(ArgumentParseContext context, string stringToPar
136157 /// <param name="collection">Collection to enumerate.</param>
137158 /// <returns>The enumerated objects.</returns>
138159 protected abstract IEnumerable < object > GetElements ( object collection ) ;
160+
161+ /// <summary>
162+ /// Given a parser context, returns the preferred element separator. Returns null
163+ /// if no such separator exists.
164+ /// </summary>
165+ /// <param name="context">Parser context.</param>
166+ /// <returns>Preferred element separator, if one exists; null otherwise.</returns>
167+ private static string GetPreferredElementSeparatorOrDefault ( ArgumentParseContext context ) =>
168+ context . ElementSeparators . FirstOrDefault ( ) ;
139169 }
140170}
0 commit comments