Beispiel #1
0
        }               // read-only GUID GUIDPerType property
        #endregion      // Public Properties


        #region Overrides of Other Methods of Object
        /// <summary>
        /// This method overrides the Equal method on System.Object by
        /// evaluating the compact GUID strings if the other comparand is a
        /// BCLIntegerTypeInfo. In all other cases, this method returns FALSE.
        /// </summary>
        /// <param name="obj">
        /// Specify another BCLIntegerTypeInfo instance. A null reference or one
        /// to any other type is meaningless, and is covered by returning FALSE.
        /// </param>
        /// <returns>
        /// This method returns TRUE when both instances have identical BCLType
        /// properties. Otherwise, the return value is FALSE.
        /// </returns>
        public override bool Equals(object obj)
        {
            if (obj == null)
            {                   // The null reference is never equal to an instance!
                return(false);
            }                   // TRUE (degenerate case) block, if ( obj == null )
            else
            {                   // The next step depends on whether or not the objects are of like kind.
                if (obj.GetType( ) == this.GetType( ))
                {               // They are. Cast other to one of our kind, then call the Equals method on the compact GUID member.
                    BCLIntegerTypeInfo bclOtherIntegerTypeInfo = ( BCLIntegerTypeInfo )obj;
                    return(_typBCLType.Equals(bclOtherIntegerTypeInfo._typBCLType));
                }       // TRUE (anticipated outcome) block, if ( obj.GetType ( ) == this.GetType ( ) )
                else
                {       // Objects of different kinds are implicitly unequal.
                    return(false);
                }       // FALSE (unanticipated outcome) block, if ( obj.GetType ( ) == this.GetType ( ) )
            }           // FALSE (anticipated case) block, if ( obj == null )
        }               // public override bool Equals
Beispiel #2
0
        /// <summary>
        /// Format a bit mask; this method is intended to implement the ToString
        /// overload on the BitArray classes.
        /// </summary>
        /// <typeparam name="T">
        /// Though not enforced by the compiler, the input must be an integral
        /// type, though it is left to this method to enforce it at run time.
        /// </typeparam>
        /// <param name="pgenBitMask">
        /// Specify the bit mask to format, which must be an integral type.
        /// System.Byte is considered an integral type that stores 8 bits.
        /// </param>
        /// <param name="pstrFormatString">
        /// Specify the format string, which must be either "G" by itself, "H",
        /// or "L" followed by a positive integer less than the number of bits
        /// represented by pgenBitMask.
        /// </param>
        /// <returns>
        /// if the function succeeds, the return value is a string containing a
        /// 1 or 0 for each bit in pgenBitMask.
        /// </returns>
        /// <exception cref="ArgumentOutOfRangeException">
        /// An ArgumentOutOfRangeException exception is thrown when the bits per
        /// group suffix is less than zero.
        /// </exception>
        /// <exception cref="ArgumentException">
        /// An ArgumentException exception is thrown when the bits per group
        /// suffix is non-numeric.
        /// </exception>
        internal static string FormatBitMask <T> (
            T pgenBitMask,
            string pstrFormatString)
        {
            const string FORMAT_ITEM_PREFIX = "{0:";
            const char   FORMAT_ITEM_SUFFIX = '}';

            FormattingParameters fpFormattingParams = ParseFormatString(
                pstrFormatString);
            BCLIntegerTypeInfo bclTypeInfo = InfoForIntegralType(
                pgenBitMask.GetType( ));
            string strGeneralFormatString = string.Concat(
                HEXADECIMAL,
                (bclTypeInfo.RequiredStorageBytes * HEX_DIGITS_PER_BYTE));
            string strWorkFormat = string.Format(
                string.Concat(
                    FORMAT_ITEM_PREFIX,
                    strGeneralFormatString,
                    FORMAT_ITEM_SUFFIX),
                pgenBitMask);

            //	----------------------------------------------------------------
            //	For the General case, formatting is done, but for the Bits case,
            //	we're just getting underway.
            //	----------------------------------------------------------------

            switch (fpFormattingParams.FormatPrefix)
            {
            case FormattingParameters.FormatCode.General:
                return(strWorkFormat);

            case FormattingParameters.FormatCode.BitsHighToLow:
            case FormattingParameters.FormatCode.BitsLowToHigh:
                StringBuilder rsbOneCharPerBit = new StringBuilder(bclTypeInfo.CapacityInBits);

                foreach (char chr4Bits in strWorkFormat)
                {                               // Since it happens after the fact, the decision to append a space must precede appending more bits.
                    fpFormattingParams.AddPaddingAsSpecified(
                        rsbOneCharPerBit);
                    rsbOneCharPerBit.Append(
                        s_abytAsBits [Array.BinarySearch <char> (
                                          s_achrHexDigit,
                                          chr4Bits)]);
                }                               // foreach ( char chr4Bits in strWorkFormat )

                //	--------------------------------------------------------
                //	Since there are only two possible values at this point,
                //	the simplest implementation of the next decision is an
                //	old fashioned IF statement.
                //	--------------------------------------------------------

                if (fpFormattingParams.FormatPrefix == FormattingParameters.FormatCode.BitsHighToLow)
                {
                    return(rsbOneCharPerBit.ToString( ));
                }                               // TRUE (Use the conventional visualization.) block, if ( fpFormattingParams.FormatPrefix == FormattingParameters.FormatCode.BitsHighToLow )
                else
                {
                    return(StrReverse(rsbOneCharPerBit.ToString( )));
                }                               // FALSE (Use the alternate visualization.) block, if ( fpFormattingParams.FormatPrefix == FormattingParameters.FormatCode.BitsHighToLow )

            default:
                string strMsg = string.Format(
                    Properties.Resources.ERRMSG_INVALID_FORMAT_PREFIX_ENUM,
                    ( int )fpFormattingParams.FormatPrefix);
                System.Diagnostics.Debug.Fail(
                    strMsg);
                return(strMsg);
            }           // switch ( fpFormattingParams.FormatPrefix )
        }               // FormatBitMask