From 9bcd1eabcecaa182f638bc526c1d28ad6ba6a971 Mon Sep 17 00:00:00 2001 From: Oliver Booth Date: Sun, 7 Mar 2021 18:09:27 +0000 Subject: [PATCH] (#7) Move CharExtensions to child namespace - Deprecate Random methods in favour of RandomExtensions methods --- X10D/src/CharExtensions.cs | 90 ----------------------- X10D/src/CharExtensions/CharExtensions.cs | 21 ++++++ 2 files changed, 21 insertions(+), 90 deletions(-) delete mode 100644 X10D/src/CharExtensions.cs create mode 100644 X10D/src/CharExtensions/CharExtensions.cs diff --git a/X10D/src/CharExtensions.cs b/X10D/src/CharExtensions.cs deleted file mode 100644 index 343981c..0000000 --- a/X10D/src/CharExtensions.cs +++ /dev/null @@ -1,90 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; - -namespace X10D -{ - /// - /// Extension methods for . - /// - public static class CharExtensions - { - /// - /// Generates a new random string by filling it with characters found in . - /// - /// The character set. - /// The length of the string to generate. - /// Returns a containing characters. - public static string Random(this char[] chars, int length) - { - return chars.Random(length, RandomExtensions.Random); - } - - /// - /// Generates a new random string by filling it with characters found in . - /// - /// The character set. - /// The length of the string to generate. - /// The instance. - /// Returns a containing characters. - /// is . - public static string Random(this char[] chars, int length, Random random) - { - if (chars is null) - { - throw new ArgumentNullException(nameof(chars)); - } - - if (random is null) - { - throw new ArgumentNullException(nameof(random)); - } - - var builder = new StringBuilder(length); - for (var i = 0; i < length; i++) - { - builder.Append(chars[random.Next(0, chars.Length)]); - } - - return builder.ToString(); - } - - /// - /// Generates a new random string by filling it with characters found in . - /// - /// The character set. - /// The length of the string to generate. - /// Returns a containing characters. - public static string Random(this IEnumerable chars, int length) - { - return chars.Random(length, RandomExtensions.Random); - } - - /// - /// Generates a new random string by filling it with characters found in . - /// - /// The character set. - /// The length of the string to generate. - /// The instance. - /// Returns a containing characters. - public static string Random(this IEnumerable chars, int length, Random random) - { - return chars.ToArray().Random(length, random); - } - - /// - /// Repeats a character a specified number of times. - /// - /// The character to repeat. - /// The repeat count. - /// - /// Returns a whose value is repeated - /// times. - /// - public static string Repeat(this char c, int count) - { - return new string(c, count); - } - } -} diff --git a/X10D/src/CharExtensions/CharExtensions.cs b/X10D/src/CharExtensions/CharExtensions.cs new file mode 100644 index 0000000..263bd3a --- /dev/null +++ b/X10D/src/CharExtensions/CharExtensions.cs @@ -0,0 +1,21 @@ +namespace X10D.CharExtensions +{ + /// + /// Extension methods for . + /// + public static class CharExtensions + { + /// + /// Returns a string composed of the current character repeated a specified number of times. + /// + /// The character to repeat. + /// The number of times to repeat. + /// + /// A composed of repeated times. + /// + public static string Repeat(this char value, int count) + { + return new(value, count); + } + } +}