Example #1
0
        /// <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 UnionShort))
            {
                return(false);
            }
            UnionShort a = (UnionShort)obj;

            return(S0 == a.S0);
        }
Example #2
0
        /// <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();
        }