/// <summary> /// Test UnionLong . /// </summary> /// <param name="sb">String buffer.</param> public static void TestLong(StringBuilder sb) { sb.AppendLine("[TestLong]"); // ctor. UnionLong v = new UnionLong(-Math.PI); sb.AppendLine(string.Format("D: {0}", v.D0)); sb.AppendLine(string.Format("L: {0} // HEX {0:X16}", v.L0)); sb.AppendLine(string.Format("UL: {0} // HEX {0:X16}", v.UL0)); sb.AppendLine(string.Format("F: {0}, {1}", v.F0, v.F1)); sb.AppendLine(string.Format("I: {0}, {1} // HEX {0:X8} {1:X8}", v.I0, v.I1)); sb.AppendLine(string.Format("S: {0}, {1}, {2}, {3} // HEX {0:X4} {1:X4} {2:X4} {3:X4}", v.S0, v.S1, v.S2, v.S3)); sb.AppendLine(string.Format("B(HEX): {0:X2} {1:X2} {2:X2} {3:X2} {4:X2} {5:X2} {6:X2} {7:X2}", v.B0, v.B1, v.B2, v.B3, v.B4, v.B5, v.B6, v.B7)); 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("ToInt32Array", v.ToInt32Array())); sb.AppendLine(StrByArray("ToSingleArray", v.ToSingleArray())); sb.AppendLine(StrByArray("ToUInt64Array", v.ToUInt64Array())); sb.AppendLine(StrByArray("ToInt64Array", v.ToInt64Array())); sb.AppendLine(StrByArray("ToDoubleArray", v.ToDoubleArray())); // LoadBytes. if (true) { v.LoadBytesAt(5, 0, 2, (byte)0x55, (byte)0xAA); short[] buf = new short[2]; v.SaveBytesAt(4, 0, 4, buf); sb.AppendLine(string.Format("LoadBytesAt D: {0}", v.D0)); sb.AppendLine(string.Format("LoadBytesAt L: {0} // HEX {0:X16}", v.L0)); sb.AppendLine(string.Format("LoadBytesAt B(HEX): {0:X2} {1:X2} {2:X2} {3:X2} {4:X2} {5:X2} {6:X2} {7:X2}", v.B0, v.B1, v.B2, v.B3, v.B4, v.B5, v.B6, v.B7)); sb.AppendLine(StrByArray("SaveBytesAt", buf)); } // 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(); }
/// <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 UnionLong)) { return(false); } UnionLong a = (UnionLong)obj; return(L0 == a.L0); }
/// <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(); }
/// <summary> /// Test UnionShort . /// </summary> /// <param name="sb">String buffer.</param> public static void TestShort(StringBuilder sb) { sb.AppendLine("[TestShort]"); // ctor. UnionShort v = new UnionShort(0x8765); sb.AppendLine(string.Format("S: {0} // HEX {0:X4}", v.S0)); sb.AppendLine(string.Format("US: {0} // HEX {0:X4}", v.US0)); sb.AppendLine(string.Format("B(HEX): {0:X2} {1:X2}", v.B0, v.B1)); 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("ToSByteArray", v.ToSByteArray())); sb.AppendLine(StrByArray("ToByteArray", v.ToByteArray())); sb.AppendLine(StrByArray("ToUInt16Array", v.ToUInt16Array())); sb.AppendLine(StrByArray("ToInt16Array", v.ToInt16Array())); // 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(); }