コード例 #1
0
        /*
         * Using different matching data types as our collection to determine if there is a match.
         * Convert a set of examples all true then all false using different DataTypes as the collection of trueValues
         */
        public static void setThenConvert_2_Steps()
        {
            p("\n-=-=-=-=-=-=-=-=-\nDataType_Class > Boolean_Extended_Syntax > setThenConvert_2_Steps");

            /*
             * UnitOf.DataType, "12.5" for this entire example.
             */
            UnitOf.DataType numberMatches = new UnitOf.DataType("12.5");//String passed in.

            /*
             * Returns true for all
             */
            bool t_MatchStr_NonCase_Equals   = numberMatches.ToBoolean(new string[] { "1.2", "12.5", "3" });    //True, matches "12.5"
            bool t_MatchFloat_NonCase_Equals = numberMatches.ToBoolean(new object[] { 1.2f, 12.5f, 3f });       //True, matches 12.5
            bool t_MatchStr_NonCase_Contains = numberMatches.ToBoolean(new object[] { 5, 12, 3 }, false, true); //True, matches 5 & 12

            /*
             * Returns false for all
             */
            bool f_MatchStr_NonCase_Equals2   = numberMatches.ToBoolean(new string[] { "1.2", "12.55", "3" });      //False, No matches
            bool f_MatchFloat_NonCase_Equals2 = numberMatches.ToBoolean(new object[] { 1.2f, 12.55f, 3f });         //False, No matches
            bool f_MatchStr_NonCase_Contains2 = numberMatches.ToBoolean(new object[] { 5, 12, 3 }, false, false);   //False, No matches

            /*
             * Print results
             */
            pt("t_MatchStr_NonCase_Equals: " + t_MatchStr_NonCase_Equals);          //True, matches "12.5"
            pt("t_MatchFloat_NonCase_Equals: " + t_MatchFloat_NonCase_Equals);      //True, matches 12.5
            pt("t_MatchStr_NonCase_Contains: " + t_MatchStr_NonCase_Contains);      //True, matches 5 & 12
            pt("f_MatchStr_NonCase_Equals2: " + f_MatchStr_NonCase_Equals2);        //False, No matches
            pt("f_MatchFloat_NonCase_Equals2: " + f_MatchFloat_NonCase_Equals2);    //False, No matches
            pt("f_MatchStr_NonCase_Contains2: " + f_MatchStr_NonCase_Contains2);    //False, No matches
        }
コード例 #2
0
        public static void run()
        {
            p("\n-=-=-=-=-=-=-=-=-\nDataType_Class > Fraction_Extended_Syntax");

            /*
             * Simply the following existing fractions.
             */
            string fracToSimplify2o4         = new UnitOf.DataType("2/4").ToFraction();                             //Returns "1/2"
            string fracToSimplify4o2         = new UnitOf.DataType("4/2").ToFraction();                             //Returns "2" or "2/1"
            string fracToSimplify2o5         = new UnitOf.DataType("2/5").ToFraction();                             //Returns "2/5", cant get any simpler
            string fracToSimplify_default1o2 = new UnitOf.DataType("Will error, return default").ToFraction("1/2"); //Cannot create a fraction from this, default "1/2" is returned

            /*
             * Decimal to fraction
             * Convert whole numbers, decimals, and numbers in strings to fraction equivalent.
             */
            string numToFrac_dot5       = new UnitOf.DataType(.5).ToFraction();   //Returns "1/2"
            string numToFrac_dot75      = new UnitOf.DataType(.75).ToFraction();  //Returns "3/4"
            string numToFrac_2          = new UnitOf.DataType(2).ToFraction();    //Returns "2" or "2/1"
            string strNumToFrac_strNeg2 = new UnitOf.DataType("-2").ToFraction(); //Returns "-2" or "-2/1"

            /*
             * Fraction to Decimal
             * Convert the following fractions to their decimal (double) equivalent.
             */
            double fracToDecimal_2o4 = new UnitOf.DataType("2/4").ToDouble();   //Returns 0.5
            double fracToDecimal_1o2 = new UnitOf.DataType("1/2").ToDouble();   //Returns 0.5
            double fracToDecimal_4o2 = new UnitOf.DataType("4/2").ToDouble();   //Returns 2

            /*
             * Print results
             */
            pt("fracToSimplify2o4: " + fracToSimplify2o4);                 //Returns "1/2"
            pt("fracToSimplify4o2: " + fracToSimplify4o2);                 //Returns "2" or "2/1"
            pt("fracToSimplify2o5: " + fracToSimplify2o5);                 //Returns "2/5", cant get any simpler
            pt("fracToSimplify_default1o2: " + fracToSimplify_default1o2); //Cannot create a fraction from this, default "1/2" is returned
            pt("numToFrac_dot5: " + numToFrac_dot5);                       //Returns "1/2"
            pt("numToFrac_dot75: " + numToFrac_dot75);                     //Returns "3/4"
            pt("numToFrac_2: " + numToFrac_2);                             //Returns "2" or "2/1"
            pt("strNumToFrac_2: " + strNumToFrac_strNeg2);                 //Returns "-2" or "-2/1"
            pt("fracToDecimal_2o4: " + fracToDecimal_2o4);                 //Returns 0.5
            pt("fracToDecimal_1o2: " + fracToDecimal_1o2);                 //Returns 0.5
            pt("fracToDecimal_4o2: " + fracToDecimal_4o2);                 //Returns 2
        }
コード例 #3
0
        public static void run()
        {
            //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

            /*
             * Our intial value of "12.5" as type String is passed into our new instance of UnitOf.DataType.
             * UnitOf.DataType determines the type passed in making it unnecessary for the user to have to manually define this.
             * Below are also just a few examples of what can be passed in
             */
            p("\n-=-=-=-=-=-=-=-=-\nDataType_Class > Basic_2_Step_Conversions");
            p("-=-=-=-=-\nInstantiating UnitOf.DataType(\"12.5\")");
            UnitOf.DataType uoDataType = new UnitOf.DataType("12.5");   //String passed in.
            //dt = new UnitOf.DataType(12.5);                           //Example of double passed in.
            //dt = new UnitOf.DataType(12);                             //Example of int passed in.
            //dt = new UnitOf.DataType('$');                            //Example of char pssed in.
            //dt = new UnitOf.DataType(false);                          //Example of boolean passed in.
            //dt = new UnitOf.DataType("12.5");                         //Back to our example, 12.5 in string form
            //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

            /*
             * getTypeConstantPassed() and getValuePassed() return the variable type and value passed in respectively.
             * Because we passed in "12.5" as a String, the getTypeConstantPassed() will return the word "String".
             * getValuePassed() will return "12.5" as a string since that is how it was passed in.
             */
            string dataTypePassedType  = uoDataType.GetTypeConstantPassed(); //The word "String" is returned
            object dataTypePassedValue = uoDataType.GetValuePassed();        //"12.5" as a String is returned


            /*
             * Returns an double equivalent of what was passed in as the DataType value, "12.5".
             * If the conversion fails, The user defined parameter passed is returned.
             * Otherwise if nothing is passed in the UnitOf.ToDouble() default value of 0.0d is returned.
             */
            double doubleDefault0      = uoDataType.ToDouble();     //Returns 12.5 from "12.5", If the conversion did fail, the UnitOf.ToDouble() default value of 0.0d is returned.
            double doubleDefault1dot23 = uoDataType.ToDouble(1.23); //Returns 12.5 If the conversion did fail, 1.23 would be returned.


            /*
             * Returns an int equivalent (ending decimal values will be dropped) of what was passed in as the DataType value, "12.5".
             * If the conversion fails, The user defined parameter passed is returned.
             * Otherwise if nothing is passed in the UnitOf.ToInt() default value of 0 is returned.
             */
            int intDefault0     = uoDataType.ToInt();       //Returns 12 as "12.5" passed in is a non-decimal type so the ".5" is dropped, If the conversion did fail, the UnitOf.ToInt() default value of 0 is returned.
            int intDefaultNeg25 = uoDataType.ToInt(-25);    //Returns 12 If the conversion did fail, -25 would be returned.


            /*
             * Returns a String equivalent of what was passed in as the DataType value, "12.5".
             * If the conversion fails, The user defined parameter passed is returned.
             * Otherwise if nothing is passed in the UnitOf.ToString() default value of "" is returned.
             */
            string stringDefaultEmptyStr  = uoDataType.ToString();          //String equivalent of "12.5" is returned, If the conversion did fail, the UnitOf.ToString() default value of null is returned.
            string stringDefault1dot23Str = uoDataType.ToString("1.23");    //Returns "12.5" If the conversion did fail, "1.23" would be returned.


            /*
             * Returns a boolean equivalent of what was passed in as the DataType value, "12.5".
             * If the conversion fails, The user defined parameter passed is returned.
             * Otherwise if nothing is passed in the UnitOf.ToBoolean() default value of false is returned.
             * NOTE: More in its own extended class - examples/DataType_Class/Boolean_Extended_Syntax.cs
             */

            bool booleanDefaultFalse = uoDataType.ToBoolean();       //Conversion fails: false is returned. No default was passed in so the UnitOf.ToBoolean() default of false is returned.
            bool booleanDefaultTrue  = uoDataType.ToBoolean(true);   //Conversion fails: true is returned. Default of true was passed in so it is returned


            /*
             * Returns a String fraction equivalent of what was passed in as the DataType value, "12.5".
             * If the conversion fails, The user defined parameter passed is returned.
             * Otherwise if nothing is passed in the UnitOf.ToFraction() default value of "" is returned.
             */
            string fractionDefaultEmpty   = uoDataType.ToFraction();        //Returns "25/2" passed in as 25 divided by 2 equals the DataType value passed in, 12.5. If the conversion did fail, the UnitOf.ToFraction() default value of "" is returned.
            string fractionDefault2Slash5 = uoDataType.ToFraction("2/5");   //Returns "25/2" If the conversion did fail, "2/5" would be returned.


            /*
             * Returns an Object equivalent of what was passed in as the DataType value, "12.5".
             * If the conversion fails, The user defined parameter passed is returned.
             * Otherwise if nothing is passed in the UnitOf.ToObject() default value of null is returned.
             */
            object objectDefaultNull      = uoDataType.ToObject();          //Object equivalent of "12.5" is returned, If the conversion fails, the UnitOf.ToObject() default value of null is returned.
            object objectDefault123       = uoDataType.ToObject(123);       //Returns "12.5" If the conversion did fail, 123 as an Object would be returned.
            object objectDefault1dot23    = uoDataType.ToObject(1.23);      //Returns "12.5" If the conversion did fail, 1.23 as an Object would be returned.
            object objectDefault12dot3Str = uoDataType.ToObject("12.3");    //Returns "12.5" If the conversion did fail, "12.3" as an Object would be returned.


            /*
             * Returns a char equivalent by taking the first non-spaced character of what was passed in as the DataType value, "12.5".
             * If the conversion fails, The user defined parameter passed is returned.
             * Otherwise if nothing is passed in the UnitOf.ToChar() default value of '\0' is returned.
             */
            char charDefaultCharNul = uoDataType.ToChar();      //Returns '1' as it is the first non-spaced character of "12.5" passed in , If the conversion did fail, the UnitOf.ToChar() default value of '\0' is returned.
            char charDefaultAtSign  = uoDataType.ToChar('@');   //Returns '1' If the conversion did fail, '@' would be returned.


            /*
             * Returns an float equivalent of what was passed in as the DataType value, "12.5".
             * If the conversion fails, The user defined parameter passed is returned.
             * Otherwise if nothing is passed in the UnitOf.ToFloat() default value of 0.0f is returned.
             */
            float floatDefault0       = uoDataType.ToFloat();       //Returns 12.5 from "12.5", If the conversion did fail, the UnitOf.ToFloat() default value of 0.0f is returned.
            float floatDefault1dot23f = uoDataType.ToFloat(1.23f);  //Returns 12.5 If the conversion did fail, 1.23f would be returned.


            /*
             * Returns an long equivalent (ending decimal values will be dropped) of what was passed in as the DataType value, "12.5".
             * If the conversion fails, The user defined parameter passed is returned.
             * Otherwise if nothing is passed in the UnitOf.ToLong() default value of (long)0 is returned.
             */
            long longDefault0  = uoDataType.ToLong();   //Returns 12 as "12.5" passed in is a non-decimal type so the ".5" is dropped, If the conversion did fail, the UnitOf.ToLong() default value of (long)0 is returned.
            long longDefault25 = uoDataType.ToLong(25); //Returns 12 If the conversion did fail, 25 would be returned.


            /*
             * Returns a short equivalent (ending decimal values will be dropped) of what was passed in as the DataType value, "12.5".
             * If the conversion fails, The user defined parameter passed is returned.
             * Otherwise if nothing is passed in the UnitOf.ToShort() default value of (short)0 is returned.
             */
            short shortDefault0  = uoDataType.ToShort();            //Returns 12 as "12.5" passed in is a non-decimal type so the ".5" is dropped, If the conversion did fail, the UnitOf.ToShort() default value of (short)0 is returned.
            short shortDefault15 = uoDataType.ToShort((short)15);   //Returns 12 If the conversion did fail, (short)15 would be returned.


            /*
             * Returns a byte equivalent (ending decimal values will be dropped) of what was passed in as the DataType value, "12.5".
             * If the conversion fails, The user defined parameter passed is returned.
             * Otherwise if nothing is passed in the UnitOf.ToByte() default value of (byte)0 is returned.
             */
            byte byteDefault0 = uoDataType.ToByte();        //Returns 12 as "12.5" passed in is a non-decimal type so the ".5" is dropped, If the conversion did fail, the UnitOf.ToByte() default value of (byte)0 is returned.
            byte byteDefault5 = uoDataType.ToByte((byte)5); //Returns 12 If the conversion did fail, (byte)5 would be returned.


            /*
             * Returns an sbyte equivalent (ending decimal values will be dropped) of what was passed in as the DataType value, "12.5".
             * If the conversion fails, The user defined parameter passed is returned.
             * Otherwise if nothing is passed in the UnitOf.ToSbyte() default value of (sbyte)0 is returned.
             */
            sbyte sbyteDefault0 = uoDataType.ToSbyte();         //Returns 12 as "12.5" passed in is a non-decimal type so the ".5" is dropped, If the conversion did fail, the UnitOf.ToSbyte() default value of (sbyte)0 is returned.
            sbyte sbyteDefault6 = uoDataType.ToSbyte((sbyte)6); //Returns 12 If the conversion did fail, (sbyte)6 would be returned.


            /*
             * Returns a uint equivalent (ending decimal values will be dropped) of what was passed in as the DataType value, "12.5".
             * If the conversion fails, The user defined parameter passed is returned.
             * Otherwise if nothing is passed in the UnitOf.ToUint() default value of (uint)0 is returned.
             */
            uint uintDefault0 = uoDataType.ToUint();        //Returns 12 as "12.5" passed in is a non-decimal type so the ".5" is dropped, If the conversion did fail, the UnitOf.ToUint() default value of (uint)0 is returned.
            uint uintDefault7 = uoDataType.ToUint((uint)7); //Returns 12 If the conversion did fail, (uint)7 would be returned.


            /*
             * Returns a ulong equivalent (ending decimal values will be dropped) of what was passed in as the DataType value, "12.5".
             * If the conversion fails, The user defined parameter passed is returned.
             * Otherwise if nothing is passed in the UnitOf.ToUlong() default value of (ulong)0 is returned.
             */
            ulong ulongDefault0 = uoDataType.ToUlong();         //Returns 12 as "12.5" passed in is a non-decimal type so the ".5" is dropped, If the conversion did fail, the UnitOf.ToUlong() default value of (ulong)0 is returned.
            ulong ulongDefault8 = uoDataType.ToUlong((ulong)8); //Returns 12 If the conversion did fail, (ulong)8 would be returned.


            /*
             * Returns a ushort equivalent (ending decimal values will be dropped) of what was passed in as the DataType value, "12.5".
             * If the conversion fails, The user defined parameter passed is returned.
             * Otherwise if nothing is passed in the UnitOf.ToUshort() default value of (ushort)0 is returned.
             */
            ushort ushortDefault0 = uoDataType.ToUshort();          //Returns 12 as "12.5" passed in is a non-decimal type so the ".5" is dropped, If the conversion did fail, the UnitOf.ToUshort() default value of (ushort)0 is returned.
            ushort ushortDefault9 = uoDataType.ToUshort((ushort)9); //Returns 12 If the conversion did fail, (ushort)9 would be returned.


            /*
             * Returns a decimal equivalent (ending decimal values will be dropped) of what was passed in as the DataType value, "12.5".
             * If the conversion fails, The user defined parameter passed is returned.
             * Otherwise if nothing is passed in the UnitOf.ToDecimal() default value of 0.0M is returned.
             */
            decimal decimalDefault0  = uoDataType.ToDecimal();      //Returns 12 as "12.5" passed in is a non-decimal type so the ".5" is dropped, If the conversion did fail, the UnitOf.ToDecimal() default value of 0.0M is returned.
            decimal decimalDefault1M = uoDataType.ToDecimal(1M);    //Returns 12 If the conversion did fail, 1M would be returned.


            /*
             * Returns a DateTime equivalent of what was passed in as the DataType value, "12.5".
             * If the conversion fails, The user defined parameter passed is returned.
             * Otherwise if nothing is passed in the UnitOf.ToDateTime() default value of DateTime.Today is returned.
             */
            DateTime dateTimeDefaultNewDT = uoDataType.ToDateTime();                //Returns "12/5/2018 12:00:00 AM" (if compiled in the US during the year of 2018) as "12.5" is read as month: 12, day: 5, and the rest are defaults. If the conversion did fail, the UnitOf.ToDateTime() default value of DateTime.Today is returned.
            DateTime dateTimeDefaultToday = uoDataType.ToDateTime(DateTime.Today);  //Returns "12/5/2018 12:00:00 AM"  If failed, returns DateTime.Today, today (your system's date and time) would be returned like 11/30/2008 12:00:00 AM.


            /*
             * Returns a DateTime equivalent of what was passed in as the DataType value, "12.5".
             * If the conversion fails, The user defined parameter passed is returned.
             * Otherwise if nothing is passed in the UnitOf.ToDateTime() default value of DateTime.Today is returned.
             */
            TimeSpan timeSpanDefaultNewTS       = uoDataType.ToTimeSpan();                          //Returns "00:00:00" as the conversion fails and this is the default
            TimeSpan timeSpanDefaultFrom2Minues = uoDataType.ToTimeSpan(TimeSpan.FromMinutes(2));   //Returns "00:02:00" as the conversion fails and the default passed in was 2 minutes


            /*
             * -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
             * Print Conversions
             * -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
             */
            p("-=-=-=-=-\nType and Value Originally passed in (\"12.5\" as a String)");
            pt(dataTypePassedType);         //The word "String" is returned
            pt(dataTypePassedValue);        //"12.5" as a String is returned

            p("-=-=-=-=-\nConverted \"12.5\" toDouble()");
            pt(doubleDefault0);             //Returns 12.5 from "12.5", If the conversion did fail, the UnitOf.ToDouble() default value of 0.0d is returned.
            pt(doubleDefault1dot23);        //Returns 12.5 If the conversion did fail, 1.23 would be returned.

            p("-=-=-=-=-\nConverted \"12.5\" toInt()");
            pt(intDefault0);                //Returns 12 as "12.5" passed in is a non-decimal type so the ".5" is dropped, If the conversion did fail, the UnitOf.ToInt() default value of 0 is returned.
            pt(intDefaultNeg25);            //Returns 12 If the conversion did fail, -25 would be returned.

            p("-=-=-=-=-\nConverted \"12.5\" toString()");
            pt(stringDefaultEmptyStr);      //String equivalent of "12.5" is returned, If the conversion did fail, the UnitOf.ToString() default value of null is returned.
            pt(stringDefault1dot23Str);     //Returns "12.5" If the conversion did fail, "1.23" would be returned.

            p("-=-=-=-=-\nConverting toBoolean()");
            pt(booleanDefaultFalse);        //Conversion fails: false is returned. No default was passed in so the UnitOf.ToBoolean() default of false is returned.
            pt(booleanDefaultTrue);         //Conversion fails: true is returned. Default of true was passed in so it is returned

            p("-=-=-=-=-\nConverting toFraction()");
            pt(fractionDefaultEmpty);       //Returns "25/2" passed in as 25 divided by 2 equals the DataType value passed in, 12.5. If the conversion did fail, the UnitOf.ToFraction() default value of "" is returned.
            pt(fractionDefault2Slash5);     //Returns "25/2" If the conversion did fail, "2/5" would be returned.

            p("-=-=-=-=-\nConverted \"12.5\" toObject()");
            pt(objectDefaultNull);          //Object equivalent of "12.5" is returned, If the conversion fails, the UnitOf.ToObject() default value of null is returned.
            pt(objectDefault123);           //Returns "12.5" If the conversion did fail, 123 as an Object would be returned.
            pt(objectDefault1dot23);        //Returns "12.5" If the conversion did fail, 1.23 as an Object would be returned.
            pt(objectDefault12dot3Str);     //Returns "12.5" If the conversion did fail, "12.3" as an Object would be returned.

            p("-=-=-=-=-\nConverted \"12.5\" toChar()");
            pt(charDefaultCharNul);         //Returns '1' as it is the first non-spaced character of "12.5" passed in , If the conversion did fail, the UnitOf.ToChar() default value of '\0' is returned.
            pt(charDefaultAtSign);          //Returns '1' If the conversion did fail, '@' would be returned.

            p("-=-=-=-=-\nConverted \"12.5\" toFloat()");
            pt(floatDefault0);              //Returns 12.5 from "12.5", If the conversion did fail, the UnitOf.ToFloat() default value of 0.0f is returned.
            pt(floatDefault1dot23f);        //Returns 12.5 If the conversion did fail, 1.23f would be returned.

            p("-=-=-=-=-\nConverted \"12.5\" toLong()");
            pt(longDefault0);               //Returns 12 as "12.5" passed in is a non-decimal type so the ".5" is dropped, If the conversion did fail, the UnitOf.ToLong() default value of (long)0 is returned.
            pt(longDefault25);              //Returns 12 If the conversion did fail, 25 would be returned.

            p("-=-=-=-=-\nConverted \"12.5\" toShort()");
            pt(shortDefault0);              //Returns 12 as "12.5" passed in is a non-decimal type so the ".5" is dropped, If the conversion did fail, the UnitOf.ToShort() default value of (short)0 is returned.
            pt(shortDefault15);             //Returns 12 If the conversion did fail, (short)15 would be returned.

            p("-=-=-=-=-\nConverted \"12.5\" toByte()");
            pt(byteDefault0);               //Returns 12 as "12.5" passed in is a non-decimal type so the ".5" is dropped, If the conversion did fail, the UnitOf.ToByte() default value of (byte)0 is returned.
            pt(byteDefault5);               //Returns 12 If the conversion did fail, (byte)5 would be returned.

            p("-=-=-=-=-\nConverted \"12.5\" toSbyte()");
            pt(sbyteDefault0);              //Returns 12 as "12.5" passed in is a non-decimal type so the ".5" is dropped, If the conversion did fail, the UnitOf.ToSbyte() default value of (sbyte)0 is returned.
            pt(sbyteDefault6);              //Returns 12 If the conversion did fail, (sbyte)6 would be returned.

            p("-=-=-=-=-\nConverted \"12.5\" toUint()");
            pt(uintDefault0);               //Returns 12 as "12.5" passed in is a non-decimal type so the ".5" is dropped, If the conversion did fail, the UnitOf.ToUint() default value of (uint)0 is returned.
            pt(uintDefault7);               //Returns 12 If the conversion did fail, (uint)7 would be returned.

            p("-=-=-=-=-\nConverted \"12.5\" toUlong()");
            pt(ulongDefault0);              //Returns 12 as "12.5" passed in is a non-decimal type so the ".5" is dropped, If the conversion did fail, the UnitOf.ToUlong() default value of (ulong)0 is returned.
            pt(ulongDefault8);              //Returns 12 If the conversion did fail, (ulong)8 would be returned.

            p("-=-=-=-=-\nConverted \"12.5\" toUshort()");
            pt(ushortDefault0);             //Returns 12 as "12.5" passed in is a non-decimal type so the ".5" is dropped, If the conversion did fail, the UnitOf.ToUshort() default value of (ushort)0 is returned.
            pt(ushortDefault9);             //Returns 12 If the conversion did fail, (ushort)9 would be returned.

            p("-=-=-=-=-\nConverted \"12.5\" toDecimal()");
            pt(decimalDefault0);            //Returns 12 as "12.5" passed in is a non-decimal type so the ".5" is dropped, If the conversion did fail, the UnitOf.ToDecimal() default value of 0.0M is returned.
            pt(decimalDefault1M);           //Returns 12 If the conversion did fail, 1M would be returned.

            p("-=-=-=-=-\nConverted \"12.5\" toDateTime()");
            pt(dateTimeDefaultNewDT);       //Returns "12/5/2018 12:00:00 AM" (if compiled in the US during the year of 2018) as "12.5" is read as month: 12, day: 5, and the rest are defaults. If the conversion did fail, the UnitOf.ToDateTime() default value of DateTime.Today is returned.
            pt(dateTimeDefaultToday);       //Returns "12/5/2018 12:00:00 AM"  If failed, returns DateTime.Today, today (your system's date and time) would be returned like 11/30/2008 12:00:00 AM.

            p("-=-=-=-=-\nConverted \"12.5\" toTimeSpan()");
            pt(timeSpanDefaultNewTS);       //Returns "00:00:00" as the conversion fails and this is the default
            pt(timeSpanDefaultFrom2Minues); //Returns "00:02:00" as the conversion fails and the default passed in was 2 minutes
        }
コード例 #4
0
        /*
         * Determine if our collection of "Unit", "unitof", or "ThisIsUnitOf" matches in our UnitOf.DataType value, "UnitOf" toggling our matching settings.
         */
        public static void oneLiner_1_Step()
        {
            p("\n-=-=-=-=-=-=-=-=-\nDataType_Class > Boolean_Extended_Syntax > oneLiner_1_Step");

            /**
             * Returns true if "UnitOf" contains the specified sequence of char values in the same casing as the passed in UnitOf.DataType value.
             * This specified sequence of char values are: "Unit", "unitof", or "ThisIsUnitOf".
             *
             * 1st Parameter | trueValues           | Object[]  | Objects to match the UnitOf.DataType value against: Collection passed is a String array with 3 elements, "Unit", "unitof", "ThisIsUnitOf".
             * 2nd Parameter | caseSensitive (true) | boolean   | If matching is case sensitive (can be left blank defaulting with false)
             * 3rd Parameter | contains (true)      | boolean   | If matching is less strict by only comparing the specified sequence of char value in any of the collection elements.
             *
             * Results breakdown: returns true
             * "UnitOf" == "Unit" | The proper casing exists for the first 4 characters and am only performing a contains, not equals. If equals, this would be false
             * "UnitOf" != "unitof" | CaseSensitivity (second parameter) is set to true meaning because the "u" and "o" of "unitof" are not capitalized this returns false. if casing were to be ignored this would be true.
             * "UnitOf" != "ThisIsUnitOf" | While "UnitOf" with its proper casing exists in "ThisIsUnitOf", contains does not check if the UnitOf.DataType value is contained within the collection, only the vice versa exists.
             */
            bool matchStr_Case_Contains = new UnitOf.DataType("UnitOf").ToBoolean(new string[] { "Unit", "unitof", "ThisIsUnitOf" }, true, true);//Returns true due to "Unit"

            /**
             * Returns true if "UnitOf" contains the specified sequence of char values (casing ignored) as the passed in UnitOf.DataType value.
             * This specified sequence of char values are: "Unit", "unitof", or "ThisIsUnitOf"
             *
             * 1st Parameter | trueValues           | Object[]  | Objects to match the UnitOf.DataType value against: Collection passed is a String array with 3 elements, "Unit", "unitof", "ThisIsUnitOf".
             * 2nd Parameter | caseSensitive (false) | boolean   | If matching is case sensitive (can be left blank defaulting with false)
             * 3rd Parameter | contains (true)      | boolean   | If matching is less strict by only comparing the specified sequence of char value in any of the collection elements.
             *
             * Results breakdown: returns true
             * "UnitOf" == "Unit" | "Unit" is within "UnitOf"
             * "UnitOf" == "unitof" | "unitof" is within "UnitOf" as well as casing being ignored
             * "UnitOf" != "ThisIsUnitOf" | While "UnitOf" with its proper casing exists in "ThisIsUnitOf", contains does not check if the UnitOf.DataType value is contained within the collection, only the vice versa exists.
             */
            bool matchStr_NonCase_Contains = new UnitOf.DataType("UnitOf").ToBoolean(new string[] { "Unit", "unitof", "ThisIsUnitOf" }, false, true);//Returns true: "Unit", "unitof"

            /**
             * Returns true if "UnitOf" equals the specified sequence of char values (casing ignored) as the passed in UnitOf.DataType value.
             * This specified sequence of chars being: "Unit", "unitof", or "ThisIsUnitOf"
             *
             * 1st Parameter | trueValues           | Object[]  | Objects to match the UnitOf.DataType value against: Collection passed is a String array with 3 elements, "Unit", "unitof", "ThisIsUnitOf".
             * 2nd Parameter | caseSensitive (false)| boolean   | If matching is case sensitive (can be left blank defaulting with false)
             * 3rd Parameter | contains (false)     | boolean   | If matching is less strict by only comparing the specified sequence of char value in any of the collection elements.
             *
             * Results breakdown: returns true
             * "UnitOf" != "Unit" | Despite casing being ignored, "UnitOf" does not equal "Unit" due to "Of" missing.
             * "UnitOf" == "unitof" | Because casing is ignored, "unitof" equals "UnitOf"
             * "UnitOf" != "ThisIsUnitOf" | "UnitOf" does not equal "ThisIsUnitOf" due to it starting with "ThisIs"
             */
            bool matchStr_NonCase_Equals = new UnitOf.DataType("UnitOf").ToBoolean(new string[] { "Unit", "unitof", "ThisIsUnitOf" });//Returns true. only "unitof"

            /**
             * Returns true if "UnitOf" contains the specified sequence of char values in the same casing as the passed in UnitOf.DataType value.
             * This specified sequence of chars being: "Unit", "unitof", or "ThisIsUnitOf"
             *
             * 1st Parameter | trueValues           | Object[]  | Objects to match the UnitOf.DataType value against: Collection passed is a String array with 3 elements, "Unit", "unitof", "ThisIsUnitOf".
             * 2nd Parameter | caseSensitive (true) | boolean   | If matching is case sensitive (can be left blank defaulting with false)
             * 3rd Parameter | contains (false)     | boolean   | If matching is less strict by only comparing the specified sequence of char value in any of the collection elements.
             *
             * Results breakdown: returns false
             * "UnitOf" != "Unit" | While the proper casing is correct, "UnitOf" does not equal "Unit" due to "Of" missing.
             * "UnitOf" != "unitof" | "unitof" does not equals "UnitOf" because casing is not ignored
             * "UnitOf" != "ThisIsUnitOf" | "UnitOf" does not equal "ThisIsUnitOf" due to it starting with "ThisIs"
             */
            bool matchStr_Case_Equals = new UnitOf.DataType("UnitOf").ToBoolean(new string[] { "Unit", "unitof", "ThisIsUnitOf" }, true);//Returns false, no matches

            //Print results
            pt("String Passed: UnitOf | Collection passed with true value: Unit, unitof, ThisIsUnitOf");
            pt("matchStr_Case_Contains: " + matchStr_Case_Contains);        //Returns true due to "Unit"
            pt("matchStr_NonCase_Contains: " + matchStr_NonCase_Contains);  //Returns true: "Unit", "unitof"
            pt("matchStr_NonCase_Equals: " + matchStr_NonCase_Equals);      //Returns true. only "unitof"
            pt("matchStr_Case_Equals: " + matchStr_Case_Equals);            //Returns false, no matches
        }