Exemplo n.º 1
0
 /// <summary>
 ///  Create a copy of a String8. Use when the source of the String8s
 ///  will change (like a reader reusing the same byte[] buffer) and
 ///  you need to keep a copy of specific values with minimal object overhead.
 /// </summary>
 /// <param name="source">String8 to copy</param>
 /// <returns>String8 copy which will persist</returns>
 public String8 GetCopy(ITabularValue source)
 {
     if (source is String8TabularValue)
     {
         return(GetCopy(source.ToString8()));
     }
     return(GetCopy(source.ToString()));
 }
Exemplo n.º 2
0
        public static bool ToBoolean(this ITabularValue value)
        {
            bool result;

            if (value.TryToBoolean(out result))
            {
                return(result);
            }
            throw new FormatException(value.ToString());
        }
Exemplo n.º 3
0
        public static int ToInteger(this ITabularValue value)
        {
            int result;

            if (value.TryToInteger(out result))
            {
                return(result);
            }
            throw new FormatException(value.ToString());
        }
Exemplo n.º 4
0
        public static DateTime ToDateTime(this ITabularValue value)
        {
            DateTime result;

            if (value.TryToDateTime(out result))
            {
                return(result);
            }
            throw new FormatException(value.ToString());
        }
        private static void ITabularValue_Basics(string value, String8 value8, ITabularValue itv)
        {
            Assert.AreEqual(String.IsNullOrEmpty(value), itv.IsNullOrEmpty());
            Assert.AreEqual(value8, itv.ToString8());
            Assert.AreEqual(value, itv.ToString());

            bool asBoolean;

            if (bool.TryParse(value, out asBoolean))
            {
                Assert.AreEqual(asBoolean, itv.ToBoolean());
            }
            else
            {
                Verify.Exception <FormatException>(() => { var result = itv.ToBoolean(); });
            }

            int asInteger;

            if (int.TryParse(value, out asInteger))
            {
                Assert.AreEqual(asInteger, itv.ToInteger());
            }
            else
            {
                Verify.Exception <FormatException>(() => { var result = itv.ToInteger(); });
            }

            DateTime asDateTime;

            if (DateTime.TryParse(value, CultureInfo.CurrentCulture, DateTimeStyles.AssumeUniversal | DateTimeStyles.AdjustToUniversal, out asDateTime))
            {
                Assert.AreEqual(asDateTime, itv.ToDateTime());
            }
            else
            {
                Verify.Exception <FormatException>(() => { var result = itv.ToDateTime(); });
            }
        }