public bool PosTest3() { bool retVal = true; const string c_TEST_DESC = "PosTest3: Verify the Nullable<T> object's HasValue is false"; const string c_TEST_ID = "P003"; char?nullObj = new Nullable <char>(); TestLibrary.TestFramework.BeginScenario(c_TEST_DESC); try { if (nullObj.GetHashCode() != 0) { string errorDesc = "HashCod is not 0 as expected: Actual(" + nullObj.GetHashCode() + ")"; TestLibrary.TestFramework.LogError("005 " + "TestID_" + c_TEST_ID, errorDesc); retVal = false; } } catch (Exception e) { TestLibrary.TestFramework.LogError("006 ", "Unexpected exception: " + e); TestLibrary.TestFramework.LogInformation(e.StackTrace); retVal = false; } return(retVal); }
public bool PosTest2() { bool retVal = true; const string c_TEST_DESC = "PosTest2: Verify the Nullable<T> type is char"; const string c_TEST_ID = "P002"; char value = TestLibrary.Generator.GetChar(-55); char? nullObj = new Nullable<char>(value); int expectedValue = value.GetHashCode(); TestLibrary.TestFramework.BeginScenario(c_TEST_DESC); try { if (nullObj.GetHashCode() != expectedValue) { string errorDesc = "HashCod is not " + expectedValue + " as expected: Actual(" + nullObj.GetHashCode() + ")"; errorDesc += "\n value is " + value; TestLibrary.TestFramework.LogError("003 " + "TestID_" + c_TEST_ID, errorDesc); retVal = false; } } catch (Exception e) { TestLibrary.TestFramework.LogError("004 ", "Unexpected exception: " + e + "\n value is " + value); TestLibrary.TestFramework.LogInformation(e.StackTrace); retVal = false; } return retVal; }
public bool PosTest2() { bool retVal = true; const string c_TEST_DESC = "PosTest2: Verify the Nullable<T> type is char"; const string c_TEST_ID = "P002"; char value = TestLibrary.Generator.GetChar(-55); char?nullObj = new Nullable <char>(value); int expectedValue = value.GetHashCode(); TestLibrary.TestFramework.BeginScenario(c_TEST_DESC); try { if (nullObj.GetHashCode() != expectedValue) { string errorDesc = "HashCod is not " + expectedValue + " as expected: Actual(" + nullObj.GetHashCode() + ")"; errorDesc += "\n value is " + value; TestLibrary.TestFramework.LogError("003 " + "TestID_" + c_TEST_ID, errorDesc); retVal = false; } } catch (Exception e) { TestLibrary.TestFramework.LogError("004 ", "Unexpected exception: " + e + "\n value is " + value); TestLibrary.TestFramework.LogInformation(e.StackTrace); retVal = false; } return(retVal); }
public static void TestBasics() { // Nullable and Nullable<T> are mostly verbatim ports so we don't test much here. Nullable <int> n = default(Nullable <int>); Assert.False(n.HasValue); Assert.Throws <InvalidOperationException>(() => n.Value); Assert.Throws <InvalidOperationException>(() => (int)n); Assert.Equal(null, n); Assert.NotEqual(7, n); Assert.Equal(0, n.GetHashCode()); Assert.Equal("", n.ToString()); Assert.Equal(default(int), n.GetValueOrDefault()); Assert.Equal(999, n.GetValueOrDefault(999)); n = new Nullable <int>(42); Assert.True(n.HasValue); Assert.Equal(42, n.Value); Assert.Equal(42, (int)n); Assert.NotEqual(null, n); Assert.NotEqual(7, n); Assert.Equal(42, n); Assert.Equal(42.GetHashCode(), n.GetHashCode()); Assert.Equal(42.ToString(), n.ToString()); Assert.Equal(42, n.GetValueOrDefault()); Assert.Equal(42, n.GetValueOrDefault(999)); n = 88; Assert.True(n.HasValue); Assert.Equal(88, n.Value); }
public override int GetHashCode() { int hash = 1; if (detailsCase_ == DetailsOneofCase.ListElementType) { hash ^= ListElementType.GetHashCode(); } if (detailsCase_ == DetailsOneofCase.StructType) { hash ^= StructType.GetHashCode(); } if (detailsCase_ == DetailsOneofCase.TimeFormat) { hash ^= TimeFormat.GetHashCode(); } if (TypeCode != global::Google.Cloud.Automl.V1Beta1.TypeCode.Unspecified) { hash ^= TypeCode.GetHashCode(); } if (Nullable != false) { hash ^= Nullable.GetHashCode(); } hash ^= (int)detailsCase_; if (_unknownFields != null) { hash ^= _unknownFields.GetHashCode(); } return(hash); }
public override int GetHashCode() { var hashCode = -223084965; hashCode = hashCode * -1521134295 + Nullable.GetHashCode(); hashCode = hashCode * -1521134295 + EqualityComparer <object> .Default.GetHashCode(DefaultValue); return(hashCode); }
public override int GetHashCode() { var hashCode = -482873273; hashCode = hashCode * -1521134295 + Nullable.GetHashCode(); hashCode = hashCode * -1521134295 + EqualityComparer <DataDescriptor> .Default.GetHashCode(ItemDescriptor); return(hashCode); }
public override int GetHashCode() { var hashCode = 2064393502; hashCode = hashCode * -1521134295 + Nullable.GetHashCode(); hashCode = hashCode * -1521134295 + EqualityComparer <object> .Default.GetHashCode(DefaultValue); hashCode = hashCode * -1521134295 + EqualityComparer <DataDescriptor> .Default.GetHashCode(ItemDescriptor); return(hashCode); }
public override int GetHashCode() { unchecked { var hashCode = _numValue.GetHashCode(); if (_stringValue != null) { hashCode = (hashCode * 397) ^ _stringValue.GetHashCode(); } return(hashCode); } }
static void Display(Nullable <int> x) { Console.WriteLine("HasValue:{0}", x.HasValue); if (x.HasValue) { Console.WriteLine("Value:{0}", x.Value); Console.WriteLine("Explicit conversion:{0}", (int)x);//nullable拆箱 } Console.WriteLine("GetValueOrDefault():{0}", x.GetValueOrDefault()); Console.WriteLine("GetValueOrDefault(10):{0}", x.GetValueOrDefault(10)); Console.WriteLine("ToString():\"{0}\"", x.ToString()); Console.WriteLine("GetHashCode():{0}", x.GetHashCode()); }
static void Display(Nullable <int> x) { Console.WriteLine($"HasValue: {x.HasValue}"); if (x.HasValue) { Console.WriteLine($"Value: {x.Value}"); Console.WriteLine($"Explicit conversion: {(int)x}"); } Console.WriteLine($"GetValueOrDefault {x.GetValueOrDefault()}"); Console.WriteLine($"getValueOrDefault {x.GetValueOrDefault(10)}"); Console.WriteLine($"ToString: {x.ToString()}"); Console.WriteLine($"getHashCode: {x.GetHashCode()}"); }
public override int GetHashCode() { unchecked { var hashCode = (Name != null ? Name.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (Type != null ? Type.GetHashCode() : 0); hashCode = (hashCode * 397) ^ Length.GetHashCode(); hashCode = (hashCode * 397) ^ Nullable.GetHashCode(); hashCode = (hashCode * 397) ^ (DefaultValue != null ? DefaultValue.GetHashCode() : 0); hashCode = (hashCode * 397) ^ IsPrimaryKey.GetHashCode(); return(hashCode); } }
static void Display(Nullable <int> x) { if (x.HasValue) { Console.WriteLine("Value: {0}", x.Value); Console.WriteLine("Explicit conversion: {0}", (int)x); //显式转换 } Console.WriteLine("GetValueOrDefault(): {0}", x.GetValueOrDefault()); //无参数的 Console.WriteLine("GetValueOrDefaul(10): {0}", x.GetValueOrDefault(10)); Console.WriteLine("ToString(): \"{0}\"", x.ToString()); Console.WriteLine("GetHashCode(): {0}", x.GetHashCode()); //重载了这两个方法,使得当里面没有值的时候返回0 Console.WriteLine(); }
/// <summary> /// 转换有值和无值的可空类型 /// </summary> /// <param name="x"></param> private static void Display(Nullable <int> x) { Console.WriteLine("HasValue:{0}", x.HasValue); if (x.HasValue) { Console.WriteLine("Value:{0}", x.Value); } Console.WriteLine("GetValueOrDefault(): {0}", x.GetValueOrDefault()); //指定返回的默认值 Console.WriteLine("GetValueOrDefault(10): {0}", x.GetValueOrDefault(10)); Console.WriteLine("ToString():\"{0}\"", x.ToString()); Console.WriteLine("GetHashCode():\"{0}\"", x.GetHashCode()); Console.WriteLine("=================="); }
static void Display(Nullable<int> x) { Console.WriteLine("HasValue: {0}", x.HasValue); if (x.HasValue) { Console.WriteLine("Value: {0}", x.Value); Console.WriteLine("Explicti conversion: {0}", (int)x); } Console.WriteLine("GetValueOrdDefault(): {0}", x.GetValueOrDefault()); Console.WriteLine("GetValueOrDefaullt(10): {0}", x.GetValueOrDefault(10)); Console.WriteLine("ToString(): \"{0}\"", x.ToString()); Console.WriteLine("GetHashCode(): {0}", x.GetHashCode()); }
/// <summary> /// Returns the hash code for this instance. /// </summary> public override int GetHashCode() { if (_sKey != null) { return(_sKey.GetHashCode()); } else if (_iKey != null) { return(_iKey.GetHashCode()); } else { return(0); } }
public override int GetHashCode() { var hashCode = -657939666; hashCode = hashCode * -1521134295 + EqualityComparer <string> .Default.GetHashCode(Name); hashCode = hashCode * -1521134295 + EqualityComparer <string> .Default.GetHashCode(Type); hashCode = hashCode * -1521134295 + IsPK.GetHashCode(); hashCode = hashCode * -1521134295 + Nullable.GetHashCode(); hashCode = hashCode * -1521134295 + Size.GetHashCode(); hashCode = hashCode * -1521134295 + Precision.GetHashCode(); hashCode = hashCode * -1521134295 + EqualityComparer <string> .Default.GetHashCode(BaseType); return(hashCode); }
public override int GetHashCode() { unchecked { int result = base.GetHashCode(); result = (result * 397) ^ (Type != null ? Type.GetHashCode() : 0); result = (result * 397) ^ AutoIncrement.GetHashCode(); result = (result * 397) ^ Seed; result = (result * 397) ^ Increment; result = (result * 397) ^ Nullable.GetHashCode(); result = (result * 397) ^ Size.GetHashCode(); result = (result * 397) ^ DecimalScale; result = (result * 397) ^ DecimalPrecision; result = (result * 397) ^ (DefaultValue != null ? DefaultValue.GetHashCode() : 0); return(result); } }
public override int GetHashCode() { unchecked { var hashCode = Name != null?Name.GetHashCode() : 0; hashCode = (hashCode * 397) ^ (int)Type; hashCode = (hashCode * 397) ^ (From != null ? From.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (int)Rel; hashCode = (hashCode * 397) ^ (int)Scope; hashCode = (hashCode * 397) ^ (Default != null ? Default.GetHashCode() : 0); hashCode = (hashCode * 397) ^ Nullable.GetHashCode(); hashCode = (hashCode * 397) ^ Required.GetHashCode(); hashCode = (hashCode * 397) ^ Disabled.GetHashCode(); hashCode = (hashCode * 397) ^ Protected.GetHashCode(); hashCode = (hashCode * 397) ^ Personal.GetHashCode(); hashCode = (hashCode * 397) ^ (Annotations != null ? Annotations.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (Description != null ? Description.GetHashCode() : 0); return(hashCode); } }
/// <summary> /// Serves as a hash function for a particular type. /// </summary> /// <returns>A hash code for the current object.</returns> public override int GetHashCode() { unchecked { int result = 17; result = result * 23 + base.GetHashCode(); result = result * 23 + ((Name != null) ? Name.GetHashCode() : 0); result = result * 23 + Type.GetHashCode(); result = result * 23 + Editable.GetHashCode(); result = result * 23 + Mandatory.GetHashCode(); result = result * 23 + Hidden.GetHashCode(); result = result * 23 + Hideable.GetHashCode(); result = result * 23 + Width.GetHashCode(); result = result * 23 + ((Text != null) ? Text.GetHashCode() : 0); result = result * 23 + Xtype.GetHashCode(); result = result * 23 + Align.GetHashCode(); result = result * 23 + ((Tooltip != null) ? Tooltip.GetHashCode() : 0); result = result * 23 + Sortable.GetHashCode(); result = result * 23 + SortDirection.GetHashCode(); result = result * 23 + ((Format != null) ? Format.GetHashCode() : 0); result = result * 23 + DecimalPlaces.GetHashCode(); result = result * 23 + ((DataUrl != null) ? DataUrl.GetHashCode() : 0); result = result * 23 + ((DefaultValue != null) ? DefaultValue.GetHashCode() : 0); result = result * 23 + ((Description != null) ? Description.GetHashCode() : 0); result = result * 23 + Rank.GetHashCode(); result = result * 23 + ReadOnly.GetHashCode(); result = result * 23 + MaxLength.GetHashCode(); result = result * 23 + ((Validator != null) ? Validator.GetHashCode() : 0); result = result * 23 + ((SearchFieldDefinition != null) ? SearchFieldDefinition.GetHashCode() : 0); result = result * 23 + SingleComboFilter.GetHashCode(); result = result * 23 + AllowComboCustomValue.GetHashCode(); result = result * 23 + SearchComboFromLeft.GetHashCode(); result = result * 23 + LoadWhenVisible.GetHashCode(); result = result * 23 + Nullable.GetHashCode(); result = result * 23 + ((Tpl != null) ? Tpl.GetHashCode() : 0); result = result * 23 + MinCharSearch.GetHashCode(); result = result * 23 + ((AdditionalWhereSqlTemp != null) ? AdditionalWhereSqlTemp.GetHashCode() : 0); return(result); } }
public override int GetHashCode() { int hashcode = 157; unchecked { if (isset.type) { hashcode = (hashcode * 397) + Type.GetHashCode(); } if (isset.encoding) { hashcode = (hashcode * 397) + Encoding.GetHashCode(); } if (isset.nullable) { hashcode = (hashcode * 397) + Nullable.GetHashCode(); } if (isset.is_array) { hashcode = (hashcode * 397) + Is_array.GetHashCode(); } if (isset.precision) { hashcode = (hashcode * 397) + Precision.GetHashCode(); } if (isset.scale) { hashcode = (hashcode * 397) + Scale.GetHashCode(); } if (isset.comp_param) { hashcode = (hashcode * 397) + Comp_param.GetHashCode(); } if (isset.size) { hashcode = (hashcode * 397) + Size.GetHashCode(); } } return(hashcode); }
public static void TestBasics() { // Nullable and Nullable<T> are mostly verbatim ports so we don't test much here. Nullable <int> n = default(Nullable <int>); bool b; int v; int h; String s; int i; b = n.HasValue; Assert.False(b); try { v = n.Value; Assert.True(false, "Nullable<>.Value should have thrown."); } catch (InvalidOperationException) { } try { i = (int)n; Assert.True(false, "Nullable<>.Value should have thrown."); } catch (InvalidOperationException) { } b = n.Equals(null); Assert.True(b); b = n.Equals(7); Assert.False(b); h = n.GetHashCode(); Assert.Equal(h, 0); s = n.ToString(); Assert.Equal(s, ""); v = n.GetValueOrDefault(); Assert.Equal(v, default(int)); v = n.GetValueOrDefault(999); Assert.Equal(v, 999); n = new Nullable <int>(42); b = n.HasValue; Assert.True(b); v = n.Value; Assert.Equal(v, 42); i = (int)n; Assert.Equal(i, 42); b = n.Equals(null); Assert.False(b); b = n.Equals(7); Assert.False(b); b = n.Equals(42); Assert.True(b); h = n.GetHashCode(); Assert.Equal(h, 42.GetHashCode()); s = n.ToString(); Assert.Equal(s, 42.ToString()); v = n.GetValueOrDefault(); Assert.Equal(v, 42); v = n.GetValueOrDefault(999); Assert.Equal(v, 42); n = 88; b = n.HasValue; Assert.True(b); v = n.Value; Assert.Equal(v, 88); }
public override int GetHashCode(Nullable <T> obj) { return(obj.GetHashCode()); }
public bool PosTest3() { bool retVal = true; const string c_TEST_DESC = "PosTest3: Verify the Nullable<T> object's HasValue is false"; const string c_TEST_ID = "P003"; char? nullObj = new Nullable<char>(); TestLibrary.TestFramework.BeginScenario(c_TEST_DESC); try { if (nullObj.GetHashCode() != 0) { string errorDesc = "HashCod is not 0 as expected: Actual(" + nullObj.GetHashCode() + ")"; TestLibrary.TestFramework.LogError("005 " + "TestID_" + c_TEST_ID, errorDesc); retVal = false; } } catch (Exception e) { TestLibrary.TestFramework.LogError("006 ", "Unexpected exception: " + e ); TestLibrary.TestFramework.LogInformation(e.StackTrace); retVal = false; } return retVal; }