예제 #1
0
        public static TOD Parse(string str)
        {
            TOD ret = null;

            if (!TryParse(str, out ret))
            {
                throw new FormatException("Cannot parse TOD object!");
            }
            return(ret);
        }
예제 #2
0
        public static bool TryParse(string s, out TOD tod)
        {
            uint     num;
            TimeSpan span;

            if (TryParseToTicks(s, out num))
            {
                tod = new TOD(num);
                return(true);
            }
            if (PlcOpenDateConverterBase.TryParseTimeSpan(s, out span))
            {
                tod = new TOD(span);
                return(true);
            }
            tod = null;
            return(false);
        }
예제 #3
0
 public static bool TryConvert(TOD date, Type targetType, out object targetValue)
 {
     targetValue = null;
     if (targetType == typeof(TimeSpan))
     {
         targetValue = date.Time;
     }
     else if (targetType == typeof(uint))
     {
         targetValue = date.Ticks;
     }
     else if (targetType == typeof(long))
     {
         targetValue = date.Ticks;
     }
     else if (targetType == typeof(string))
     {
         targetValue = date.ToString();
     }
     return(targetValue != null);
 }
예제 #4
0
 public static bool TryConvert(object source, out TOD timeOfDay)
 {
     timeOfDay = null;
     if (source.GetType() == typeof(long))
     {
         timeOfDay = Create((long)source);
     }
     else if (source.GetType() == typeof(uint))
     {
         timeOfDay = Create((uint)source);
     }
     else if (source.GetType() == typeof(TimeSpan))
     {
         timeOfDay = Create((TimeSpan)source);
     }
     else if (source.GetType() == typeof(string))
     {
         TryParse((string)source, out timeOfDay);
     }
     return(timeOfDay != null);
 }
예제 #5
0
 public static byte[] GetBytes(TOD tod) =>
 BitConverter.GetBytes(tod.Ticks);
예제 #6
0
 public static bool TryParse(string str, out TOD ret) =>
 PlcOpenTODConverter.TryParse(str, out ret);