@@ -32,9 +32,10 @@ public static string Repeat(this char value, int repetitions)
3232 /// <returns>String built by repeating the specified string.</returns>
3333 public static string Repeat ( this string value , int repetitions )
3434 {
35+ #if NETSTANDARD2_0
3536 if ( value == null )
3637 throw new ArgumentNullException ( nameof ( value ) ) ;
37- if ( repetitions < 0 )
38+ if ( repetitions < 0 || repetitions >= int . MaxValue )
3839 throw new ArgumentOutOfRangeException ( nameof ( repetitions ) ) ;
3940
4041 int Length = value . Length ;
@@ -45,6 +46,23 @@ public static string Repeat(this string value, int repetitions)
4546 value . CopyTo ( 0 , Characters , p , Length ) ;
4647
4748 return new string ( Characters ) ;
49+ #else
50+ return value == null
51+ ? throw new ArgumentNullException ( nameof ( value ) )
52+ : repetitions < 0 || repetitions >= int . MaxValue
53+ ? throw new ArgumentOutOfRangeException ( nameof ( repetitions ) )
54+ : string . Create ( value . Length * ( repetitions + 1 ) , ( value , repetitions ) , BuildString ) ;
55+
56+ static void BuildString ( Span < char > destination , ( string Value , int Repetitions ) state )
57+ {
58+ int repetitions = state . Repetitions ;
59+ ReadOnlySpan < char > value = state . Value . AsSpan ( ) ;
60+ int length = value . Length ;
61+
62+ for ( int i = 0 , p = 0 ; i <= repetitions ; i ++ , p += length )
63+ value . CopyTo ( destination [ p ..] ) ;
64+ }
65+ #endif
4866 }
4967
5068 /// <summary>
0 commit comments