public static void HashCode_Combine_Add_1() { var hc = new HashCodeBuilder(); hc.Add(1); Assert.AreEqual(hc.ToHashCode(), HashCodeBuilder.Combine(1)); }
public override int GetHashCode() { var hashCode = new HashCodeBuilder(); hashCode.Add(Name, StringComparer.OrdinalIgnoreCase); hashCode.Add(Value); return hashCode.ToHashCode(); }
public int GetHashCode(SearchField obj) { if (obj is null) { return(0); } HashCodeBuilder builder = new HashCodeBuilder(); builder.Add(obj.Name); builder.Add(obj.Type); builder.Add(obj.IsKey); builder.Add(obj.IsHidden); builder.Add(obj.IsSearchable); builder.Add(obj.IsFilterable); builder.Add(obj.IsSortable); builder.Add(obj.IsFacetable); builder.Add(obj.Analyzer); builder.Add(obj.SearchAnalyzer); builder.Add(obj.IndexAnalyzer); builder.Add(obj.SynonymMaps, CollectionComparer <string> .Shared); builder.Add(obj.Fields, SharedFieldsCollection); return(builder.ToHashCode()); }
public override int GetHashCode() { var hashCode = new HashCodeBuilder(); hashCode.Add(Name, StringComparer.InvariantCultureIgnoreCase); hashCode.Add(Value); return(hashCode.ToHashCode()); }
public override int GetHashCode() { var hashCode = new HashCodeBuilder(); hashCode.Add(Keys); hashCode.Add(Labels); hashCode.Add(AsOf); hashCode.Add(Fields); return(hashCode.ToHashCode()); }
public override int GetHashCode() { var hashCode = new HashCodeBuilder(); hashCode.Add(Keys); hashCode.Add(Labels); hashCode.Add(AsOf); hashCode.Add(Fields); hashCode.Add(BatchLink, StringComparer.Ordinal); return(hashCode.ToHashCode()); }
public static void HashCode_Combine_Add_5() { var hc = new HashCodeBuilder(); hc.Add(1); hc.Add(2); hc.Add(3); hc.Add(4); hc.Add(5); Assert.AreEqual(hc.ToHashCode(), HashCodeBuilder.Combine(1, 2, 3, 4, 5)); }
public static void HashCode_Add_Null() { var hc = new HashCodeBuilder(); hc.Add <string>(null); var expected = new HashCodeBuilder(); expected.Add(EqualityComparer <string> .Default.GetHashCode(null)); Assert.AreEqual(expected.ToHashCode(), hc.ToHashCode()); }
public static void HashCode_Add_HashCode() { var hc1 = new HashCodeBuilder(); hc1.Add("Hello"); var hc2 = new HashCodeBuilder(); hc2.Add("Hello".GetHashCode()); Assert.AreEqual(hc1.ToHashCode(), hc2.ToHashCode()); }
public static void HashCode_Add_NullEqualityComparer() { var hc = new HashCodeBuilder(); hc.Add(1); hc.Add("Hello", null); var expected = new HashCodeBuilder(); expected.Add(1); expected.Add("Hello"); Assert.AreEqual(expected.ToHashCode(), hc.ToHashCode()); }
public static void HashCode_Add_GenericEqualityComparer() { var hc = new HashCodeBuilder(); hc.Add(1); hc.Add("Hello", new ConstComparer()); var expected = new HashCodeBuilder(); expected.Add(1); expected.Add(ConstComparer.ConstantValue); Assert.AreEqual(expected.ToHashCode(), hc.ToHashCode()); }
public int GetHashCode(OutputFieldMappingEntry obj) { if (obj is null) { return(0); } HashCodeBuilder builder = new HashCodeBuilder(); builder.Add(obj.Name); builder.Add(obj.TargetName); return(builder.ToHashCode()); }
public int GetHashCode(ConfigurationSetting setting) { var hashCode = new HashCodeBuilder(); hashCode.Add(setting.Key, StringComparer.Ordinal); hashCode.Add(setting.Label, StringComparer.Ordinal); hashCode.Add(setting.Value, StringComparer.Ordinal); hashCode.Add(setting.ContentType, StringComparer.Ordinal); hashCode.Add(setting.LastModified); hashCode.Add(setting.ETag); hashCode.Add(setting.ReadOnly); hashCode.Add(setting.Tags); return(hashCode.ToHashCode()); }
public int GetHashCode(SearchIndexerSkillset obj) { if (obj is null) { return(0); } HashCodeBuilder builder = new HashCodeBuilder(); builder.Add(obj.Name); builder.Add(obj.Description); builder.Add(obj.Skills, SharedSkillsCollection); return(builder.ToHashCode()); }
public int GetHashCode(ICollection <T> obj) { if (obj is null) { return(0); } HashCodeBuilder builder = new HashCodeBuilder(); foreach (T element in obj) { builder.Add(element, ElementComparer); } return(builder.ToHashCode()); }
public int GetHashCode(InputFieldMappingEntry obj) { if (obj is null) { return(0); } HashCodeBuilder builder = new HashCodeBuilder(); builder.Add(obj.Name); builder.Add(obj.Source); builder.Add(obj.SourceContext); builder.Add(obj.Inputs, SharedInputsCollection); return(builder.ToHashCode()); }
public int GetHashCode(SearchIndexerDataSourceConnection obj) { if (obj is null) { return(0); } HashCodeBuilder builder = new HashCodeBuilder(); builder.Add(obj.Name); builder.Add(obj.Type); builder.Add(obj.Description); builder.Add(obj.Container?.Name); builder.Add(obj.Container?.Query); return(builder.ToHashCode()); }
public int GetHashCode(SearchIndexerSkill obj) { if (obj is null) { return(0); } HashCodeBuilder builder = new HashCodeBuilder(); // BUGBUG: Ignore the name since 1-based automatic names are only returned in GET methods, not PUT methods. builder.Add(obj.ODataType); builder.Add(obj.Description); builder.Add(obj.Context); builder.Add(obj.Inputs, SharedInputsCollection); builder.Add(obj.Outputs, SharedOutputsCollection); return(builder.ToHashCode()); }
/// <summary> /// This method uses reflection to build a valid hash code. /// It uses AccessibleObject.setAccessible to gain access to private /// fields. This means that it will throw a security exception if run under /// a security manager, if the permissions are not set up correctly. It is also /// not as efficient as testing explicitly. /// If the TestTransients parameter is set to true, transient /// members will be tested, otherwise they are ignored, as they are likely /// derived fields, and not part of the value of the Object. /// Static fields will not be included. Superclass fields will be included /// up to and including the specified superclass. A null superclass is treated /// as java.lang.Object. /// Two randomly chosen, non-zero, odd numbers must be passed in. Ideally /// these should be different for each class, however this is not vital. /// Prime numbers are preferred, especially for the multiplier. /// Throws IllegalArgumentException if the Object is null /// Throws IllegalArgumentException if the number is zero or even since 2.0 /// </summary> /// <param name="initialNonZeroOddNumber">a non-zero, odd number used as the initial value</param> /// <param name="multiplierNonZeroOddNumber">a non-zero, odd number used as the multiplier</param> /// <param name="obj">the Object to create a hashCode for</param> /// <param name="reflectUpToClass">whether to include transient fields</param> /// <param name="testTransients">the superclass to reflect up to (inclusive),may be null</param> /// <returns>hash code</returns> public static int ReflectionHashCode( int initialNonZeroOddNumber, int multiplierNonZeroOddNumber, object obj, bool testTransients, Type reflectUpToClass) { if (obj == null) { throw new ArgumentException("The object to build a hash code for must not be null"); } var builder = new HashCodeBuilder(initialNonZeroOddNumber, multiplierNonZeroOddNumber); var clazz = obj.GetType(); reflectionAppend(obj, clazz, builder, testTransients); while (clazz.BaseType != null && clazz != reflectUpToClass) { clazz = clazz.BaseType; reflectionAppend(obj, clazz, builder, testTransients); } return(builder.ToHashCode()); }