diff --git a/StringBuilderExtensions/StringBuilderExtensions.cs b/StringBuilderExtensions/StringBuilderExtensions.cs index 9b5f93d..98bc583 100644 --- a/StringBuilderExtensions/StringBuilderExtensions.cs +++ b/StringBuilderExtensions/StringBuilderExtensions.cs @@ -24,13 +24,33 @@ using System; using System.Collections.Generic; -using System.Diagnostics.Contracts; using System.Globalization; using System.Linq; +using System.Resources; using System.Text; namespace System.Text { + static class Contract + { + public static void Ensures(bool b) + { + return; + //if (!b) + // throw new Exception(); + } + + public static T OldValue(T x) + { + return x; + } + + public static T Result() + { + return default(T); + } + } + public static partial class StringBuilderExtensions { /// @@ -44,9 +64,11 @@ public static partial class StringBuilderExtensions /// is null. public static StringBuilder Remove(this StringBuilder sb, params char[] removeChars) { - Contract.Requires(removeChars != null); - Contract.Ensures(sb.Length <= Contract.OldValue(sb.Length)); - + if (sb == null) + throw new ArgumentNullException(nameof(sb)); + if (removeChars == null) + throw new ArgumentNullException(nameof(removeChars)); + var sbLength = sb.Length; for (int i = 0; i < sb.Length; ) { if (removeChars.Any(ch => ch == sb[i])) @@ -54,6 +76,8 @@ public static StringBuilder Remove(this StringBuilder sb, params char[] removeCh else i++; } + if (sb.Length > sbLength) + throw new Exception(); return sb; } @@ -69,11 +93,17 @@ public static StringBuilder Remove(this StringBuilder sb, params char[] removeCh /// public static StringBuilder Remove(this StringBuilder sb, int startIndex) { - Contract.Requires(startIndex >= 0); - Contract.Requires(startIndex < sb.Length); - Contract.Ensures(sb.Length <= Contract.OldValue(sb.Length)); - - return sb.Remove(startIndex, sb.Length - startIndex); + if (sb == null) + throw new ArgumentNullException(nameof(sb)); + if (startIndex < 0) + throw new ArgumentOutOfRangeException(nameof(startIndex)); + if (startIndex >= sb.Length) + throw new ArgumentOutOfRangeException(nameof(startIndex)); + var sbLength = sb.Length; + sb.Remove(startIndex, sb.Length - startIndex); + if (sb.Length > sbLength) + throw new Exception(); + return sb; } ///// @@ -209,25 +239,12 @@ private static StringBuilder TrimHelper(this StringBuilder sb, char[] trimChars, /// public static StringBuilder TrimStart(this StringBuilder sb, params char[] trimChars) { - Contract.Ensures(Contract.Result() != null); - //if (sb.Length != 0) - //{ - // int length = 0; - // int num2 = sb.Length; - // while ((sb[length] == ' ') && (length < num2)) - // { - // length++; - // } - // if (length > 0) - // { - // sb.Remove(0, length); - // } - //} - //return sb; - if ((trimChars != null) && (trimChars.Length != 0)) - return sb.TrimHelper(trimChars, 0); - else - return sb.TrimHelper(0); + if (sb == null) + throw new ArgumentNullException(nameof(sb)); + var result = trimChars != null && trimChars.Length != 0 ? sb.TrimHelper(trimChars, 0) : sb.TrimHelper(0); + if (result == null) + throw new Exception(); + return result; } /// @@ -244,25 +261,12 @@ public static StringBuilder TrimStart(this StringBuilder sb, params char[] trimC /// public static StringBuilder TrimEnd(this StringBuilder sb, params char[] trimChars) { - Contract.Ensures(Contract.Result() != null); - //if (sb.Length != 0) - //{ - // int length = sb.Length; - // int num2 = length - 1; - // while ((sb[num2] == ' ') && (num2 > -1)) - // { - // num2--; - // } - // if (num2 < (length - 1)) - // { - // sb.Remove(num2 + 1, (length - num2) - 1); - // } - //} - //return sb; - if ((trimChars != null) && (trimChars.Length != 0)) - return sb.TrimHelper(trimChars, 1); - else - return sb.TrimHelper(1); + if (sb == null) + throw new ArgumentNullException(nameof(sb)); + var result = trimChars != null && trimChars.Length != 0 ? sb.TrimHelper(trimChars, 1) : sb.TrimHelper(1); + if (result == null) + throw new Exception(); + return result; } /// @@ -276,32 +280,12 @@ public static StringBuilder TrimEnd(this StringBuilder sb, params char[] trimCha /// public static StringBuilder Trim(this StringBuilder sb) { - Contract.Ensures(Contract.Result() != null); - //if (sb.Length != 0) - //{ - // int length = 0; - // int num2 = sb.Length; - // while ((sb[length] == ' ') && (length < num2)) - // { - // length++; - // } - // if (length > 0) - // { - // sb.Remove(0, length); - // num2 = sb.Length; - // } - // length = num2 - 1; - // while ((sb[length] == ' ') && (length > -1)) - // { - // length--; - // } - // if (length < (num2 - 1)) - // { - // sb.Remove(length + 1, (num2 - length) - 1); - // } - //} - //return sb; - return sb.TrimHelper(2); + if (sb == null) + throw new ArgumentNullException(nameof(sb)); + var result = sb.TrimHelper(2); + if (result == null) + throw new Exception(); + return result; } /// @@ -318,12 +302,12 @@ public static StringBuilder Trim(this StringBuilder sb) /// public static StringBuilder Trim(this StringBuilder sb, params char[] trimChars) { - Contract.Ensures(Contract.Result() != null); - - if ((trimChars != null) && (trimChars.Length != 0)) - return sb.TrimHelper(trimChars, 2); - else - return sb.TrimHelper(2); + if (sb == null) + throw new ArgumentNullException(nameof(sb)); + var result = trimChars != null && trimChars.Length != 0 ? sb.TrimHelper(trimChars, 2) : sb.TrimHelper(2); + if (result == null) + throw new Exception(); + return result; } /// @@ -338,9 +322,12 @@ public static StringBuilder Trim(this StringBuilder sb, params char[] trimChars) /// public static int IndexOf(this StringBuilder sb, char value) { - Contract.Ensures(Contract.Result() >= -1); - Contract.Ensures(Contract.Result() < sb.Length); - return IndexOf(sb, value, 0, sb.Length); + if (sb == null) + throw new ArgumentNullException(nameof(sb)); + var result = IndexOf(sb, value, 0, sb.Length); + if (result < -1 || result >= sb.Length) + throw new Exception(); + return result; } /// @@ -360,12 +347,19 @@ public static int IndexOf(this StringBuilder sb, char value) /// public static int IndexOf(this StringBuilder sb, char value, int startIndex) { - Contract.Requires(sb.Length == 0 || startIndex >= 0); - Contract.Requires(sb.Length == 0 || startIndex < sb.Length); - Contract.Ensures(Contract.Result() == -1 || Contract.Result() >= startIndex); - Contract.Ensures(Contract.Result() < sb.Length); - - return sb.IndexOf(value, startIndex, sb.Length - startIndex); + if (sb == null) + throw new ArgumentNullException(nameof(sb)); + if (sb.Length != 0 && startIndex < 0) + throw new ArgumentOutOfRangeException(); + if (sb.Length != 0 && startIndex >= sb.Length) + throw new ArgumentOutOfRangeException(); + + var result = sb.IndexOf(value, startIndex, sb.Length - startIndex); + if (result != -1 && result < startIndex) + throw new Exception(); + if (result >= sb.Length) + throw new Exception(); + return result; } /// @@ -390,9 +384,14 @@ public static int IndexOf(this StringBuilder sb, char value, int startIndex) /// public static int IndexOf(this StringBuilder sb, char value, int startIndex, int count) { - Contract.Requires(sb.Length == 0 || startIndex >= 0); - Contract.Requires(sb.Length == 0 || count >= 0); - Contract.Requires(sb.Length == 0 || startIndex + count <= sb.Length); + if (sb == null) + throw new ArgumentNullException(nameof(sb)); + if (sb.Length != 0 && startIndex < 0) + throw new ArgumentOutOfRangeException(); + if (sb.Length != 0 && count < 0) + throw new ArgumentOutOfRangeException(); + if (sb.Length != 0 && startIndex + count > sb.Length) + throw new ArgumentOutOfRangeException(); Contract.Ensures(Contract.Result() >= -1); Contract.Ensures(Contract.Result() < sb.Length); Contract.Ensures(Contract.Result() == -1 || @@ -426,7 +425,10 @@ public static int IndexOf(this StringBuilder sb, char value, int startIndex, int /// is null. public static int IndexOf(this StringBuilder sb, string value, bool ignoreCase = false) { - Contract.Requires(value != null); + if (sb == null) + throw new ArgumentNullException(nameof(sb)); + if (value == null) + throw new ArgumentNullException(nameof(value)); Contract.Ensures(Contract.Result() >= -1); Contract.Ensures(sb.Length == 0 || Contract.Result() <= Math.Max(sb.Length - value.Length, -1)); Contract.Ensures(value != string.Empty || Contract.Result() == 0); @@ -455,9 +457,14 @@ public static int IndexOf(this StringBuilder sb, string value, bool ignoreCase = /// public static int IndexOf(this StringBuilder sb, string value, int startIndex, bool ignoreCase = false) { - Contract.Requires(value != null); - Contract.Requires(startIndex >= 0); - Contract.Requires((sb.Length == 0 && startIndex == 0) || startIndex < sb.Length); + if (sb == null) + throw new ArgumentNullException(nameof(sb)); + if (value == null) + throw new ArgumentNullException(nameof(value)); + if (startIndex < 0) + throw new ArgumentOutOfRangeException(nameof(startIndex)); + if ((sb.Length != 0 || startIndex != 0) && startIndex >= sb.Length) + throw new ArgumentOutOfRangeException(); Contract.Ensures(Contract.Result() == -1 || Contract.Result() >= startIndex); Contract.Ensures(value == string.Empty || Contract.Result() < sb.Length); Contract.Ensures(value != string.Empty || Contract.Result() == startIndex); @@ -487,10 +494,16 @@ public static int IndexOf(this StringBuilder sb, string value, int startIndex, b /// public static int IndexOf(this StringBuilder sb, string value, int startIndex, int count, bool ignoreCase = false) { - Contract.Requires(value != null); - Contract.Requires(startIndex >= 0); - Contract.Requires(count >= 0); - Contract.Requires(startIndex + count <= sb.Length); + if (sb == null) + throw new ArgumentNullException(nameof(sb)); + if (value == null) + throw new ArgumentNullException(nameof(value)); + if (startIndex < 0) + throw new ArgumentOutOfRangeException(nameof(startIndex)); + if (count < 0) + throw new ArgumentOutOfRangeException(nameof(count)); + if (startIndex + count > sb.Length) + throw new ArgumentOutOfRangeException(); Contract.Ensures(value == string.Empty || Contract.Result() < Math.Max(startIndex + 1 + count - value.Length, 0)); Contract.Ensures(Contract.Result() == -1 || Contract.Result() >= startIndex); Contract.Ensures(value != string.Empty || Contract.Result() == startIndex); @@ -560,7 +573,10 @@ private static int IndexOfInternal(StringBuilder sb, string value, int startInde /// anyOf is null. public static int IndexOfAny(this StringBuilder sb, char[] anyOf) { - Contract.Requires(anyOf != null); + if (sb == null) + throw new ArgumentNullException(nameof(sb)); + if (anyOf == null) + throw new ArgumentNullException(nameof(anyOf)); Contract.Ensures(Contract.Result() >= -1); Contract.Ensures(Contract.Result() < sb.Length); @@ -585,9 +601,14 @@ public static int IndexOfAny(this StringBuilder sb, char[] anyOf) /// public static int IndexOfAny(this StringBuilder sb, char[] anyOf, int startIndex) { - Contract.Requires(anyOf != null); - Contract.Requires(sb.Length == 0 || startIndex >= 0); - Contract.Requires(sb.Length == 0 || startIndex < sb.Length); + if (sb == null) + throw new ArgumentNullException(nameof(sb)); + if (anyOf == null) + throw new ArgumentNullException(nameof(anyOf)); + if (sb.Length != 0 && startIndex < 0) + throw new ArgumentOutOfRangeException(); + if (sb.Length != 0 && startIndex >= sb.Length) + throw new ArgumentOutOfRangeException(); Contract.Ensures(Contract.Result() < sb.Length); Contract.Ensures(Contract.Result() == -1 || (Contract.Result() >= startIndex && Contract.Result() < sb.Length)); @@ -614,11 +635,18 @@ public static int IndexOfAny(this StringBuilder sb, char[] anyOf, int startIndex /// public static int IndexOfAny(this StringBuilder sb, char[] anyOf, int startIndex, int count) { - Contract.Requires(anyOf != null); - Contract.Requires(sb.Length == 0 || startIndex >= 0); - Contract.Requires(sb.Length == 0 || startIndex < sb.Length); - Contract.Requires(sb.Length == 0 || count >= 0); - Contract.Requires(sb.Length == 0 || startIndex + count <= sb.Length); + if (sb == null) + throw new ArgumentNullException(nameof(sb)); + if (anyOf == null) + throw new ArgumentNullException(nameof(anyOf)); + if (sb.Length != 0 && startIndex < 0) + throw new ArgumentOutOfRangeException(); + if (sb.Length != 0 && startIndex >= sb.Length) + throw new ArgumentOutOfRangeException(); + if (sb.Length != 0 && count < 0) + throw new ArgumentOutOfRangeException(); + if (sb.Length != 0 && startIndex + count > sb.Length) + throw new ArgumentOutOfRangeException(); Contract.Ensures(Contract.Result() < sb.Length); Contract.Ensures(Contract.Result() == -1 || (Contract.Result() >= startIndex && Contract.Result() < startIndex + count)); @@ -650,6 +678,8 @@ public static int IndexOfAny(this StringBuilder sb, char[] anyOf, int startIndex /// public static int LastIndexOf(this StringBuilder sb, char value) { + if (sb == null) + throw new ArgumentNullException(nameof(sb)); Contract.Ensures(Contract.Result() >= -1); Contract.Ensures(Contract.Result() < sb.Length); return LastIndexOf(sb, value, sb.Length - 1, sb.Length); @@ -677,8 +707,12 @@ public static int LastIndexOf(this StringBuilder sb, char value) /// public static int LastIndexOf(this StringBuilder sb, char value, int startIndex) { - Contract.Requires(sb.Length == 0 || startIndex >= 0); - Contract.Requires(sb.Length == 0 || startIndex < sb.Length); + if (sb == null) + throw new ArgumentNullException(nameof(sb)); + if (sb.Length != 0 && startIndex < 0) + throw new ArgumentOutOfRangeException(); + if (sb.Length != 0 && startIndex >= sb.Length) + throw new ArgumentOutOfRangeException(); Contract.Ensures(Contract.Result() == -1 || Contract.Result() <= startIndex); Contract.Ensures(Contract.Result() < sb.Length); return sb.LastIndexOf(value, startIndex, startIndex + 1); @@ -705,10 +739,16 @@ public static int LastIndexOf(this StringBuilder sb, char value, int startIndex) /// public static int LastIndexOf(this StringBuilder sb, char value, int startIndex, int count) { - Contract.Requires(sb.Length == 0 || startIndex >= 0); - Contract.Requires(sb.Length == 0 || startIndex < sb.Length); - Contract.Requires(sb.Length == 0 || count >= 0); - Contract.Requires(sb.Length == 0 || startIndex - count + 1 >= 0); + if (sb == null) + throw new ArgumentNullException(nameof(sb)); + if (sb.Length != 0 && startIndex < 0) + throw new ArgumentOutOfRangeException(); + if (sb.Length != 0 && startIndex >= sb.Length) + throw new ArgumentOutOfRangeException(); + if (sb.Length != 0 && count < 0) + throw new ArgumentOutOfRangeException(); + if (sb.Length != 0 && startIndex - count + 1 < 0) + throw new ArgumentOutOfRangeException(); Contract.Ensures(Contract.Result() >= -1); Contract.Ensures(Contract.Result() <= startIndex); Contract.Ensures(Contract.Result() == -1 || Contract.Result() >= startIndex - count + 1); @@ -742,7 +782,10 @@ public static int LastIndexOf(this StringBuilder sb, char value, int startIndex, /// value is null. public static int LastIndexOf(this StringBuilder sb, string value, bool ignoreCase = false) { - Contract.Requires(value != null); + if (sb == null) + throw new ArgumentNullException(nameof(sb)); + if (value == null) + throw new ArgumentNullException(nameof(value)); Contract.Ensures(Contract.Result() >= -1); Contract.Ensures(Contract.Result() <= Math.Max(sb.Length - value.Length, -1)); Contract.Ensures(value != string.Empty || (Contract.Result() == 0 && sb.Length == 0) || (Contract.Result() == sb.Length - 1)); @@ -773,9 +816,14 @@ public static int LastIndexOf(this StringBuilder sb, string value, bool ignoreCa /// public static int LastIndexOf(this StringBuilder sb, string value, int startIndex, bool ignoreCase = false) { - Contract.Requires(value != null); - Contract.Requires(startIndex >= 0); - Contract.Requires((sb.Length == 0 && startIndex == 0) || startIndex < sb.Length); + if (sb == null) + throw new ArgumentNullException(nameof(sb)); + if (value == null) + throw new ArgumentNullException(nameof(value)); + if (startIndex < 0) + throw new ArgumentOutOfRangeException(nameof(startIndex)); + if ((sb.Length != 0 || startIndex != 0) && startIndex >= sb.Length) + throw new ArgumentOutOfRangeException(); Contract.Ensures(Contract.Result() >= -1); Contract.Ensures(value == string.Empty || Contract.Result() <= Math.Max(startIndex + 1 - value.Length, -1)); Contract.Ensures(value != string.Empty || Contract.Result() == startIndex); @@ -802,11 +850,18 @@ public static int LastIndexOf(this StringBuilder sb, string value, int startInde /// public static int LastIndexOf(this StringBuilder sb, string value, int startIndex, int count, bool ignoreCase = false) { - Contract.Requires(value != null); - Contract.Requires(startIndex >= 0); - Contract.Requires(count >= 0); - Contract.Requires((sb.Length == 0 && startIndex == 0) || startIndex < sb.Length); - Contract.Requires((sb.Length == 0 && startIndex == 0) || startIndex - count + 1 >= 0); + if (sb == null) + throw new ArgumentNullException(nameof(sb)); + if (value == null) + throw new ArgumentNullException(nameof(value)); + if (!(startIndex >= 0)) + throw new ArgumentOutOfRangeException(nameof(startIndex)); + if (!(count >= 0)) + throw new ArgumentOutOfRangeException(nameof(count)); + if (!((sb.Length == 0 && startIndex == 0) || startIndex < sb.Length)) + throw new ArgumentOutOfRangeException(); + if (!((sb.Length == 0 && startIndex == 0) || startIndex - count + 1 >= 0)) + throw new ArgumentOutOfRangeException(); Contract.Ensures(Contract.Result() >= -1); Contract.Ensures(value == string.Empty || Contract.Result() <= Math.Max(startIndex + 1 - value.Length, -1)); Contract.Ensures(Contract.Result() == -1 || Contract.Result() >= startIndex + 1 - count); @@ -877,7 +932,10 @@ private static int LastIndexOfInternal(StringBuilder sb, string value, int start /// is null. public static int LastIndexOfAny(this StringBuilder sb, char[] anyOf) { - Contract.Requires(anyOf != null); + if (sb == null) + throw new ArgumentNullException(nameof(sb)); + if (anyOf == null) + throw new ArgumentNullException(nameof(anyOf)); Contract.Ensures(Contract.Result() >= -1); Contract.Ensures(Contract.Result() < sb.Length); return sb.LastIndexOfAny(anyOf, sb.Length - 1, sb.Length); @@ -901,9 +959,14 @@ public static int LastIndexOfAny(this StringBuilder sb, char[] anyOf) /// public static int LastIndexOfAny(this StringBuilder sb, char[] anyOf, int startIndex) { - Contract.Requires(anyOf != null); - Contract.Requires(sb.Length == 0 || startIndex >= 0); - Contract.Requires(sb.Length == 0 || startIndex < sb.Length); + if (sb == null) + throw new ArgumentNullException(nameof(sb)); + if (anyOf == null) + throw new ArgumentNullException(nameof(anyOf)); + if (sb.Length != 0 && startIndex < 0) + throw new ArgumentOutOfRangeException(); + if (sb.Length != 0 && startIndex >= sb.Length) + throw new ArgumentOutOfRangeException(); Contract.Ensures(Contract.Result() < sb.Length); Contract.Ensures(Contract.Result() >= -1 && Contract.Result() <= startIndex); return sb.LastIndexOfAny(anyOf, startIndex, startIndex + 1); @@ -928,11 +991,18 @@ public static int LastIndexOfAny(this StringBuilder sb, char[] anyOf, int startI /// public static int LastIndexOfAny(this StringBuilder sb, char[] anyOf, int startIndex, int count) { - Contract.Requires(anyOf != null); - Contract.Requires(sb.Length == 0 || startIndex >= 0); - Contract.Requires(sb.Length == 0 || startIndex < sb.Length); - Contract.Requires(sb.Length == 0 || count >= 0); - Contract.Requires(sb.Length == 0 || startIndex - count + 1 >= 0); + if (sb == null) + throw new ArgumentNullException(nameof(sb)); + if (anyOf == null) + throw new ArgumentNullException(nameof(anyOf)); + if (!(sb.Length == 0 || startIndex >= 0)) + throw new ArgumentOutOfRangeException(); + if (!(sb.Length == 0 || startIndex < sb.Length)) + throw new ArgumentOutOfRangeException(); + if (!(sb.Length == 0 || count >= 0)) + throw new ArgumentOutOfRangeException(); + if (!(sb.Length == 0 || startIndex - count + 1 >= 0)) + throw new ArgumentOutOfRangeException(); Contract.Ensures(Contract.Result() < sb.Length); Contract.Ensures(Contract.Result() == -1 || (Contract.Result() <= startIndex && Contract.Result() > startIndex - count)); @@ -964,7 +1034,10 @@ public static int LastIndexOfAny(this StringBuilder sb, char[] anyOf, int startI /// is null. public static bool StartsWith(this StringBuilder sb, string value, bool ignoreCase = false) { - Contract.Requires(value != null); + if (sb == null) + throw new ArgumentNullException(nameof(sb)); + if (value == null) + throw new ArgumentNullException(nameof(value)); Contract.Ensures(!Contract.Result() || value.Length <= sb.Length); int length = value.Length; @@ -1006,7 +1079,10 @@ public static bool StartsWith(this StringBuilder sb, string value, bool ignoreCa /// is null. public static bool EndsWith(this StringBuilder sb, string value, bool ignoreCase = false) { - Contract.Requires(value != null); + if (sb == null) + throw new ArgumentNullException(nameof(sb)); + if (value == null) + throw new ArgumentNullException(nameof(value)); Contract.Ensures(!Contract.Result() || value.Length <= sb.Length); int length = value.Length; @@ -1045,6 +1121,8 @@ public static bool EndsWith(this StringBuilder sb, string value, bool ignoreCase /// The converted to lowercase. public static StringBuilder ToLower(this StringBuilder sb) { + if (sb == null) + throw new ArgumentNullException(nameof(sb)); Contract.Ensures(Contract.Result() != null); Contract.Ensures(Contract.Result().Length == sb.Length); @@ -1065,7 +1143,10 @@ public static StringBuilder ToLower(this StringBuilder sb) /// is null. public static StringBuilder ToLower(this StringBuilder sb, CultureInfo culture) { - Contract.Requires(culture != null); + if (sb == null) + throw new ArgumentNullException(nameof(sb)); + if (culture == null) + throw new ArgumentNullException(nameof(culture)); Contract.Ensures(Contract.Result() != null); Contract.Ensures(Contract.Result().Length == sb.Length); @@ -1084,6 +1165,8 @@ public static StringBuilder ToLower(this StringBuilder sb, CultureInfo culture) /// The converted to lowercase using invariant culture. public static StringBuilder ToLowerInvariant(this StringBuilder sb) { + if (sb == null) + throw new ArgumentNullException(nameof(sb)); Contract.Ensures(Contract.Result() != null); Contract.Ensures(Contract.Result().Length == sb.Length); @@ -1097,6 +1180,8 @@ public static StringBuilder ToLowerInvariant(this StringBuilder sb) /// The converted to uppercase. public static StringBuilder ToUpper(this StringBuilder sb) { + if (sb == null) + throw new ArgumentNullException(nameof(sb)); Contract.Ensures(Contract.Result() != null); Contract.Ensures(Contract.Result().Length == sb.Length); @@ -1117,7 +1202,10 @@ public static StringBuilder ToUpper(this StringBuilder sb) /// is null. public static StringBuilder ToUpper(this StringBuilder sb, CultureInfo culture) { - Contract.Requires(culture != null); + if (sb == null) + throw new ArgumentNullException(nameof(sb)); + if (culture == null) + throw new ArgumentNullException(nameof(culture)); Contract.Ensures(Contract.Result() != null); Contract.Ensures(Contract.Result().Length == sb.Length); @@ -1136,6 +1224,8 @@ public static StringBuilder ToUpper(this StringBuilder sb, CultureInfo culture) /// The converted to uppercase using invariant culture. public static StringBuilder ToUpperInvariant(this StringBuilder sb) { + if (sb == null) + throw new ArgumentNullException(nameof(sb)); Contract.Ensures(Contract.Result() != null); Contract.Ensures(Contract.Result().Length == sb.Length); diff --git a/StringBuilderExtensions/StringBuilderExtensions.csproj b/StringBuilderExtensions/StringBuilderExtensions.csproj index 8b7042e..b198e97 100644 --- a/StringBuilderExtensions/StringBuilderExtensions.csproj +++ b/StringBuilderExtensions/StringBuilderExtensions.csproj @@ -106,11 +106,4 @@ - - - - all - runtime; build; native; contentfiles; analyzers - - \ No newline at end of file