Exemple #1
0
        }   //  Constructor to fully initialize the object (3 of 3)


        /// <summary>
        /// This method implements IComparable for TestItemSortByString objects.
        /// </summary>
        /// <param name="pComparand">
        /// The other TestItemSortByString against which to compare this one.
        /// </param>
        /// <returns>
        /// The return value is specified in the IComparable interface, as it is
        /// implemented by the string class, which carries it out on behalf of
        /// objects of this class.
        /// </returns>
        public int CompareTo ( object pComparand )
        {
            if ( pComparand.GetType ( ) == this.GetType ( ) )
            {
                TestItemSortByString tiComparand = ( TestItemSortByString ) pComparand;
                return _lngKey.CompareTo ( tiComparand.Key );
            }   // TRUE (normal) block, if ( pComparand.GetType ( ) == this.GetType ( ) )
            else
            {
                throw new ArgumentException ( Properties.Resources.IDS_COMPARETO_MISMATCH );
            }   // FALSE (exception) block, if ( pComparand.GetType ( ) == this.GetType ( ) )
        }   // public int CompareTo (implements IComparable)
        }   //private string [ ] LoadInputList


        private static TestItemSortByString [ ] LoadList ( string [ ] pastrInputList )
        {
			const long KEY_FIELD = ArrayInfo.ARRAY_FIRST_ELEMENT;
			const long VALUE_FIELD = KEY_FIELD + ArrayInfo.NEXT_INDEX;
			const long EXPECTED_FIELD_COUNT = VALUE_FIELD + ArrayInfo.NEXT_INDEX;

            // On entry, pastrMasterFile is known to be populated.
            long lngLastItem = pastrInputList.LongLength + ArrayInfo.INDEX_FROM_ORDINAL;
			long lngKey = KEY_FIELD;

			//	----------------------------------------------------------------
			//	Since the label row is separated from the data, the array that
			//	stores the data needs one fewer elements than are in the input
			//	array. Moreover, the code in the ELSE block of the outermost of
			//	the IF blocks within the following FOR loop must adjust the
			//	subscript into which it inserts each element down by one, to
			//	account for the discarded label.
			//	----------------------------------------------------------------

			TestItemSortByString [ ] ratiItems = new TestItemSortByString [ lngLastItem ];
            
            for ( long lngCurrentItem = ArrayInfo.ARRAY_FIRST_ELEMENT ;
                       lngCurrentItem <= lngLastItem ;
                       lngCurrentItem++ )
            {
                string [ ] astrFields = pastrInputList [ lngCurrentItem ].Split ( new char [ ] { SpecialCharacters.TAB_CHAR } );

                if ( lngCurrentItem == ArrayInfo.ARRAY_FIRST_ELEMENT )
                {   // The first element contains labels.
                    if ( s_Labels == null )
                    {   // Save to compare against the next list.
                        if ( astrFields.Length == EXPECTED_FIELD_COUNT )
                        {   // Label appears to be OK.
                            s_Labels = pastrInputList [ lngCurrentItem ];
                        }   // TRUE (normal) block, if ( astrTest.Length == EXPECTED_FIELD_COUNT )
                        else
                        {   // Compose a message and throw an exception.
                            string strMsg = string.Format (
                                Properties.Resources.IDS_BAD_MASTER_LABEL_ROW ,
                                new object [ ]
                                {
                                    EXPECTED_FIELD_COUNT ,
                                    astrFields.Length ,
                                    pastrInputList [ lngCurrentItem ] ,
                                    Environment.NewLine
                                } );
                            throw new Exception ( strMsg );
                        }   // FALSE (exception) block, if ( astrTest.Length == EXPECTED_FIELD_COUNT )
                    }   // TRUE (first time) block, if ( s_Labels == null )
                    else
                    {   // Both must match, or we die.
                        if ( pastrInputList [ lngCurrentItem ] != s_Labels )
                        {   // Compose a message and throw an exception.
                            string strMsg = string.Format (
                                Properties.Resources.IDS_INCONSISTENT_INPUTS ,
                                s_Labels ,
                                pastrInputList [ lngCurrentItem ] ,
                                Environment.NewLine );
                            throw new Exception ( strMsg );
                        }   // if ( pastrInputList [ lngCurrentItem ] != s_Labels )
                    }   // FALSE (subsequent calls) block, if ( s_Labels == null )
                }   // TRUE (one-off) block, if ( lngCurrentItem == ArrayInfo.ARRAY_FIRST_ELEMENT )
                else
                {
                    if ( long.TryParse ( astrFields [ KEY_FIELD ] , out lngKey ) )
                    {
						ratiItems [ lngCurrentItem + ArrayInfo.INDEX_FROM_ORDINAL ] = new TestItemSortByString (
                            lngKey ,
                            astrFields [ VALUE_FIELD ] );
                    }   // TRUE (normal) block, if ( long.TryParse ( astrFields [ KEY_FIELD ] , out lngKey ) )
                    else
                    {
                        string strMsg = string.Format (
                            Properties.Resources.IDS_INVALID_KEY ,
                            astrFields [ KEY_FIELD ] ,
                            pastrInputList [ lngCurrentItem ] );
                        throw new Exception ( strMsg );
                    }   // FALSE (exception) block, if ( long.TryParse ( astrFields [ KEY_FIELD ] , out lngKey ) )
                }   // FALSE block, if ( lngCurrentItem == ArrayInfo.ARRAY_FIRST_ELEMENT )
            }   // for ( long lngCurrentItem = ArrayInfo.ARRAY_FIRST_ELEMENT ; lngCurrentItem <= lngLastItem ; lngCurrentItem++ )

            return ratiItems;
        }   // private static TestItemSortByString [ ] LoadList