diff --git a/common.props b/common.props index e62e7cf6..4cb66769 100644 --- a/common.props +++ b/common.props @@ -48,6 +48,10 @@ projects from the command-line or the IDE. --> + + + + diff --git a/src/Cadru.AspNetCore.Mvc.TagHelpers/Cadru.AspNetCore.Mvc.TagHelpers.csproj b/src/Cadru.AspNetCore.Mvc.TagHelpers/Cadru.AspNetCore.Mvc.TagHelpers.csproj index 8e82ebbe..56fa7e69 100644 --- a/src/Cadru.AspNetCore.Mvc.TagHelpers/Cadru.AspNetCore.Mvc.TagHelpers.csproj +++ b/src/Cadru.AspNetCore.Mvc.TagHelpers/Cadru.AspNetCore.Mvc.TagHelpers.csproj @@ -3,6 +3,8 @@ netstandard2.0;netstandard2.1;net5.0 Provides additional ASP.NET Core TagHelpers. $(CommonPackageTags) aspnetcore taghelper rendering + latest + enable diff --git a/src/Cadru.AspNetCore.Mvc.TagHelpers/Cadru.AspNetCore.Mvc.TagHelpers.xml b/src/Cadru.AspNetCore.Mvc.TagHelpers/Cadru.AspNetCore.Mvc.TagHelpers.xml index 673e1961..d615ac00 100644 --- a/src/Cadru.AspNetCore.Mvc.TagHelpers/Cadru.AspNetCore.Mvc.TagHelpers.xml +++ b/src/Cadru.AspNetCore.Mvc.TagHelpers/Cadru.AspNetCore.Mvc.TagHelpers.xml @@ -232,5 +232,217 @@ A new representing the HTML tag. + + + Specifies that is allowed as an input even if the + corresponding type disallows it. + + + + + Initializes a new instance of the class. + + + + + Specifies that is disallowed as an input even if the + corresponding type allows it. + + + + + Initializes a new instance of the class. + + + + + Specifies that a method that will never return under any circumstance. + + + + + Initializes a new instance of the class. + + + + + + Specifies that the method will not return if the associated + parameter is passed the specified value. + + + + + Gets the condition parameter value. + Code after the method is considered unreachable by diagnostics if the argument + to the associated parameter matches this value. + + + + + Initializes a new instance of the + class with the specified parameter value. + + + The condition parameter value. + Code after the method is considered unreachable by diagnostics if the argument + to the associated parameter matches this value. + + + + + Specifies that an output may be even if the + corresponding type disallows it. + + + + + Initializes a new instance of the class. + + + + + Specifies that when a method returns , + the parameter may be even if the corresponding type disallows it. + + + + + Gets the return value condition. + If the method returns this value, the associated parameter may be . + + + + + Initializes the attribute with the specified return value condition. + + + The return value condition. + If the method returns this value, the associated parameter may be . + + + + + Specifies that the method or property will ensure that the listed field and property members have + not- values. + + + + + Gets field or property member names. + + + + + Initializes the attribute with a field or property member. + + + The field or property member that is promised to be not-null. + + + + + Initializes the attribute with the list of field and property members. + + + The list of field and property members that are promised to be not-null. + + + + + Specifies that the method or property will ensure that the listed field and property members have + non- values when returning with the specified return value condition. + + + + + Gets the return value condition. + + + + + Gets field or property member names. + + + + + Initializes the attribute with the specified return value condition and a field or property member. + + + The return value condition. If the method returns this value, + the associated parameter will not be . + + + The field or property member that is promised to be not-. + + + + + Initializes the attribute with the specified return value condition and list + of field and property members. + + + The return value condition. If the method returns this value, + the associated parameter will not be . + + + The list of field and property members that are promised to be not-null. + + + + + Specifies that an output is not even if the + corresponding type allows it. + + + + + Initializes a new instance of the class. + + + + + Specifies that the output will be non- if the + named parameter is non-. + + + + + Gets the associated parameter name. + The output will be non- if the argument to the + parameter specified is non-. + + + + + Initializes the attribute with the associated parameter name. + + + The associated parameter name. + The output will be non- if the argument to the + parameter specified is non-. + + + + + Specifies that when a method returns , + the parameter will not be even if the corresponding type allows it. + + + + + Gets the return value condition. + If the method returns this value, the associated parameter will not be . + + + + + Initializes the attribute with the specified return value condition. + + + The return value condition. + If the method returns this value, the associated parameter will not be . + + diff --git a/src/Cadru.AspNetCore.Mvc/Extensions/StateManagementExtensions.cs b/src/Cadru.AspNetCore.Mvc/Extensions/StateManagementExtensions.cs index f29da85f..f386769f 100644 --- a/src/Cadru.AspNetCore.Mvc/Extensions/StateManagementExtensions.cs +++ b/src/Cadru.AspNetCore.Mvc/Extensions/StateManagementExtensions.cs @@ -37,6 +37,12 @@ namespace Cadru.AspNetCore.Mvc.Extensions /// public static class StateManagementExtensions { + private static string GetTypeName() + { + var type = typeof(T); + return $"{type.Namespace}.{type.Name}"; + } + /// /// Gets the value associated with the specified key. /// @@ -57,7 +63,7 @@ public static class StateManagementExtensions [return: MaybeNull] public static T Get(this ITempDataDictionary storageProvider) { - storageProvider.TryGetValue(typeof(T).FullName, out var value); + storageProvider.TryGetValue(GetTypeName(), out var value); return value; } @@ -99,7 +105,7 @@ public static T Get(this ITempDataDictionary storageProvider, string key) [return: MaybeNull] public static T Get(this ISession storageProvider) { - storageProvider.TryGetValue(typeof(T).FullName, out var value); + storageProvider.TryGetValue(GetTypeName(), out var value); return value; } @@ -141,7 +147,7 @@ public static T Get(this ISession storageProvider, string key) [return: MaybeNull] public static T Get(this ViewDataDictionary storageProvider) { - storageProvider.TryGetValue(typeof(T).FullName, out var value); + storageProvider.TryGetValue(GetTypeName(), out var value); return value; } @@ -184,7 +190,7 @@ public static T Get(this ViewDataDictionary storageProvider, string key) [return: MaybeNull] public static T Peek(this ITempDataDictionary storageProvider) { - storageProvider.TryPeekValue(typeof(T).FullName, out var value); + storageProvider.TryPeekValue(GetTypeName(), out var value); return value; } @@ -228,7 +234,7 @@ public static T Peek(this ITempDataDictionary storageProvider, string key) [return: MaybeNull] public static T Peek(this ISession storageProvider) { - return storageProvider.Get(typeof(T).FullName); + return storageProvider.Get(GetTypeName()); } /// @@ -321,7 +327,7 @@ public static T Peek(this ViewDataDictionary storageProvider, string key) /// public static void Put(this ITempDataDictionary storageProvider, T value) { - storageProvider.Put(typeof(T).FullName, value); + storageProvider.Put(GetTypeName(), value); } /// @@ -355,7 +361,7 @@ public static void Put(this ITempDataDictionary storageProvider, string key, /// public static void Put(this ISession storageProvider, T value) { - storageProvider.Put(typeof(T).FullName, value); + storageProvider.Put(GetTypeName(), value); } /// @@ -389,7 +395,7 @@ public static void Put(this ISession storageProvider, string key, T value) /// public static void Put(this ViewDataDictionary storageProvider, T value) { - storageProvider.Put(typeof(T).FullName, value); + storageProvider.Put(GetTypeName(), value); } /// @@ -423,7 +429,6 @@ public static void Put(this ViewDataDictionary storageProvider, string key, T /// contains an element with the /// specified key; otherwise, . /// - [SuppressMessage("Design", "CA1031:Do not catch general exception types", Justification = "")] public static bool TryGetValue(this ITempDataDictionary storageProvider, string key, [MaybeNull] out T value) { var valid = false; @@ -461,7 +466,6 @@ public static bool TryGetValue(this ITempDataDictionary storageProvider, stri /// contains an element with the /// specified key; otherwise, . /// - [SuppressMessage("Design", "CA1031:Do not catch general exception types", Justification = "")] public static bool TryGetValue(this ISession storageProvider, string key, [MaybeNull] out T value) { var valid = false; @@ -500,7 +504,6 @@ public static bool TryGetValue(this ISession storageProvider, string key, [Ma /// contains an element with the /// specified key; otherwise, . /// - [SuppressMessage("Design", "CA1031:Do not catch general exception types", Justification = "")] public static bool TryGetValue(this ViewDataDictionary storageProvider, string key, [MaybeNull] out T value) { var valid = false; @@ -539,7 +542,6 @@ public static bool TryGetValue(this ViewDataDictionary storageProvider, strin /// contains an element with the /// specified key; otherwise, . /// - [SuppressMessage("Design", "CA1031:Do not catch general exception types", Justification = "")] public static bool TryPeekValue(this ITempDataDictionary storageProvider, string key, [MaybeNull] out T value) { var valid = false; diff --git a/src/Cadru.Build.Tasks/Cadru.Build.Tasks.csproj b/src/Cadru.Build.Tasks/Cadru.Build.Tasks.csproj index 38a071d3..891172f3 100644 --- a/src/Cadru.Build.Tasks/Cadru.Build.Tasks.csproj +++ b/src/Cadru.Build.Tasks/Cadru.Build.Tasks.csproj @@ -3,6 +3,8 @@ netstandard2.0;netstandard2.1;net5.0 Provides additional MSBuild tasks. $(CommonPackageTags) collections logical natural string comparison date comparison comparer + latest + enable diff --git a/src/Cadru.Caching/CacheKey.cs b/src/Cadru.Caching/CacheKey.cs index 248df7f8..dabd3d97 100644 --- a/src/Cadru.Caching/CacheKey.cs +++ b/src/Cadru.Caching/CacheKey.cs @@ -87,14 +87,22 @@ public CacheKey(string prefix, IEnumerable? data) foreach (var element in e) { - tempBuilder.Add(element.ToString()); + var key = element.ToString(); + if (!String.IsNullOrWhiteSpace(key)) + { + tempBuilder.Add(key); + } } keyBuilder.Add(String.Join("-", tempBuilder)); } else { - keyBuilder.Add(d.ToString()); + var key = d.ToString(); + if (!String.IsNullOrWhiteSpace(key)) + { + keyBuilder.Add(key); + } } } } @@ -119,7 +127,7 @@ public CacheKey(string prefix, IEnumerable? data) private int Hash { get; } /// - public override bool Equals(object obj) => (obj is CacheKey key) ? this.Key == key.Key : this == obj; + public override bool Equals(object? obj) => (obj is CacheKey key) ? this.Key == key.Key : this == obj; /// public override int GetHashCode() => this.Hash; diff --git a/src/Cadru.Collections/Cadru.Collections.xml b/src/Cadru.Collections/Cadru.Collections.xml index f69e4490..009a538f 100644 --- a/src/Cadru.Collections/Cadru.Collections.xml +++ b/src/Cadru.Collections/Cadru.Collections.xml @@ -2271,5 +2271,217 @@ This compare operation reverses the comparison. + + + Specifies that is allowed as an input even if the + corresponding type disallows it. + + + + + Initializes a new instance of the class. + + + + + Specifies that is disallowed as an input even if the + corresponding type allows it. + + + + + Initializes a new instance of the class. + + + + + Specifies that a method that will never return under any circumstance. + + + + + Initializes a new instance of the class. + + + + + + Specifies that the method will not return if the associated + parameter is passed the specified value. + + + + + Gets the condition parameter value. + Code after the method is considered unreachable by diagnostics if the argument + to the associated parameter matches this value. + + + + + Initializes a new instance of the + class with the specified parameter value. + + + The condition parameter value. + Code after the method is considered unreachable by diagnostics if the argument + to the associated parameter matches this value. + + + + + Specifies that an output may be even if the + corresponding type disallows it. + + + + + Initializes a new instance of the class. + + + + + Specifies that when a method returns , + the parameter may be even if the corresponding type disallows it. + + + + + Gets the return value condition. + If the method returns this value, the associated parameter may be . + + + + + Initializes the attribute with the specified return value condition. + + + The return value condition. + If the method returns this value, the associated parameter may be . + + + + + Specifies that the method or property will ensure that the listed field and property members have + not- values. + + + + + Gets field or property member names. + + + + + Initializes the attribute with a field or property member. + + + The field or property member that is promised to be not-null. + + + + + Initializes the attribute with the list of field and property members. + + + The list of field and property members that are promised to be not-null. + + + + + Specifies that the method or property will ensure that the listed field and property members have + non- values when returning with the specified return value condition. + + + + + Gets the return value condition. + + + + + Gets field or property member names. + + + + + Initializes the attribute with the specified return value condition and a field or property member. + + + The return value condition. If the method returns this value, + the associated parameter will not be . + + + The field or property member that is promised to be not-. + + + + + Initializes the attribute with the specified return value condition and list + of field and property members. + + + The return value condition. If the method returns this value, + the associated parameter will not be . + + + The list of field and property members that are promised to be not-null. + + + + + Specifies that an output is not even if the + corresponding type allows it. + + + + + Initializes a new instance of the class. + + + + + Specifies that the output will be non- if the + named parameter is non-. + + + + + Gets the associated parameter name. + The output will be non- if the argument to the + parameter specified is non-. + + + + + Initializes the attribute with the associated parameter name. + + + The associated parameter name. + The output will be non- if the argument to the + parameter specified is non-. + + + + + Specifies that when a method returns , + the parameter will not be even if the corresponding type allows it. + + + + + Gets the return value condition. + If the method returns this value, the associated parameter will not be . + + + + + Initializes the attribute with the specified return value condition. + + + The return value condition. + If the method returns this value, the associated parameter will not be . + + diff --git a/src/Cadru.Collections/ComparisonComparer{T}.cs b/src/Cadru.Collections/ComparisonComparer{T}.cs index 442c9ce7..8464e8e7 100644 --- a/src/Cadru.Collections/ComparisonComparer{T}.cs +++ b/src/Cadru.Collections/ComparisonComparer{T}.cs @@ -55,7 +55,6 @@ protected ComparisonComparer(Comparison comparison) /// /// is . /// - [SuppressMessage("Microsoft.Design", "CA1000:DoNotDeclareStaticMembersOnGenericTypes", Justification = "The type must be generic but the Create method shouldn't be.")] public new static Comparer Create(Comparison comparison) { Requires.NotNull(comparison, nameof(comparison)); @@ -64,9 +63,9 @@ public new static Comparer Create(Comparison comparison) } /// - public override int Compare(T x, T y) + public override int Compare(T? x, T? y) { - return this.comparison(x, y); + return this.comparison(x!, y!); } } } \ No newline at end of file diff --git a/src/Cadru.Collections/DateComparer.cs b/src/Cadru.Collections/DateComparer.cs index a8ddc906..389c005e 100644 --- a/src/Cadru.Collections/DateComparer.cs +++ b/src/Cadru.Collections/DateComparer.cs @@ -103,8 +103,6 @@ public DateComparer(CultureInfo culture) /// Encoding /// and Localization. /// - [SuppressMessage("Microsoft.Globalization", "CA1304:SpecifyCultureInfo", MessageId = "Cadru.Collections.DateComparer.#ctor", Justification = "This constructor call implicitly passes a culture.")] - [SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1623:PropertySummaryDocumentationMustMatchAccessors", Justification = "Reviewed.")] public static IComparer Default => new DateComparer(); /// @@ -125,7 +123,6 @@ public DateComparer(CultureInfo culture) /// Encoding /// and Localization. /// - [SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1623:PropertySummaryDocumentationMustMatchAccessors", Justification = "Reviewed.")] public static IComparer DefaultInvariant => new DateComparer(CultureInfo.InvariantCulture); /// @@ -135,7 +132,7 @@ public int Compare(DateTime x, DateTime y) } /// - public int Compare(object x, object y) + public int Compare(object? x, object? y) { int result; @@ -173,7 +170,7 @@ public int Compare(object x, object y) /// /// The strings should be a valid date time format. - public int Compare(string x, string y) + public int Compare(string? x, string? y) { if (!DateTime.TryParse(x, this.cultureInfo, DateTimeStyles.None, out var t1)) { @@ -195,7 +192,7 @@ public bool Equals(DateTime x, DateTime y) } /// - public bool Equals(string x, string y) + public bool Equals(string? x, string? y) { if (x.IsNull() && y.IsNull()) { @@ -236,7 +233,7 @@ public bool Equals(string x, string y) } /// - bool IEqualityComparer.Equals(object x, object y) + bool IEqualityComparer.Equals(object? x, object? y) { return Equals(x, y); } diff --git a/src/Cadru.Collections/Equality(T).cs b/src/Cadru.Collections/Equality(T).cs index 810f0aa5..6a1015c8 100644 --- a/src/Cadru.Collections/Equality(T).cs +++ b/src/Cadru.Collections/Equality(T).cs @@ -43,8 +43,7 @@ public static class Equality /// The type of the key returned by . /// A function to extract a key from an element. /// An instance of an . - [SuppressMessage("Microsoft.Design", "CA1000:DoNotDeclareStaticMembersOnGenericTypes", Justification = "Reviewed.")] - public static IEqualityComparer CreateComparer(Func keySelector) + public static IEqualityComparer CreateComparer(Func keySelector) where TKey: notnull { return CreateComparer(keySelector, null); } @@ -60,18 +59,17 @@ public static IEqualityComparer CreateComparer(Func to compare keys. /// /// An instance of an . - [SuppressMessage("Microsoft.Design", "CA1000:DoNotDeclareStaticMembersOnGenericTypes", Justification = "Reviewed.")] - public static IEqualityComparer CreateComparer(Func keySelector, IEqualityComparer? comparer) + public static IEqualityComparer CreateComparer(Func keySelector, IEqualityComparer? comparer) where TKey : notnull { return new KeyEqualityComparer(keySelector, comparer); } - private class KeyEqualityComparer : IEqualityComparer + private class KeyEqualityComparer : IEqualityComparer where V : notnull { private readonly IEqualityComparer comparer; - private readonly Func keySelector; + private readonly Func keySelector; - public KeyEqualityComparer(Func keySelector, IEqualityComparer? comparer) + public KeyEqualityComparer(Func keySelector, IEqualityComparer? comparer) { Requires.NotNull(keySelector, nameof(keySelector)); @@ -79,7 +77,7 @@ public KeyEqualityComparer(Func keySelector, IEqualityComparer? c this.comparer = comparer ?? EqualityComparer.Default; } - public bool Equals(TSource x, TSource y) + public bool Equals(TSource? x, TSource? y) { return this.comparer.Equals(this.keySelector(x), this.keySelector(y)); } diff --git a/src/Cadru.Collections/GenericKeyedCollection(TKey,TItem).cs b/src/Cadru.Collections/GenericKeyedCollection(TKey,TItem).cs index 3f990bed..307477c4 100644 --- a/src/Cadru.Collections/GenericKeyedCollection(TKey,TItem).cs +++ b/src/Cadru.Collections/GenericKeyedCollection(TKey,TItem).cs @@ -32,7 +32,7 @@ namespace Cadru.Collections /// /// The type of keys in the collection. /// The type of items in the collection. - public class GenericKeyedCollection : KeyedCollection + public class GenericKeyedCollection : KeyedCollection where TKey: notnull { private readonly Func getKeyFunc; diff --git a/src/Cadru.Collections/LogicalStringComparer.cs b/src/Cadru.Collections/LogicalStringComparer.cs index 6e6b358a..5767cf6d 100644 --- a/src/Cadru.Collections/LogicalStringComparer.cs +++ b/src/Cadru.Collections/LogicalStringComparer.cs @@ -59,7 +59,6 @@ namespace Cadru.Collections /// Windows Explorer: (1.txt, [1.txt, _1.txt, =1.txt /// this code: (1.txt, =1.txt, [1.txt, _1.txt /// - [SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1650:ElementDocumentationMustBeSpelledCorrectly", Justification = "Reviewed.")] public sealed class LogicalStringComparer : IComparer, IEqualityComparer, IComparer, IEqualityComparer { private readonly CultureInfo cultureInfo; @@ -126,8 +125,6 @@ public LogicalStringComparer(CultureInfo culture) /// Encoding /// and Localization. /// - [SuppressMessage("Microsoft.Globalization", "CA1304:SpecifyCultureInfo", MessageId = "Cadru.Collections.LogicalStringComparer.#ctor", Justification = "This constructor call implicitly passes a culture.")] - [SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1623:PropertySummaryDocumentationMustMatchAccessors", Justification = "Reviewed.")] public static IComparer Default => new LogicalStringComparer(); /// @@ -149,11 +146,10 @@ public LogicalStringComparer(CultureInfo culture) /// Encoding /// and Localization. /// - [SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1623:PropertySummaryDocumentationMustMatchAccessors", Justification = "Reviewed.")] public static IComparer DefaultInvariant => new LogicalStringComparer(CultureInfo.InvariantCulture); /// - public int Compare(object x, object y) + public int Compare(object? x, object? y) { int result; @@ -190,8 +186,7 @@ public int Compare(object x, object y) } /// - [SuppressMessage("Microsoft.Maintainability", "CA1502:AvoidExcessiveComplexity", Justification = "Reviewed.")] - public int Compare(string x, string y) + public int Compare(string? x, string? y) { if (String.IsNullOrEmpty(x) && String.IsNullOrEmpty(y)) { @@ -207,8 +202,8 @@ public int Compare(string x, string y) } else { - var lengthOfX = x.Length; - var lengthOfY = y.Length; + var lengthOfX = x!.Length; + var lengthOfY = y!.Length; var sp1 = Char.IsLetterOrDigit(x[0]); var sp2 = Char.IsLetterOrDigit(y[0]); @@ -309,13 +304,13 @@ public int Compare(string x, string y) } /// - bool IEqualityComparer.Equals(object x, object y) + bool IEqualityComparer.Equals(object? x, object? y) { return Equals(x, y); } /// - public bool Equals(string x, string y) + public bool Equals(string? x, string? y) { return String.Equals(x, y); } @@ -341,7 +336,6 @@ public int GetHashCode(string obj) return obj.GetHashCode(); } - [SuppressMessage("StyleCop.CSharp.NamingRules", "SA1305:FieldNamesMustNotUseHungarianNotation", Justification = "Reviewed.")] private static int CompareNumbers(string s1, int s1Length, ref int i1, string s2, int s2Length, ref int i2) { int nzStart1 = i1, nzStart2 = i2; @@ -387,7 +381,6 @@ private static int CompareNumbers(string s1, int s1Length, ref int i1, string s2 return 1; } - [SuppressMessage("StyleCop.CSharp.NamingRules", "SA1305:FieldNamesMustNotUseHungarianNotation", Justification = "Reviewed.")] private static void ScanNumber(string s, int length, int start, ref int nzStart, ref int end) { nzStart = start; diff --git a/src/Cadru.Collections/MultiValueDictionary.Enumerator.cs b/src/Cadru.Collections/MultiValueDictionary.Enumerator.cs index 517c57c2..9457c889 100644 --- a/src/Cadru.Collections/MultiValueDictionary.Enumerator.cs +++ b/src/Cadru.Collections/MultiValueDictionary.Enumerator.cs @@ -31,7 +31,7 @@ namespace Cadru.Collections public partial class MultiValueDictionary { private sealed class Enumerator : - IEnumerator>> + IEnumerator>> { private readonly MultiValueDictionary _multiValueDictionary; private readonly int _version; diff --git a/src/Cadru.Collections/MultiValueDictionary.cs b/src/Cadru.Collections/MultiValueDictionary.cs index bae4c4fe..a960c94e 100644 --- a/src/Cadru.Collections/MultiValueDictionary.cs +++ b/src/Cadru.Collections/MultiValueDictionary.cs @@ -23,6 +23,7 @@ using System; using System.Collections; using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; using Cadru.Collections.Resources; @@ -50,7 +51,7 @@ namespace Cadru.Collections /// The type of the key. /// The type of the value. public partial class MultiValueDictionary : - IReadOnlyDictionary> + IReadOnlyDictionary> where TKey : notnull { private readonly Dictionary _dictionary; private int _version; @@ -1212,7 +1213,7 @@ public bool TryGetValue(TKey key, out IReadOnlyCollection value) } var success = this._dictionary.TryGetValue(key, out var collection); - value = collection; + value = collection!; return success; } } diff --git a/src/Cadru.Collections/NameValuePair.cs b/src/Cadru.Collections/NameValuePair.cs index 96f3fb7a..50c3f28c 100644 --- a/src/Cadru.Collections/NameValuePair.cs +++ b/src/Cadru.Collections/NameValuePair.cs @@ -68,7 +68,6 @@ public NameValuePair(string key) /// if left and right do note represent the same /// server; otherwise . /// - [SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1625:ElementDocumentationMustNotBeCopiedAndPasted", Justification = "Reviewed.")] public static bool operator !=(NameValuePair left, NameValuePair right) { return !left.Equals(right); @@ -84,7 +83,6 @@ public NameValuePair(string key) /// if left and right represent the same server; /// otherwise . /// - [SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1625:ElementDocumentationMustNotBeCopiedAndPasted", Justification = "Reviewed.")] public static bool operator ==(NameValuePair left, NameValuePair right) { return left.Equals(right); @@ -128,9 +126,9 @@ public bool Equals(NameValuePair other) /// equals the value of this /// instance; otherwise, . /// - public override bool Equals(object obj) + public override bool Equals(object? obj) { - if (obj.IsNull() || !(obj is NameValuePair pair)) + if (obj.IsNull() || obj is not NameValuePair pair) { return false; } @@ -162,10 +160,10 @@ public override int GetHashCode() public override string ToString() { var stringBuilder = new StringBuilder(16); - stringBuilder.Append("["); + stringBuilder.Append('['); if (this.Key.IsNotNull()) { - stringBuilder.Append(this.Key.ToString()); + stringBuilder.Append(this.Key); } stringBuilder.Append(": "); @@ -184,7 +182,7 @@ public override string ToString() } } - stringBuilder.Append("]"); + stringBuilder.Append(']'); return stringBuilder.ToString(); } } diff --git a/src/Cadru.Collections/ReverseComparisonComparer(T).cs b/src/Cadru.Collections/ReverseComparisonComparer(T).cs index b7c42f47..52dab6a9 100644 --- a/src/Cadru.Collections/ReverseComparisonComparer(T).cs +++ b/src/Cadru.Collections/ReverseComparisonComparer(T).cs @@ -56,7 +56,6 @@ protected ReverseComparisonComparer(Comparison comparison) /// /// is . /// - [SuppressMessage("Microsoft.Design", "CA1000:DoNotDeclareStaticMembersOnGenericTypes", Justification = "The type must be generic but the Create method shouldn't be.")] public new static Comparer Create(Comparison comparison) { Requires.NotNull(comparison, nameof(comparison)); @@ -66,10 +65,10 @@ public new static Comparer Create(Comparison comparison) /// /// This compare operation reverses the comparison. - public override int Compare(T x, T y) + public override int Compare(T? x, T? y) { // This intentionally reverses the order of the comparison parameters. - return this.comparison(y, x); + return this.comparison(y!, x!); } } } \ No newline at end of file diff --git a/src/Cadru.Core/Color/HSV.cs b/src/Cadru.Core/Color/HSV.cs index 69be7152..6d8a9f2c 100644 --- a/src/Cadru.Core/Color/HSV.cs +++ b/src/Cadru.Core/Color/HSV.cs @@ -87,7 +87,7 @@ public double Value } /// - public override bool Equals(object obj) + public override bool Equals(object? obj) { if (obj is HSV hsv) { diff --git a/src/Cadru.Core/Color/RGB.cs b/src/Cadru.Core/Color/RGB.cs index 0747ba6c..cd80f4d6 100644 --- a/src/Cadru.Core/Color/RGB.cs +++ b/src/Cadru.Core/Color/RGB.cs @@ -139,7 +139,7 @@ public byte Red } /// - public override bool Equals(object obj) + public override bool Equals(object? obj) { if (obj is RGB rgb) { diff --git a/src/Cadru.Core/Color/RGBA.cs b/src/Cadru.Core/Color/RGBA.cs index ab420f1d..1d3e0065 100644 --- a/src/Cadru.Core/Color/RGBA.cs +++ b/src/Cadru.Core/Color/RGBA.cs @@ -185,7 +185,7 @@ public byte Red } /// - public override bool Equals(object obj) + public override bool Equals(object? obj) { if (obj is RGBA rgba) { diff --git a/src/Cadru.Core/Comb.cs b/src/Cadru.Core/Comb.cs index 93ff8c2a..9ff09603 100644 --- a/src/Cadru.Core/Comb.cs +++ b/src/Cadru.Core/Comb.cs @@ -125,11 +125,6 @@ public Comb(byte[] array) /// The next 2 bytes of the . /// The next 2 bytes of the . /// The remaining 8 bytes of the . - [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "a", Justification = "Reviewed.")] - [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "b", Justification = "Reviewed.")] - [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "c", Justification = "Reviewed.")] - [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "d", Justification = "Reviewed.")] - [SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1625:ElementDocumentationMustNotBeCopiedAndPasted", Justification = "Reviewed.")] public Comb(int a, short b, short c, byte[] d) : this() { @@ -165,18 +160,6 @@ public Comb(int a, short b, short c, byte[] d) /// The next byte of the . /// The next byte of the . /// The next byte of the . - [SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1625:ElementDocumentationMustNotBeCopiedAndPasted", Justification = "Reviewed.")] - [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "a", Justification = "Reviewed.")] - [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "b", Justification = "Reviewed.")] - [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "c", Justification = "Reviewed.")] - [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "d", Justification = "Reviewed.")] - [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "e", Justification = "Reviewed.")] - [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "f", Justification = "Reviewed.")] - [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "g", Justification = "Reviewed.")] - [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "h", Justification = "Reviewed.")] - [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "i", Justification = "Reviewed.")] - [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "j", Justification = "Reviewed.")] - [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "k", Justification = "Reviewed.")] public Comb(int a, short b, short c, byte d, byte e, byte f, byte g, byte h, byte i, byte j, byte k) : this() { @@ -218,7 +201,6 @@ public Comb(int a, short b, short c, byte d, byte e, byte f, byte g, byte h, byt /// but not more. /// /// - [SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1650:ElementDocumentationMustBeSpelledCorrectly", Justification = "Reviewed.")] public Comb(string value) { Requires.NotNullOrEmpty(value, nameof(value)); @@ -776,7 +758,7 @@ public static bool TryParseExact(string input, string format, out Comb result) /// /// is not a . /// - public int CompareTo(object obj) + public int CompareTo(object? obj) { if (obj == null) { @@ -835,9 +817,9 @@ public int CompareTo(Comb other) /// and has the same value as this instance; /// otherwise, . /// - public override bool Equals(object obj) + public override bool Equals(object? obj) { - if (!(obj is Comb comb)) + if (obj is not Comb comb) { return false; } @@ -889,7 +871,6 @@ public override int GetHashCode() /// method on the returned string. /// /// - [SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1650:ElementDocumentationMustBeSpelledCorrectly", Justification = "Reviewed.")] public override string ToString() { return this.ToString("D", null); @@ -967,7 +948,7 @@ public override string ToString() /// method on the returned string. /// /// - public string ToString(string format) + public string ToString(string? format) { if (format.IsNullOrEmpty()) { @@ -1166,9 +1147,7 @@ public string ToString(string format) /// Types article. /// /// - [SuppressMessage("Microsoft.Globalization", "CA1305:SpecifyIFormatProvider", MessageId = "Cadru.Comb.ToString(System.String)", Justification = "Reviewed.")] - [SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1628:DocumentationTextMustBeginWithACapitalLetter", Justification = "Reviewed.")] - public string ToString(string format, IFormatProvider? formatProvider) + public string ToString(string? format, IFormatProvider? formatProvider) { return this.ToString(format); } @@ -1200,7 +1179,6 @@ public byte[] ToByteArray() return buffer; } - [SuppressMessage("StyleCop.CSharp.NamingRules", "SA1305:FieldNamesMustNotUseHungarianNotation", Justification = "Reviewed.")] private static int Compare(Comb x, Comb y) { var xBuffer = x.ToByteArray(); @@ -1229,30 +1207,15 @@ private static string ParseFormat(string format) return "D"; } - switch (format[0]) + return (format[0]) switch { - case 'N': - case 'n': - return "N"; - - case 'D': - case 'd': - return "D"; - - case 'B': - case 'b': - return "B"; - - case 'P': - case 'p': - return "P"; - - case 'X': - case 'x': - return "X"; - } - - throw new FormatException(Strings.Format_InvalidGuidFormatSpecification); + 'N' or 'n' => "N", + 'D' or 'd' => "D", + 'B' or 'b' => "B", + 'P' or 'p' => "P", + 'X' or 'x' => "X", + _ => throw new FormatException(Strings.Format_InvalidGuidFormatSpecification), + }; } private DateTimeOffset GetDateTimeOffset() diff --git a/src/Cadru.Core/ConstrainedNumeric.cs b/src/Cadru.Core/ConstrainedNumeric.cs index f00a2e80..83ce01e4 100644 --- a/src/Cadru.Core/ConstrainedNumeric.cs +++ b/src/Cadru.Core/ConstrainedNumeric.cs @@ -92,7 +92,7 @@ public T Value } /// - public int CompareTo(object obj) + public int CompareTo(object? obj) { if (obj == null) { @@ -118,9 +118,9 @@ public int CompareTo(object obj) public int CompareTo(T other) => this.Value.CompareTo(other); /// - public override bool Equals(object obj) + public override bool Equals(object? obj) { - if (!(obj is ConstrainedNumeric cn)) + if (obj is not ConstrainedNumeric cn) { return false; } diff --git a/src/Cadru.Core/Enum{T}.cs b/src/Cadru.Core/Enum{T}.cs index 9ba294ba..02dff359 100644 --- a/src/Cadru.Core/Enum{T}.cs +++ b/src/Cadru.Core/Enum{T}.cs @@ -39,8 +39,6 @@ namespace Cadru /// Provides a class for working with enumerations. /// /// The enumeration type. - [SuppressMessage("Microsoft.Naming", "CA1711:IdentifiersShouldNotHaveIncorrectSuffix", Justification = "Reviewed.")] - [SuppressMessage("Microsoft.Naming", "CA1716:IdentifiersShouldNotMatchKeywords", Justification = "Reviewed.")] public static class Enum where TEnum : struct { /// @@ -69,7 +67,6 @@ public static class Enum where TEnum : struct /// type as . ///

/// - [SuppressMessage("Microsoft.Design", "CA1000:DoNotDeclareStaticMembersOnGenericTypes", Justification = "Reviewed.")] public static string? GetDescription(TEnum value) { return GetDescription(value, useNameAsFallback: true); @@ -116,11 +113,10 @@ public static class Enum where TEnum : struct /// type as . ///

/// - [SuppressMessage("Microsoft.Design", "CA1000:DoNotDeclareStaticMembersOnGenericTypes", Justification = "Reviewed.")] public static string? GetDescription(TEnum value, bool useNameAsFallback) { - var fieldInfo = value.GetType().GetTypeInfo().GetDeclaredField(value.ToString()); - return fieldInfo.GetDescription(useNameAsFallback); + var fieldInfo = value.GetType().GetTypeInfo().GetDeclaredField(value.ToString()!); + return fieldInfo?.GetDescription(useNameAsFallback); } /// @@ -130,7 +126,6 @@ public static class Enum where TEnum : struct /// /// is not an . /// - [SuppressMessage("Microsoft.Design", "CA1000:DoNotDeclareStaticMembersOnGenericTypes", Justification = "Reviewed.")] public static IEnumerable GetDescriptions() { return GetDescriptions(useNameAsFallback: true); @@ -153,7 +148,6 @@ public static class Enum where TEnum : struct /// , then the name of the enumerated constant is /// used; otherwise, a is used. /// - [SuppressMessage("Microsoft.Design", "CA1000:DoNotDeclareStaticMembersOnGenericTypes", Justification = "Reviewed.")] public static IEnumerable GetDescriptions(bool useNameAsFallback) { var type = typeof(TEnum).GetTypeInfo(); @@ -196,8 +190,7 @@ public static class Enum where TEnum : struct /// type as . ///

/// - [SuppressMessage("Microsoft.Design", "CA1000:DoNotDeclareStaticMembersOnGenericTypes", Justification = "Reviewed.")] - public static string GetName(TEnum value) + public static string? GetName(TEnum value) { return Enum.GetName(typeof(TEnum), value); } @@ -209,8 +202,6 @@ public static string GetName(TEnum value) /// /// is not an . /// - [SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate", Justification = "Reviewed.")] - [SuppressMessage("Microsoft.Design", "CA1000:DoNotDeclareStaticMembersOnGenericTypes", Justification = "Reviewed.")] public static IEnumerable GetNames() { return Enum.GetNames(typeof(TEnum)); @@ -223,8 +214,6 @@ public static IEnumerable GetNames() /// /// is not an . /// - [SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate", Justification = "Reviewed.")] - [SuppressMessage("Microsoft.Design", "CA1000:DoNotDeclareStaticMembersOnGenericTypes", Justification = "Reviewed.")] public static Type GetUnderlyingType() { return Enum.GetUnderlyingType(typeof(TEnum)); @@ -247,8 +236,6 @@ public static Type GetUnderlyingType() /// reflection-only context. ///

/// - [SuppressMessage("Microsoft.Design", "CA1000:DoNotDeclareStaticMembersOnGenericTypes", Justification = "Reviewed.")] - [SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate", Justification = "Reviewed.")] public static IEnumerable GetValues() { return Enum.GetValues(typeof(TEnum)).OfType(); @@ -284,7 +271,6 @@ public static IEnumerable GetValues() /// , , , /// , or . /// - [SuppressMessage("Microsoft.Design", "CA1000:DoNotDeclareStaticMembersOnGenericTypes", Justification = "Reviewed.")] public static bool IsDefined(object value) { return Enum.IsDefined(typeof(TEnum), value); @@ -319,7 +305,6 @@ public static bool IsDefined(object value) /// is outside the range of the underlying type /// of . /// - [SuppressMessage("Microsoft.Design", "CA1000:DoNotDeclareStaticMembersOnGenericTypes", Justification = "Reviewed.")] public static TEnum Parse(string value) { return Parse(value, true); @@ -359,7 +344,6 @@ public static TEnum Parse(string value) /// is outside the range of the underlying type /// of . /// - [SuppressMessage("Microsoft.Design", "CA1000:DoNotDeclareStaticMembersOnGenericTypes", Justification = "Reviewed.")] public static TEnum Parse(string value, bool ignoreCase) { return (TEnum)Enum.Parse(typeof(TEnum), value, ignoreCase); @@ -384,7 +368,6 @@ public static TEnum Parse(string value, bool ignoreCase) /// , or . ///

/// - [SuppressMessage("Microsoft.Design", "CA1000:DoNotDeclareStaticMembersOnGenericTypes", Justification = "Reviewed.")] public static TEnum ToEnum(object value) { return (TEnum)Enum.ToObject(typeof(TEnum), value); @@ -411,7 +394,6 @@ public static TEnum ToEnum(object value) /// /// is not an enumeration type. /// - [SuppressMessage("Microsoft.Design", "CA1000:DoNotDeclareStaticMembersOnGenericTypes", Justification = "Reviewed.")] public static bool TryParse(string value, out TEnum result) { return TryParse(value, true, out result); @@ -443,7 +425,6 @@ public static bool TryParse(string value, out TEnum result) /// /// is not an enumeration type. /// - [SuppressMessage("Microsoft.Design", "CA1000:DoNotDeclareStaticMembersOnGenericTypes", Justification = "Reviewed.")] public static bool TryParse(string value, bool ignoreCase, out TEnum result) { return Enum.TryParse(value, ignoreCase, out result); diff --git a/src/Cadru.Core/Extensions/DictionaryExtensions.cs b/src/Cadru.Core/Extensions/DictionaryExtensions.cs index 2d5ad497..d3374671 100644 --- a/src/Cadru.Core/Extensions/DictionaryExtensions.cs +++ b/src/Cadru.Core/Extensions/DictionaryExtensions.cs @@ -23,6 +23,7 @@ using System; using System.Collections; using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; using Validation; @@ -100,7 +101,7 @@ public static class DictionaryExtensions /// /// is . /// - public static TValue GetValueOrDefault(this IDictionary source, object key, TValue defaultValue) + public static TValue? GetValueOrDefault(this IDictionary source, object key, TValue defaultValue) { Requires.NotNull(source, nameof(source)); @@ -252,7 +253,7 @@ public static TValue GetValueOrDefault(this IDictionary source, object k /// /// is . /// - public static bool TryGetValueOrDefault(this IDictionary dictionary, TKey key, TValue defaultValue, out TValue value) + public static bool TryGetValueOrDefault(this IDictionary dictionary, TKey key, TValue defaultValue, [MaybeNullWhen(false)] out TValue value) { Requires.NotNull(dictionary, nameof(dictionary)); @@ -289,7 +290,7 @@ public static TValue GetValueOrDefault(this IDictionary source, object k /// /// is . /// - public static bool TryGetValueOrDefault(this IDictionary dictionary, object key, TValue defaultValue, out TValue value) + public static bool TryGetValueOrDefault(this IDictionary dictionary, object key, TValue defaultValue, [MaybeNullWhen(false)] out TValue value) { Requires.NotNull(dictionary, nameof(dictionary)); diff --git a/src/Cadru.Core/Extensions/EnumExtensions.cs b/src/Cadru.Core/Extensions/EnumExtensions.cs index bce91369..cbd57f25 100644 --- a/src/Cadru.Core/Extensions/EnumExtensions.cs +++ b/src/Cadru.Core/Extensions/EnumExtensions.cs @@ -103,7 +103,7 @@ public static string GetDescription(this Enum value) Requires.That(value.GetType().IsEnum, nameof(value), Strings.ArgumentExceptionMustBeEnum); var fieldInfo = value.GetType().GetTypeInfo().GetDeclaredField(value.ToString()); - return fieldInfo.GetDescription(useNameAsFallback); + return fieldInfo?.GetDescription(useNameAsFallback); } } } \ No newline at end of file diff --git a/src/Cadru.Core/Extensions/NameValueCollectionExtensions.cs b/src/Cadru.Core/Extensions/NameValueCollectionExtensions.cs index 95b231f5..26d17a36 100644 --- a/src/Cadru.Core/Extensions/NameValueCollectionExtensions.cs +++ b/src/Cadru.Core/Extensions/NameValueCollectionExtensions.cs @@ -36,7 +36,7 @@ public static class NameValueCollectionExtensions ///The index of the first matching item, or -1 if no items match. public static int GetKeyIndex(this NameValueCollection nameValueCollection, string key) { - return nameValueCollection.AllKeys.FindIndex(e => e.Equals(key, StringComparison.OrdinalIgnoreCase)); + return nameValueCollection.AllKeys.FindIndex(e => (e?.Equals(key, StringComparison.OrdinalIgnoreCase) ?? false)); } } } \ No newline at end of file diff --git a/src/Cadru.Core/Extensions/TypeExtensions.cs b/src/Cadru.Core/Extensions/TypeExtensions.cs index 661eac30..d0404f48 100644 --- a/src/Cadru.Core/Extensions/TypeExtensions.cs +++ b/src/Cadru.Core/Extensions/TypeExtensions.cs @@ -53,9 +53,9 @@ public static class TypeExtensions /// A custom attribute that matches , or /// if no such attribute is found. /// - public static T GetAttributeOfType(this FieldInfo element, bool inherit = false) where T : Attribute + public static T? GetAttributeOfType(this FieldInfo element, bool inherit = false) where T : Attribute { - return element.GetCustomAttributes(inherit).FirstOrDefault(); + return element.GetCustomAttributes(inherit)?.FirstOrDefault(); } /// @@ -117,7 +117,6 @@ public static class TypeExtensions /// /// A custom attribute type cannot be loaded. /// - [SuppressMessage("Microsoft.Design", "CA1004:GenericMethodsShouldProvideTypeParameter", Justification = "Reviewed.")] public static bool HasCustomAttribute(this Type element, bool inherit = false) where T : Attribute { Requires.NotNull(element, nameof(element)); @@ -166,7 +165,6 @@ public static class TypeExtensions /// if the specified type implements the /// interface; otherwise, . /// - [SuppressMessage("Microsoft.Design", "CA1004:GenericMethodsShouldProvideTypeParameter", Justification = "Reviewed.")] public static bool HasInterface(this Type element) { Requires.NotNull(element, nameof(element)); @@ -261,7 +259,7 @@ public static bool IsDate(this TypeInfo element) if (element.IsNullable()) { var underlyingType = Nullable.GetUnderlyingType(type); - return underlyingType.IsDate(); + return underlyingType?.IsDate() ?? false; } return type == typeof(DateTime); @@ -297,7 +295,7 @@ public static bool IsDateOffset(this TypeInfo element) if (element.IsNullable()) { var underlyingType = Nullable.GetUnderlyingType(type); - return underlyingType.IsDateOffset(); + return underlyingType?.IsDateOffset() ?? false; } return type == typeof(DateTimeOffset); @@ -371,7 +369,6 @@ public static bool IsFlagsEnum(this TypeInfo element) /// /// if the specified type is nullable; otherwise, . /// - [SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1650:ElementDocumentationMustBeSpelledCorrectly", Justification = "Reviewed.")] public static bool IsNullable(this Type element) { Requires.NotNull(element, nameof(element)); @@ -428,7 +425,7 @@ public static bool IsNumeric(this TypeInfo element) if (element.IsNullable()) { var underlyingType = Nullable.GetUnderlyingType(type); - return underlyingType.IsNumeric(); + return underlyingType?.IsNumeric() ?? false; } return type == typeof(decimal); diff --git a/src/Cadru.Core/UnixTimestamp.cs b/src/Cadru.Core/UnixTimestamp.cs index ae89bf6b..25ad1e6b 100644 --- a/src/Cadru.Core/UnixTimestamp.cs +++ b/src/Cadru.Core/UnixTimestamp.cs @@ -534,7 +534,7 @@ public UnixTimestamp AddYears(int years) /// /// is not a . /// - public int CompareTo(object obj) + public int CompareTo(object? obj) { if (obj == null) { @@ -596,7 +596,7 @@ public int CompareTo(UnixTimestamp other) /// The current instance and are equal if their /// property values are equal. /// - public override bool Equals(object obj) + public override bool Equals(object? obj) { if (obj is UnixTimestamp timestamp) { @@ -714,12 +714,11 @@ public override string ToString() /// /// is invalid or not supported. /// - public string ToString(string format, IFormatProvider formatProvider) + public string ToString(string? format, IFormatProvider? formatProvider) { return this.seconds.ToString(format, formatProvider); } - [SuppressMessage("Design", "CA1031:Do not catch general exception types", Justification = "")] private static long DateToSeconds(int year, int month, int day, int hour, int minute, int second) { long sec; diff --git a/src/Cadru.Core/WeakReference{T}.cs b/src/Cadru.Core/WeakReference{T}.cs index f21075ce..2b37ac58 100644 --- a/src/Cadru.Core/WeakReference{T}.cs +++ b/src/Cadru.Core/WeakReference{T}.cs @@ -73,9 +73,9 @@ public WeakReference(T target, bool trackResurrection) /// thrown while setting this property if the value is a null reference /// or if the object has been finalized during the set operation. /// - public new T Target + public new T? Target { - get => (T)base.Target; + get => (T?)base.Target; set => base.Target = value; } } diff --git a/src/Cadru.Data.Dapper/Cadru.Data.Dapper.xml b/src/Cadru.Data.Dapper/Cadru.Data.Dapper.xml index 00e1d536..ec8a6b8a 100644 --- a/src/Cadru.Data.Dapper/Cadru.Data.Dapper.xml +++ b/src/Cadru.Data.Dapper/Cadru.Data.Dapper.xml @@ -1780,217 +1780,5 @@ The context which contains this entity. - - - Specifies that is allowed as an input even if the - corresponding type disallows it. - - - - - Initializes a new instance of the class. - - - - - Specifies that is disallowed as an input even if the - corresponding type allows it. - - - - - Initializes a new instance of the class. - - - - - Specifies that a method that will never return under any circumstance. - - - - - Initializes a new instance of the class. - - - - - - Specifies that the method will not return if the associated - parameter is passed the specified value. - - - - - Gets the condition parameter value. - Code after the method is considered unreachable by diagnostics if the argument - to the associated parameter matches this value. - - - - - Initializes a new instance of the - class with the specified parameter value. - - - The condition parameter value. - Code after the method is considered unreachable by diagnostics if the argument - to the associated parameter matches this value. - - - - - Specifies that an output may be even if the - corresponding type disallows it. - - - - - Initializes a new instance of the class. - - - - - Specifies that when a method returns , - the parameter may be even if the corresponding type disallows it. - - - - - Gets the return value condition. - If the method returns this value, the associated parameter may be . - - - - - Initializes the attribute with the specified return value condition. - - - The return value condition. - If the method returns this value, the associated parameter may be . - - - - - Specifies that the method or property will ensure that the listed field and property members have - not- values. - - - - - Gets field or property member names. - - - - - Initializes the attribute with a field or property member. - - - The field or property member that is promised to be not-null. - - - - - Initializes the attribute with the list of field and property members. - - - The list of field and property members that are promised to be not-null. - - - - - Specifies that the method or property will ensure that the listed field and property members have - non- values when returning with the specified return value condition. - - - - - Gets the return value condition. - - - - - Gets field or property member names. - - - - - Initializes the attribute with the specified return value condition and a field or property member. - - - The return value condition. If the method returns this value, - the associated parameter will not be . - - - The field or property member that is promised to be not-. - - - - - Initializes the attribute with the specified return value condition and list - of field and property members. - - - The return value condition. If the method returns this value, - the associated parameter will not be . - - - The list of field and property members that are promised to be not-null. - - - - - Specifies that an output is not even if the - corresponding type allows it. - - - - - Initializes a new instance of the class. - - - - - Specifies that the output will be non- if the - named parameter is non-. - - - - - Gets the associated parameter name. - The output will be non- if the argument to the - parameter specified is non-. - - - - - Initializes the attribute with the associated parameter name. - - - The associated parameter name. - The output will be non- if the argument to the - parameter specified is non-. - - - - - Specifies that when a method returns , - the parameter will not be even if the corresponding type allows it. - - - - - Gets the return value condition. - If the method returns this value, the associated parameter will not be . - - - - - Initializes the attribute with the specified return value condition. - - - The return value condition. - If the method returns this value, the associated parameter will not be . - - diff --git a/src/Cadru.Data/Cadru.Data.xml b/src/Cadru.Data/Cadru.Data.xml index 43a59ec2..e8d130cf 100644 --- a/src/Cadru.Data/Cadru.Data.xml +++ b/src/Cadru.Data/Cadru.Data.xml @@ -1472,5 +1472,217 @@ Looks up a localized string similar to TextFieldParser does not support comment tokens that contain white space..
+ + + Specifies that is allowed as an input even if the + corresponding type disallows it. + + + + + Initializes a new instance of the class. + + + + + Specifies that is disallowed as an input even if the + corresponding type allows it. + + + + + Initializes a new instance of the class. + + + + + Specifies that a method that will never return under any circumstance. + + + + + Initializes a new instance of the class. + + + + + + Specifies that the method will not return if the associated + parameter is passed the specified value. + + + + + Gets the condition parameter value. + Code after the method is considered unreachable by diagnostics if the argument + to the associated parameter matches this value. + + + + + Initializes a new instance of the + class with the specified parameter value. + + + The condition parameter value. + Code after the method is considered unreachable by diagnostics if the argument + to the associated parameter matches this value. + + + + + Specifies that an output may be even if the + corresponding type disallows it. + + + + + Initializes a new instance of the class. + + + + + Specifies that when a method returns , + the parameter may be even if the corresponding type disallows it. + + + + + Gets the return value condition. + If the method returns this value, the associated parameter may be . + + + + + Initializes the attribute with the specified return value condition. + + + The return value condition. + If the method returns this value, the associated parameter may be . + + + + + Specifies that the method or property will ensure that the listed field and property members have + not- values. + + + + + Gets field or property member names. + + + + + Initializes the attribute with a field or property member. + + + The field or property member that is promised to be not-null. + + + + + Initializes the attribute with the list of field and property members. + + + The list of field and property members that are promised to be not-null. + + + + + Specifies that the method or property will ensure that the listed field and property members have + non- values when returning with the specified return value condition. + + + + + Gets the return value condition. + + + + + Gets field or property member names. + + + + + Initializes the attribute with the specified return value condition and a field or property member. + + + The return value condition. If the method returns this value, + the associated parameter will not be . + + + The field or property member that is promised to be not-. + + + + + Initializes the attribute with the specified return value condition and list + of field and property members. + + + The return value condition. If the method returns this value, + the associated parameter will not be . + + + The list of field and property members that are promised to be not-null. + + + + + Specifies that an output is not even if the + corresponding type allows it. + + + + + Initializes a new instance of the class. + + + + + Specifies that the output will be non- if the + named parameter is non-. + + + + + Gets the associated parameter name. + The output will be non- if the argument to the + parameter specified is non-. + + + + + Initializes the attribute with the associated parameter name. + + + The associated parameter name. + The output will be non- if the argument to the + parameter specified is non-. + + + + + Specifies that when a method returns , + the parameter will not be even if the corresponding type allows it. + + + + + Gets the return value condition. + If the method returns this value, the associated parameter will not be . + + + + + Initializes the attribute with the specified return value condition. + + + The return value condition. + If the method returns this value, the associated parameter will not be . + + diff --git a/src/Cadru.Data/Excel/ExcelDataReader.IDataReader.cs b/src/Cadru.Data/Excel/ExcelDataReader.IDataReader.cs index 28133f95..ec009d3c 100644 --- a/src/Cadru.Data/Excel/ExcelDataReader.IDataReader.cs +++ b/src/Cadru.Data/Excel/ExcelDataReader.IDataReader.cs @@ -257,12 +257,12 @@ private IList GetFirstRowAsHeaders(OpenXmlPart worksheetPart) return result; } - private Sheet GetSheetByIndex(int sheetIndex) + private Sheet? GetSheetByIndex(int sheetIndex) { return this.sheets.ElementAtOrDefault(sheetIndex); } - private Sheet GetSheetByName(string sheetName) + private Sheet? GetSheetByName(string sheetName) { return this.sheets.FirstOrDefault(x => x.Name == sheetName); } diff --git a/src/Cadru.Data/Excel/ExcelDataReader.IDataRecord.cs b/src/Cadru.Data/Excel/ExcelDataReader.IDataRecord.cs index 5f99b2cd..568a7be3 100644 --- a/src/Cadru.Data/Excel/ExcelDataReader.IDataRecord.cs +++ b/src/Cadru.Data/Excel/ExcelDataReader.IDataRecord.cs @@ -62,7 +62,7 @@ public long GetChars(int i, long fieldoffset, char[] buffer, int bufferoffset, i } /// - public IDataReader? GetData(int i) + public IDataReader GetData(int i) { return null; } diff --git a/src/Cadru.Environment/Cadru.Environment.csproj b/src/Cadru.Environment/Cadru.Environment.csproj index 91639005..4062fba9 100644 --- a/src/Cadru.Environment/Cadru.Environment.csproj +++ b/src/Cadru.Environment/Cadru.Environment.csproj @@ -1,6 +1,6 @@  - netstandard2.0;netstandard2.1;net5.0 + netstandard2.0;netstandard2.1;net5.0-windows latest enable Provides support for determining framework versions, IIS version and feature detection. diff --git a/src/Cadru.Environment/FrameworkVersionDetection.cs b/src/Cadru.Environment/FrameworkVersionDetection.cs index e01fc6ad..84ec1d97 100644 --- a/src/Cadru.Environment/FrameworkVersionDetection.cs +++ b/src/Cadru.Environment/FrameworkVersionDetection.cs @@ -543,7 +543,7 @@ private static bool GetCoreFrameworkVersion(FrameworkVersion frameworkVersion, o if (!String.IsNullOrEmpty(installPath)) { var fvi = FileVersionInfo.GetVersionInfo(installPath); - if (fvi != null) + if (fvi != null && fvi.ProductVersion != null) { version = new Version(fvi.ProductVersion); valid = true; @@ -667,9 +667,6 @@ private static Version GetNetfx10ExactVersion() /// determine what service pack for the .NET Framework 1.0 is installed /// on the machine. /// - [SuppressMessage("Microsoft.Usage", "CA1806:DoNotIgnoreMethodResults", - MessageId = "System.Int32.TryParse(System.String,System.Int32@)", - Justification = "In this case, we're already defaulting the out parameter but want to make sure the Parse isn't going to throw an exception.")] private static int GetNetfx10SPLevel() { var servicePackLevel = -1; @@ -692,7 +689,10 @@ private static int GetNetfx10SPLevel() var index = regValue.LastIndexOf(','); if (index > 0) { - Int32.TryParse(regValue.Substring(index + 1), out servicePackLevel); + if (!Int32.TryParse(regValue.Substring(index + 1), out servicePackLevel)) + { + servicePackLevel = -1; + } } } @@ -737,7 +737,6 @@ private static Version GetNetfx11ExactVersion() /// returned that represents a 0.0.0.0 version number if the .NET /// Framework 2.0 is not found. /// - [SuppressMessage("Design", "CA1031:Do not catch general exception types", Justification = "")] private static Version GetNetfx20ExactVersion() { var emptyVersion = new Version(0, 0, 0, 0); @@ -799,8 +798,14 @@ private static Version GetNetfx30CardSpaceExactVersion() if (GetRegistryValue(RegistryHive.LocalMachine, CardSpaceServicesRegKeyName, CardSpaceServicesPlusImagePathRegName, RegistryValueKind.ExpandString, out string regValue) && !String.IsNullOrEmpty(regValue)) { var fileVersionInfo = FileVersionInfo.GetVersionInfo(regValue.Trim('"')); - var index = fileVersionInfo.FileVersion.IndexOf(' '); - version = new Version(fileVersionInfo.FileVersion.Substring(0, index)); + if (!String.IsNullOrWhiteSpace(fileVersionInfo.FileVersion)) + { + var index = fileVersionInfo.FileVersion.IndexOf(' '); + if (index > 0) + { + version = new Version(fileVersionInfo.FileVersion.Substring(0, index)); + } + } } return version; @@ -1072,7 +1077,6 @@ private static string GetRegistryKey(FrameworkVersion frameworkVersion) /// /// if the registry value was found; otherwise, . /// - [SuppressMessage("Design", "CA1031:Do not catch general exception types", Justification = "")] private static bool GetRegistryValue(RegistryHive hive, string key, string value, RegistryValueKind kind, out T data) { var success = false; diff --git a/src/Cadru.Environment/InternetInformationServicesDetection.cs b/src/Cadru.Environment/InternetInformationServicesDetection.cs index 59acefd6..45e824d3 100644 --- a/src/Cadru.Environment/InternetInformationServicesDetection.cs +++ b/src/Cadru.Environment/InternetInformationServicesDetection.cs @@ -264,8 +264,6 @@ public static bool IsInstalled(InternetInformationServicesSubcomponent subcompon /// Services feature is installed; otherwise . /// /// Features only apply to IIS versions 7 and later. - [SuppressMessage("Microsoft.Maintainability", "CA1502:AvoidExcessiveComplexity", - Justification = "This method appears to be complex because of it's length, but it's almost all just a switch statement which then calls out to other methods to do the work.")] public static bool IsInstalled(InternetInformationServicesFeature feature) { var ret = false; @@ -491,7 +489,6 @@ private static Version GetInstalledVersion() /// /// if the registry value was found; otherwise, . /// - [SuppressMessage("Design", "CA1031:Do not catch general exception types", Justification = "")] private static bool GetRegistryValue(RegistryHive hive, string key, string value, RegistryValueKind kind, out T data) { var success = false; diff --git a/src/Cadru.Net.Http/Cadru.Net.Http.xml b/src/Cadru.Net.Http/Cadru.Net.Http.xml index 3bc6f655..2b6646cf 100644 --- a/src/Cadru.Net.Http/Cadru.Net.Http.xml +++ b/src/Cadru.Net.Http/Cadru.Net.Http.xml @@ -101,6 +101,24 @@ inner handler.
+ + + Provides HTTP content based on an empty string. + + + + + Creates a new instance of the class. + + A instance. + + + + Creates a new instance of the class. + + The media type to use for the content. + A instance. + Extension methods that aid in making formatted requests using . diff --git a/src/Cadru.Net.Http/Extensions/HttpExtensions.cs b/src/Cadru.Net.Http/Extensions/HttpExtensions.cs index a28a6927..46b9eec2 100644 --- a/src/Cadru.Net.Http/Extensions/HttpExtensions.cs +++ b/src/Cadru.Net.Http/Extensions/HttpExtensions.cs @@ -134,31 +134,12 @@ public static string AsString(this HttpContent content) /// A valid . public static HttpRequestMessage CreateRequestMessage(this HttpClient httpClient, HttpMethod method, Uri uri, QueryStringParametersDictionary? queryStringParameters = null, IDictionary? headerCollection = null) { - Uri? requestUri = null; - if ((uri == null) && (httpClient.BaseAddress == null)) + if (httpClient.BaseAddress == null && (uri == null || !uri.IsAbsoluteUri)) { throw new InvalidOperationException(Strings.net_http_client_invalid_requesturi); } - if (uri == null) - { - requestUri = httpClient.BaseAddress; - } - else - { - // If the request Uri is an absolute Uri, just use it. Otherwise - // try to combine it with the base Uri. - if (!uri.IsAbsoluteUri) - { - if (httpClient.BaseAddress == null) - { - throw new InvalidOperationException(Strings.net_http_client_invalid_requesturi); - } - else - { - requestUri = new Uri(httpClient.BaseAddress, uri); - } - } - } + + var requestUri = uri == null ? httpClient.BaseAddress! : new Uri(httpClient.BaseAddress!, uri); if (queryStringParameters != null) { diff --git a/src/Cadru.Net.Http/HttpRequestWithStatusException.cs b/src/Cadru.Net.Http/HttpRequestWithStatusException.cs index 379b722c..a0ff6f83 100644 --- a/src/Cadru.Net.Http/HttpRequestWithStatusException.cs +++ b/src/Cadru.Net.Http/HttpRequestWithStatusException.cs @@ -42,7 +42,10 @@ public class HttpRequestWithStatusException : HttpRequestException public HttpRequestWithStatusException(HttpResponseMessage responseMessage) : base(GetFormattedMessage(responseMessage)) { +#if !NET5_0 this.StatusCode = responseMessage.StatusCode; +#endif + this.ReasonPhrase = responseMessage.ReasonPhrase; } @@ -57,7 +60,10 @@ public class HttpRequestWithStatusException : HttpRequestException public HttpRequestWithStatusException(HttpResponseMessage responseMessage, Exception inner) : base(GetFormattedMessage(responseMessage), inner) { +#if !NET5_0 this.StatusCode = responseMessage.StatusCode; +#endif + this.ReasonPhrase = responseMessage.ReasonPhrase; } @@ -98,13 +104,15 @@ public HttpRequestWithStatusException(string message, Exception inner) : base(me /// with the status code. /// /// The reason phrase sent by the server. - public string ReasonPhrase { get; } + public string? ReasonPhrase { get; } +#if !NET5_0 /// /// Gets the status code of the HTTP response. /// /// The status code of the HTTP response. public HttpStatusCode? StatusCode { get; } +#endif private static string GetFormattedMessage(HttpResponseMessage responseMessage) { diff --git a/src/Cadru.Net.Http/UriScheme.cs b/src/Cadru.Net.Http/UriScheme.cs index d3904790..6d45d201 100644 --- a/src/Cadru.Net.Http/UriScheme.cs +++ b/src/Cadru.Net.Http/UriScheme.cs @@ -30,8 +30,6 @@ namespace Cadru.Net.Http /// /// A helper class for retrieving and comparing standard URI schemes. /// - [SuppressMessage("StyleCop.CSharp.NamingRules", "SA1311:StaticReadonlyFieldsMustBeginWithUpperCaseLetter", Justification = "Reviewed.")] - [SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1623:PropertySummaryDocumentationMustMatchAccessors", Justification = "Reviewed.")] public sealed class UriScheme : IEquatable { private static readonly UriScheme fileScheme = new UriScheme("file"); @@ -141,7 +139,7 @@ internal UriScheme(string scheme) /// if both objects represent the same scheme; /// otherwise, . /// - public static bool operator ==(UriScheme left, UriScheme right) + public static bool operator ==(UriScheme? left, UriScheme? right) { if (left is null || right is null) { @@ -160,7 +158,7 @@ internal UriScheme(string scheme) /// if the parameter /// equals the value of this instance; otherwise, . /// - public override bool Equals(object obj) + public override bool Equals(object? obj) { if (obj is UriScheme uriScheme) { @@ -181,7 +179,7 @@ public override bool Equals(object obj) /// if the parameter /// equals the value of this instance; otherwise, . /// - public bool Equals(UriScheme other) + public bool Equals(UriScheme? other) { if (other == null!) { diff --git a/src/Cadru.Net.Http/UrlBuilder.cs b/src/Cadru.Net.Http/UrlBuilder.cs index f5693b32..14e9e6fd 100644 --- a/src/Cadru.Net.Http/UrlBuilder.cs +++ b/src/Cadru.Net.Http/UrlBuilder.cs @@ -69,8 +69,6 @@ public UrlBuilder() /// -or- /// paramref name="uri"/> is not a valid URI. /// - [SuppressMessage("Microsoft.Usage", "CA2234:PassSystemUriObjectsInsteadOfStrings", Justification = "Reviewed.")] - [SuppressMessage("Microsoft.Design", "CA1057:StringUriOverloadsCallSystemUriOverloads", Justification = "Reviewed.")] public UrlBuilder(string uri) { this.builder = new UriBuilder(uri); @@ -100,8 +98,6 @@ public UrlBuilder(string uri) /// -or- /// paramref name="uri"/> is not a valid URI. /// - [SuppressMessage("Microsoft.Usage", "CA2234:PassSystemUriObjectsInsteadOfStrings", Justification = "Reviewed.")] - [SuppressMessage("Microsoft.Design", "CA1057:StringUriOverloadsCallSystemUriOverloads", Justification = "Reviewed.")] public UrlBuilder(string uri, string path) { this.builder = new UriBuilder(uri); @@ -344,7 +340,7 @@ public string UserName /// as the constructed /// by this instance; otherwise, . /// - public override bool Equals(object obj) + public override bool Equals(object? obj) { this.builder.Query = this.Query; return this.builder.Equals(obj); diff --git a/src/Cadru.Net.NetworkInformation/Cadru.Net.NetworkInformation.xml b/src/Cadru.Net.NetworkInformation/Cadru.Net.NetworkInformation.xml index d4436847..73754724 100644 --- a/src/Cadru.Net.NetworkInformation/Cadru.Net.NetworkInformation.xml +++ b/src/Cadru.Net.NetworkInformation/Cadru.Net.NetworkInformation.xml @@ -1112,13 +1112,13 @@ system running on the computer. - + - + - + diff --git a/src/Cadru.Net.NetworkInformation/Collections/IPAddressComparer.cs b/src/Cadru.Net.NetworkInformation/Collections/IPAddressComparer.cs index 6fce4dd7..b1821e47 100644 --- a/src/Cadru.Net.NetworkInformation/Collections/IPAddressComparer.cs +++ b/src/Cadru.Net.NetworkInformation/Collections/IPAddressComparer.cs @@ -46,38 +46,46 @@ public IPAddressComparer() /// Represents an instance of . /// /// The default - [SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1623:PropertySummaryDocumentationMustMatchAccessors", Justification = "Reviewed.")] public static IComparer Default => new IPAddressComparer(); /// - public int Compare(IPAddress x, IPAddress y) + public int Compare(IPAddress? x, IPAddress? y) { - Requires.NotNull(x, "x"); - Requires.NotNull(y, "y"); - int result; - var u1 = Convert(x.GetAddressBytes()); - var u2 = Convert(y.GetAddressBytes()); - - if (u1 < u2) - { - result = -1; - } - else if (u1 == u2) + result = x switch { - result = 0; - } - else + null when y is null => 0, + null => -1, + _ => CompareBytes(x.GetAddressBytes(), y!.GetAddressBytes()) + }; + + int CompareBytes(byte[] b1, byte[] b2) { - result = 1; + var u1 = Convert(b1); + var u2 = Convert(b2); + + if (u1 < u2) + { + result = -1; + } + else if (u1 == u2) + { + result = 0; + } + else + { + result = 1; + } + + return result; } return result; } /// - public int Compare(object x, object y) + public int Compare(object? x, object? y) { int result; @@ -115,12 +123,8 @@ public int Compare(object x, object y) /// /// The strings should be a valid date time format. - public int Compare(string x, string y) + public int Compare(string? x, string? y) { - Requires.NotNull(x, "x"); - Requires.NotNull(y, "y"); - - if (!IPAddress.TryParse(x, out var t1)) { throw new FormatException(Resources.Strings.Format_Dns_Bad_Ip_Address); @@ -135,7 +139,7 @@ public int Compare(string x, string y) } /// - public bool Equals(IPAddress x, IPAddress y) + public bool Equals(IPAddress? x, IPAddress? y) { if (x == null) { @@ -146,7 +150,7 @@ public bool Equals(IPAddress x, IPAddress y) } /// - public bool Equals(string x, string y) + public bool Equals(string? x, string? y) { if (x == null && y == null) { @@ -208,7 +212,7 @@ public int GetHashCode(object obj) } else { - if (!(obj is string s1)) + if (obj is not string s1) { hashCode = obj.GetHashCode(); } @@ -255,7 +259,7 @@ public int GetHashCode(string obj) } /// - bool IEqualityComparer.Equals(object x, object y) + bool IEqualityComparer.Equals(object? x, object? y) { return Equals(x, y); } diff --git a/src/Cadru.Net.NetworkInformation/NetworkStatus.cs b/src/Cadru.Net.NetworkInformation/NetworkStatus.cs index a6633339..f41771f6 100644 --- a/src/Cadru.Net.NetworkInformation/NetworkStatus.cs +++ b/src/Cadru.Net.NetworkInformation/NetworkStatus.cs @@ -90,7 +90,7 @@ private void ChangeNetworkStatus(ConnectionStatus current) } } - private void NetworkAddressChanged(object sender, EventArgs e) + private void NetworkAddressChanged(object? sender, EventArgs e) { var current = NetworkInterface.GetIsNetworkAvailable() ? ConnectionStatus.Connected : ConnectionStatus.Disconnected; this.ChangeNetworkStatus(current); diff --git a/src/Cadru.Net.NetworkInformation/ServerInfo.cs b/src/Cadru.Net.NetworkInformation/ServerInfo.cs index 470e78a8..1dc56f5f 100644 --- a/src/Cadru.Net.NetworkInformation/ServerInfo.cs +++ b/src/Cadru.Net.NetworkInformation/ServerInfo.cs @@ -103,27 +103,25 @@ internal ServerInfo(SERVER_INFO_101 info) public ServerTypes ServerType { get; } /// - [SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1625:ElementDocumentationMustNotBeCopiedAndPasted", Justification = "Reviewed.")] - public static bool operator ==(ServerInfo left, ServerInfo right) + public static bool operator ==(ServerInfo? left, ServerInfo? right) { return left.Equals(right); } /// - [SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1625:ElementDocumentationMustNotBeCopiedAndPasted", Justification = "Reviewed.")] - public static bool operator !=(ServerInfo left, ServerInfo right) + public static bool operator !=(ServerInfo? left, ServerInfo? right) { return !left.Equals(right); } /// - public static bool Equals(ServerInfo left, ServerInfo right) + public static bool Equals(ServerInfo? left, ServerInfo? right) { return left == right; } /// - public override bool Equals(object obj) + public override bool Equals(object? obj) { if (obj is ServerInfo s) { diff --git a/src/Cadru.Polly/Cadru.Polly.xml b/src/Cadru.Polly/Cadru.Polly.xml index 7df34ad0..d7d7aa63 100644 --- a/src/Cadru.Polly/Cadru.Polly.xml +++ b/src/Cadru.Polly/Cadru.Polly.xml @@ -1221,5 +1221,217 @@ A representing the timeout. + + + Specifies that is allowed as an input even if the + corresponding type disallows it. + + + + + Initializes a new instance of the class. + + + + + Specifies that is disallowed as an input even if the + corresponding type allows it. + + + + + Initializes a new instance of the class. + + + + + Specifies that a method that will never return under any circumstance. + + + + + Initializes a new instance of the class. + + + + + + Specifies that the method will not return if the associated + parameter is passed the specified value. + + + + + Gets the condition parameter value. + Code after the method is considered unreachable by diagnostics if the argument + to the associated parameter matches this value. + + + + + Initializes a new instance of the + class with the specified parameter value. + + + The condition parameter value. + Code after the method is considered unreachable by diagnostics if the argument + to the associated parameter matches this value. + + + + + Specifies that an output may be even if the + corresponding type disallows it. + + + + + Initializes a new instance of the class. + + + + + Specifies that when a method returns , + the parameter may be even if the corresponding type disallows it. + + + + + Gets the return value condition. + If the method returns this value, the associated parameter may be . + + + + + Initializes the attribute with the specified return value condition. + + + The return value condition. + If the method returns this value, the associated parameter may be . + + + + + Specifies that the method or property will ensure that the listed field and property members have + not- values. + + + + + Gets field or property member names. + + + + + Initializes the attribute with a field or property member. + + + The field or property member that is promised to be not-null. + + + + + Initializes the attribute with the list of field and property members. + + + The list of field and property members that are promised to be not-null. + + + + + Specifies that the method or property will ensure that the listed field and property members have + non- values when returning with the specified return value condition. + + + + + Gets the return value condition. + + + + + Gets field or property member names. + + + + + Initializes the attribute with the specified return value condition and a field or property member. + + + The return value condition. If the method returns this value, + the associated parameter will not be . + + + The field or property member that is promised to be not-. + + + + + Initializes the attribute with the specified return value condition and list + of field and property members. + + + The return value condition. If the method returns this value, + the associated parameter will not be . + + + The list of field and property members that are promised to be not-null. + + + + + Specifies that an output is not even if the + corresponding type allows it. + + + + + Initializes a new instance of the class. + + + + + Specifies that the output will be non- if the + named parameter is non-. + + + + + Gets the associated parameter name. + The output will be non- if the argument to the + parameter specified is non-. + + + + + Initializes the attribute with the associated parameter name. + + + The associated parameter name. + The output will be non- if the argument to the + parameter specified is non-. + + + + + Specifies that when a method returns , + the parameter will not be even if the corresponding type allows it. + + + + + Gets the return value condition. + If the method returns this value, the associated parameter will not be . + + + + + Initializes the attribute with the specified return value condition. + + + The return value condition. + If the method returns this value, the associated parameter will not be . + + diff --git a/tests/Cadru.Net.Tests/Http/HttpExtensionsTests.cs b/tests/Cadru.Net.Tests/Http/HttpExtensionsTests.cs new file mode 100644 index 00000000..35678a6f --- /dev/null +++ b/tests/Cadru.Net.Tests/Http/HttpExtensionsTests.cs @@ -0,0 +1,86 @@ +//------------------------------------------------------------------------------ +// +// Copyright (C) 2001-2020 Scott Dorman. +// +// +// +// Licensed under the Microsoft Public License (Ms-PL) (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://opensource.org/licenses/Ms-PL.html +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +//------------------------------------------------------------------------------ + +using System; +using System.Diagnostics.CodeAnalysis; +using System.Net.Http; + +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Cadru.Net.Http.Extensions; +using Cadru.UnitTest.Framework; +using Cadru.Net.Http.Collections; + +namespace Cadru.Net.Http.Tests +{ + [TestClass, ExcludeFromCodeCoverage] + public class HttpExtensionsTests + { + [TestMethod] + public void AsFormattedString() + { + HttpRequestMessage request = null; + + Assert.ThrowsException(() => { request.AsFormattedString(); }); + + request = new HttpRequestMessage(); + Assert.That.IsNotEmpty(request.AsFormattedString()); + + request.Content = new StringContent("body content"); + Assert.That.IsNotEmpty(request.AsFormattedString()); + StringAssert.Contains(request.AsFormattedString(), "Body:"); + } + + [TestMethod] + public void CreateRequestMessage() + { + var client = new HttpClient(); + + Assert.ThrowsException(() => { client.CreateRequestMessage(HttpMethod.Get, null); }); + Assert.ThrowsException(() => { client.CreateRequestMessage(HttpMethod.Get, new Uri("test", UriKind.Relative)); }); + + client.BaseAddress = new Uri("https://example.com/"); + + var requestMessage = client.CreateRequestMessage(HttpMethod.Get, null); + + Assert.IsNotNull(requestMessage); + Assert.IsTrue(requestMessage.Method == HttpMethod.Get); + Assert.AreEqual("https://example.com/", requestMessage.RequestUri.AbsoluteUri); + +// Assert.ThrowsException(() => { client.CreateRequestMessage(HttpMethod.Get, null); }); + + requestMessage = client.CreateRequestMessage(HttpMethod.Get, new Uri("test", UriKind.Relative)); + + Assert.IsNotNull(requestMessage); + Assert.IsTrue(requestMessage.Method == HttpMethod.Get); + Assert.AreEqual("https://example.com/test", requestMessage.RequestUri.AbsoluteUri); + + var queryStringParameters = new QueryStringParametersDictionary(); + queryStringParameters.Add("test", "testvalue"); + + requestMessage = client.CreateRequestMessage(HttpMethod.Get, new Uri("test", UriKind.Relative), queryStringParameters); + Assert.IsNotNull(requestMessage); + Assert.IsTrue(requestMessage.Method == HttpMethod.Get); + Assert.AreEqual("https://example.com/test?test=testvalue", requestMessage.RequestUri.AbsoluteUri); + Assert.That.IsNotEmpty(requestMessage.RequestUri.Query); + } + } +} \ No newline at end of file