@@ -50,88 +50,79 @@ public static AttributeValue FromDictionary<T, TArgument>(
5050 public static AttributeValue FromNullableNumberSet < T > ( IEnumerable < T ? > numbers , string ? _ )
5151 where T : struct , INumber < T >
5252 {
53- List < string ? > ns ;
54- if ( numbers . TryGetNonEnumeratedCount ( out var count ) )
55- {
56- if ( count is 0 )
57- return new AttributeValue { NS = [ ] } ;
53+ if ( numbers . TryGetNonEnumeratedCount ( out var count ) is false )
54+ return new AttributeValue { NS = numbers . Select ( x => x . ToString ( ) ) . ToList ( ) } ;
5855
59- ns = new List < string ? > ( count ) ;
60- }
61- else
62- ns = [ ] ;
56+ if ( count is 0 )
57+ return new AttributeValue { NS = [ ] } ;
6358
64- // ReSharper disable once LoopCanBeConvertedToQuery
65- foreach ( var element in numbers )
66- {
67- ns . Add ( element ? . ToString ( ) ) ;
68- }
59+ var list = new List < string ? > ( count ) ;
60+ list . AddRange ( numbers . Select ( x => x . ToString ( ) ) ) ;
6961
70- return new AttributeValue { NS = ns } ;
62+ return new AttributeValue { NS = list } ;
7163 }
7264
73- public static AttributeValue FromNullableStringSet ( IEnumerable < string ? > numbers , string ? _ )
65+ public static AttributeValue FromNumberSet < T > ( IEnumerable < T > numbers , string ? dataMember )
66+ where T : struct , INumber < T >
7467 {
75- List < string ? > ns ;
76- if ( numbers . TryGetNonEnumeratedCount ( out var count ) )
77- {
78- if ( count is 0 )
79- return new AttributeValue { NS = [ ] } ;
68+ if ( numbers . TryGetNonEnumeratedCount ( out var count ) is false )
69+ return new AttributeValue { NS = numbers . Select ( x => x . ToString ( ) ) . ToList ( ) } ;
8070
81- ns = new List < string ? > ( count ) ;
82- }
83- else
84- ns = [ ] ;
71+ if ( count is 0 )
72+ return new AttributeValue { NS = [ ] } ;
73+
74+ var list = new List < string > ( count ) ;
8575
86- // ReSharper disable once LoopCanBeConvertedToQuery
87- foreach ( var element in numbers )
88- ns . Add ( element ) ;
76+ foreach ( var @string in numbers )
77+ {
78+ list . Add ( @string . ToString ( ) ?? throw ExceptionHelper . NotNull ( $ "{ dataMember } [UNKNOWN]") ) ;
79+ }
8980
90- return new AttributeValue { NS = ns } ;
81+ return new AttributeValue { NS = list } ;
9182 }
9283
93- public static AttributeValue FromStringSet ( IEnumerable < string > numbers , string ? dataMember )
84+ public static AttributeValue FromNullableStringSet ( IEnumerable < string ? > strings , string ? _ )
9485 {
95- List < string > ns ;
96- if ( numbers . TryGetNonEnumeratedCount ( out var count ) )
97- {
98- if ( count is 0 )
99- return new AttributeValue { NS = [ ] } ;
86+ if ( strings . TryGetNonEnumeratedCount ( out var count ) is false )
87+ return new AttributeValue { SS = strings . ToList ( ) } ;
10088
101- ns = new List < string > ( count ) ;
102- }
103- else
104- ns = [ ] ;
89+ if ( count is 0 )
90+ return new AttributeValue { SS = [ ] } ;
10591
106- // ReSharper disable once LoopCanBeConvertedToQuery
107-
108- foreach ( var element in numbers )
109- {
110- ns . Add ( element ?? throw ExceptionHelper . NotNull ( $ "{ dataMember } [{ element } ]") ) ;
111- }
92+ var list = new List < string ? > ( count ) ;
93+ list . AddRange ( strings ) ;
11294
113- return new AttributeValue { NS = ns } ;
95+ return new AttributeValue { SS = list } ;
11496 }
11597
116- public static AttributeValue FromNumberSet < T > ( IEnumerable < T > numbers , string ? dataMember )
117- where T : struct , INumber < T >
98+ public static AttributeValue FromStringSet ( IEnumerable < string > strings , string ? dataMember )
11899 {
119- List < string > ns ;
120- if ( numbers . TryGetNonEnumeratedCount ( out var count ) )
100+ if ( strings . TryGetNonEnumeratedCount ( out var count ) is false )
121101 {
122- if ( count is 0 )
123- return new AttributeValue { NS = [ ] } ;
124-
125- ns = new List < string > ( count ) ;
102+ var list = new List < string > ( ) ;
103+ foreach ( var @string in strings )
104+ {
105+ if ( @string is null )
106+ throw ExceptionHelper . NotNull ( $ "{ dataMember } [UNKNOWN]") ;
107+ list . Add ( @string ) ;
108+ }
109+
110+ return new AttributeValue { SS = list } ;
126111 }
127112 else
128- ns = [ ] ;
113+ {
114+ if ( count is 0 )
115+ return new AttributeValue { SS = [ ] } ;
116+
117+ var list = new List < string > ( count ) ;
129118
130- // ReSharper disable once LoopCanBeConvertedToQuery
131- foreach ( var element in numbers )
132- ns . Add ( element . ToString ( ) ?? throw ExceptionHelper . NotNull ( $ "{ dataMember } [{ element } ]") ) ;
119+ foreach ( var @string in strings )
120+ {
121+ list . Add ( @string ?? throw ExceptionHelper . NotNull ( $ "{ dataMember } [UNKNOWN]") ) ;
122+ }
133123
134- return new AttributeValue { NS = ns } ;
124+ return new AttributeValue { SS = list } ;
125+ }
135126 }
136127
137128 public static ISet < TNumber > ToNumberISet < TNumber > ( List < string > ss , string ? dataMember )
@@ -270,15 +261,20 @@ public static AttributeValue FromEnumerable<T, TArgument>(
270261 string ? dataMember ,
271262 Func < T , TArgument , string ? , AttributeValue > resultSelector )
272263 {
273- var attributeValues = enumerable . TryGetNonEnumeratedCount ( out var count )
274- ? new List < AttributeValue > ( count )
275- : new List < AttributeValue > ( ) ;
264+ if ( enumerable . TryGetNonEnumeratedCount ( out var count ) is false )
265+ return new AttributeValue
266+ {
267+ L = [ ..enumerable . Select ( ( element , i ) => resultSelector ( element , argument , $ "{ dataMember } [{ i } ]") ) ]
268+ } ;
276269
277- foreach ( var ( element , i ) in enumerable . Select ( ( x , y ) => ( x , y ) ) )
278- attributeValues . Add ( resultSelector ( element , argument , $ " { dataMember } [ { i } ]" ) ) ;
270+ if ( count == 0 )
271+ return new AttributeValue { L = [ ] } ;
279272
273+ var list = new List < AttributeValue > ( count ) ;
274+ foreach ( var ( element , i ) in enumerable . Select ( ( x , y ) => ( x , y ) ) )
275+ list . Add ( resultSelector ( element , argument , $ "{ dataMember } [{ i } ]") ) ;
280276
281- return new AttributeValue { L = attributeValues } ;
277+ return new AttributeValue { L = list } ;
282278 }
283279
284280 public static List < TResult > ToList < TResult , TArgument > (
0 commit comments