public static int CombineValues <T>(ImmutableArray <T> values, int maxItemsToHash = int.MaxValue) { if (values.IsDefaultOrEmpty) { return(0); } var hashCode = 0; var count = 0; foreach (T value in values) { if (count++ >= maxItemsToHash) { break; } // Should end up with a constrained virtual call to object.GetHashCode (i.e. avoid boxing where possible). if (value != null) { hashCode = CodeRefactoringHash.Combine(value.GetHashCode(), hashCode); } } return(hashCode); }
public static int CombineValues <T>(T[] values, int maxItemsToHash = int.MaxValue) { if (values == null) { return(0); } var maxSize = Math.Min(maxItemsToHash, values.Length); var hashCode = 0; for (int i = 0; i < maxSize; i++) { T value = values[i]; // Should end up with a constrained virtual call to object.GetHashCode (i.e. avoid boxing where possible). #pragma warning disable RECS0017 // Possible compare of value type with 'null' if (value != null) #pragma warning restore RECS0017 // Possible compare of value type with 'null' { hashCode = CodeRefactoringHash.Combine(value.GetHashCode(), hashCode); } } return(hashCode); }
public static int CombineValues <T>(ImmutableArray <T> values, int maxItemsToHash = int.MaxValue) { if (values.IsDefaultOrEmpty) { return(0); } var hashCode = 0; var count = 0; foreach (var value in values) { if (count++ >= maxItemsToHash) { break; } // Should end up with a constrained virtual call to object.GetHashCode (i.e. avoid boxing where possible). #pragma warning disable RECS0017 // Possible compare of value type with 'null' if (value != null) #pragma warning restore RECS0017 // Possible compare of value type with 'null' { hashCode = CodeRefactoringHash.Combine(value.GetHashCode(), hashCode); } } return(hashCode); }
public static int CombineValues(IEnumerable <string> values, StringComparer stringComparer, int maxItemsToHash = int.MaxValue) { if (values == null) { return(0); } var hashCode = 0; var count = 0; foreach (var value in values) { if (count++ >= maxItemsToHash) { break; } if (value != null) { hashCode = CodeRefactoringHash.Combine(stringComparer.GetHashCode(value), hashCode); } } return(hashCode); }