/// <summary>根据所提供的格式方式,返回此 CombGuid 实例值的字符串表示形式,如果此 CombGuid 结构值为空,则返回表示空值的字符串。</summary> /// <param name="formatType">格式化方式,它指示如何格式化此 CombGuid 的值。</param> /// <returns>此 CombGuid 的值,用一系列指定格式的小写十六进制位表示</returns> public String ToString(CombGuidFormatStringType formatType) { //if (IsNull) { return _NullString; } if (IsNull) { return(Empty.ToString(formatType)); } var guidChars = GetChars(formatType); return(new String(guidChars)); }
/// <summary>根据所提供的格式方式,返回此 CombGuid 实例值的字符数组,如果此 CombGuid 结构值为空,抛出异常。</summary> /// <param name="formatType">格式化方式,它指示如何格式化此 CombGuid 的值。</param> /// <returns>此 CombGuid 的字符数组,包含一系列指定格式的小写十六进制位字符</returns> public Char[] GetChars(CombGuidFormatStringType formatType) { //if (IsNull) { throw new HmExceptionBase("此 CombGuid 结构字节数组为空!"); } if (IsNull) { return(Empty.GetChars(formatType)); } var offset = 0; var strLength = 36; var dash = true; if (formatType == CombGuidFormatStringType.Guid32Digits || formatType == CombGuidFormatStringType.Comb32Digits) { strLength = 32; dash = false; } var guidChars = new Char[strLength]; var isComb = formatType == CombGuidFormatStringType.Comb || formatType == CombGuidFormatStringType.Comb32Digits; #region MS GUID类内部代码 //g[0] = (Byte)(_a); //g[1] = (Byte)(_a >> 8); //g[2] = (Byte)(_a >> 16); //g[3] = (Byte)(_a >> 24); //g[4] = (Byte)(_b); //g[5] = (Byte)(_b >> 8); //g[6] = (Byte)(_c); //g[7] = (Byte)(_c >> 8); //g[8] = _d; //g[9] = _e; //g[10] = _f; //g[11] = _g; //g[12] = _h; //g[13] = _i; //g[14] = _j; //g[15] = _k; //// [{|(]dddddddd[-]dddd[-]dddd[-]dddd[-]dddddddddddd[}|)] //offset = HexsToChars(guidChars, offset, _a >> 24, _a >> 16); //offset = HexsToChars(guidChars, offset, _a >> 8, _a); //if (dash) guidChars[offset++] = '-'; //offset = HexsToChars(guidChars, offset, _b >> 8, _b); //if (dash) guidChars[offset++] = '-'; //offset = HexsToChars(guidChars, offset, _c >> 8, _c); //if (dash) guidChars[offset++] = '-'; //offset = HexsToChars(guidChars, offset, _d, _e); //if (dash) guidChars[offset++] = '-'; //offset = HexsToChars(guidChars, offset, _f, _g); //offset = HexsToChars(guidChars, offset, _h, _i); //offset = HexsToChars(guidChars, offset, _j, _k); #endregion if (isComb) { offset = HexsToChars(guidChars, offset, m_value[10], m_value[11]); offset = HexsToChars(guidChars, offset, m_value[12], m_value[13]); offset = HexsToChars(guidChars, offset, m_value[14], m_value[15]); if (dash) { guidChars[offset++] = '-'; } offset = HexsToChars(guidChars, offset, m_value[8], m_value[9]); if (dash) { guidChars[offset++] = '-'; } offset = HexsToChars(guidChars, offset, m_value[6], m_value[7]); if (dash) { guidChars[offset++] = '-'; } offset = HexsToChars(guidChars, offset, m_value[4], m_value[5]); if (dash) { guidChars[offset++] = '-'; } offset = HexsToChars(guidChars, offset, m_value[0], m_value[1]); offset = HexsToChars(guidChars, offset, m_value[2], m_value[3]); } else { offset = HexsToChars(guidChars, offset, m_value[3], m_value[2]); offset = HexsToChars(guidChars, offset, m_value[1], m_value[0]); if (dash) { guidChars[offset++] = '-'; } offset = HexsToChars(guidChars, offset, m_value[5], m_value[4]); if (dash) { guidChars[offset++] = '-'; } offset = HexsToChars(guidChars, offset, m_value[7], m_value[6]); if (dash) { guidChars[offset++] = '-'; } offset = HexsToChars(guidChars, offset, m_value[8], m_value[9]); if (dash) { guidChars[offset++] = '-'; } offset = HexsToChars(guidChars, offset, m_value[10], m_value[11]); offset = HexsToChars(guidChars, offset, m_value[12], m_value[13]); offset = HexsToChars(guidChars, offset, m_value[14], m_value[15]); } return(guidChars); }