/// <summary> /// Determines whether the specified object is equal to the current object (确定指定的对象是否等于当前对象). /// </summary> /// <param name="obj">The object to compare with the current object.</param> /// <returns>true if the specified object is equal to the current object; otherwise, false.</returns> public override bool Equals(object obj) { if (null == obj) { return(false); } if (!(obj is UnionInt)) { return(false); } UnionInt a = (UnionInt)obj; return(I0 == a.I0); }
/// <summary> /// Test UnionInt . /// </summary> /// <param name="sb">String buffer.</param> public static void TestInt(StringBuilder sb) { sb.AppendLine("[TestInt]"); // ctor. UnionInt v = new UnionInt((float)-Math.PI); sb.AppendLine(string.Format("F: {0}", v.F0)); sb.AppendLine(string.Format("I: {0} // HEX {0:X8}", v.I0)); sb.AppendLine(string.Format("UI: {0} // HEX {0:X8}", v.UI0)); sb.AppendLine(string.Format("S: {0}, {1} // HEX {0:X4} {1:X4}", v.S0, v.S1)); sb.AppendLine(string.Format("B(HEX): {0:X2} {1:X2} {2:X2} {3:X2}", v.B0, v.B1, v.B2, v.B3)); sb.AppendLine(string.Format("Equals(null): {0}", v.Equals(null))); sb.AppendLine(string.Format("GetHashCode: {0}", v.GetHashCode())); sb.AppendLine(string.Format("ToString: {0}", v.ToString())); sb.AppendLine(StrByArray("ToByteArray", v.ToByteArray())); sb.AppendLine(StrByArray("ToInt16Array", v.ToInt16Array())); sb.AppendLine(StrByArray("ToUInt32Array", v.ToUInt32Array())); sb.AppendLine(StrByArray("ToInt32Array", v.ToInt32Array())); sb.AppendLine(StrByArray("ToSingleArray", v.ToSingleArray())); // XmlSerializer XmlSerializer serializer = new XmlSerializer(v.GetType()); using (StringWriter sw = new StringWriter(sb)) { serializer.Serialize(sw, v); } sb.AppendLine(); // DataContractJsonSerializer . #if (NET20 || NET30) #else string jsonstr = DataContractJson(v); sb.AppendLine(string.Format("DataContractJson: {0}", jsonstr)); if (!string.IsNullOrEmpty(jsonstr)) { UnionLong v2 = DataContractJsonDeserialize <UnionLong>(jsonstr); sb.AppendLine(StrByArray("DataContractJsonDeserialize", v2.ToByteArray())); } #endif // done. sb.AppendLine(); }