Woopsa.WoopsaValue.CreateUnchecked C# (CSharp) Method

CreateUnchecked() static private method

static private CreateUnchecked ( string text, WoopsaValueType type, System.DateTime timestamp = null ) : WoopsaValue
text string
type WoopsaValueType
timestamp System.DateTime
return WoopsaValue
        internal static WoopsaValue CreateUnchecked(string text, WoopsaValueType type, DateTime? timestamp = null)
        {
            return new WoopsaValue(text, type, timestamp);
        }

Usage Example

示例#1
0
        public static WoopsaValue ToWoopsaValue(object value, WoopsaValueType type, DateTime?timeStamp = null)
        {
            try
            {
                switch (type)
                {
                case WoopsaValueType.Logical:
                    return(new WoopsaValue((bool)value, timeStamp));

                case WoopsaValueType.Integer:
                    return(new WoopsaValue(Convert.ToInt64(value), timeStamp));

                case WoopsaValueType.Real:
                    return(new WoopsaValue(Convert.ToDouble(value), timeStamp));

                case WoopsaValueType.DateTime:
                    return(new WoopsaValue((DateTime)value, timeStamp));

                case WoopsaValueType.TimeSpan:
                    if (value is TimeSpan)
                    {
                        return(new WoopsaValue((TimeSpan)value, timeStamp));
                    }
                    else
                    {
                        return(new WoopsaValue(TimeSpan.FromSeconds(Convert.ToDouble(value)),
                                               timeStamp));
                    }

                case WoopsaValueType.Text:
                    if (value == null)
                    {
                        return(new WoopsaValue(string.Empty, timeStamp));
                    }
                    else if (value.GetType().IsEnum)
                    {
                        return(new WoopsaValue(value.ToString(), timeStamp));
                    }
                    else if (string.IsNullOrEmpty((string)value))
                    {
                        return(new WoopsaValue(string.Empty, timeStamp));
                    }
                    else
                    {
                        return(new WoopsaValue(WoopsaFormat.ToStringWoopsa(value), timeStamp));
                    }

                default:
                    return(WoopsaValue.CreateUnchecked(WoopsaFormat.ToStringWoopsa(value), type, timeStamp));
                }
            }
            catch (InvalidCastException)
            {
                throw new WoopsaException(String.Format("Cannot typecast object of type {0} to Woopsa Type {1}", value.GetType(), type.ToString()));
            }
        }
All Usage Examples Of Woopsa.WoopsaValue::CreateUnchecked