Ejemplo n.º 1
0
        //////////////////////////////

        public static String ToString(Object Object)
        {
            Type objectType = Object != null?Object.GetType() : null;

            if (Object == null)
            {
                return("NULL");
            }
            else if (MyTypeHelper.IsDateTime(objectType))
            {
                return("todatetime('" + UniConvert.ToUniString(Object) + "')");
            }
            else if (objectType == typeof(InternalDateTime))
            {
                DateTime?dateTime = objectType == null ?
                                    null :
                                    (DateTime?)new DateTime(((InternalDateTime)Object).Ticks);

                return("todatetime('" + UniConvert.ToUniString(dateTime) + "')");
            }
            else if (MyTypeHelper.IsNumeric(objectType))
            {
                return(UniConvert.ToUniString(Object));
            }
            else if (MyTypeHelper.IsString(objectType))
            {
                return("'" + Object.ToString().Replace("'", "\\'") + "'");
            }
            else
            {
                throw new NotSupportedException("Objects of type " + objectType.Name + " are not supported in expressions");
            }
        }
Ejemplo n.º 2
0
        public static string GetSqlType(Type csType)
        {
            if (csType != null)
            {
                if (MyTypeHelper.IsInteger(csType))
                {
                    return("int");
                }

                else if (MyTypeHelper.IsNumeric(csType))
                {
                    return("real");
                }

                else if (MyTypeHelper.IsDateTime(csType))
                {
                    return("datetime");
                }

                else if (MyTypeHelper.IsTimeSpan(csType))
                {
                    return("datetime");
                }
            }

            return("nvarchar(max)");
        }
Ejemplo n.º 3
0
 public static Object ToInner(Object Value)
 {
     if (Value != null && MyTypeHelper.IsDateTime(Value.GetType()))
     {
         return(new InternalDateTime(((DateTime)Value).Ticks));
     }
     return(Value);
 }
Ejemplo n.º 4
0
        public Object Validate(Object Value)
        {
            if (Type == S4JFieldType.ANY)
            {
                return(Value);
            }

            if (IsRequired && Value == null)
            {
                throw new S4JNullParameterException("Parameter " + Name + " cannot be null");
            }

            if (Value != null && Type == S4JFieldType.BOOL)
            {
                if (!MyTypeHelper.IsBoolean(Value.GetType()))
                {
                    throw new S4JInvalidParameterTypeException("Parameter " + Name + " should be of type boolean");
                }
            }

            if (Value != null && Type == S4JFieldType.DATETIME)
            {
                if (!MyTypeHelper.IsDateTime(Value.GetType()))
                {
                    throw new S4JInvalidParameterTypeException("Parameter " + Name + " should be of type datetime");
                }
            }

            if (Value != null && Type == S4JFieldType.FLOAT)
            {
                if (!MyTypeHelper.IsNumeric(Value.GetType()))
                {
                    throw new S4JInvalidParameterTypeException("Parameter " + Name + " should be of type float");
                }
            }

            if (Value != null && Type == S4JFieldType.INT)
            {
                if (!MyTypeHelper.IsInteger(Value.GetType()))
                {
                    throw new S4JInvalidParameterTypeException("Parameter " + Name + " should be of type integer");
                }
            }

            if (Value != null && Type == S4JFieldType.STRING)
            {
                if (!MyTypeHelper.IsString(Value.GetType()))
                {
                    throw new S4JInvalidParameterTypeException("Parameter " + Name + " should be of type string");
                }
            }

            if (Type == S4JFieldType.ARRAY)
            {
                if (Value == null)
                {
                    return(new List <Object>());
                }
                else if (!(Value is IList))
                {
                    //if (MyTypeHelper.IsClass(Value.GetType()) || Value is IDictionary<String, Object>)
                    //    return new List<Object>() { Value };
                    throw new S4JInvalidParameterTypeException("Parameter " + Name + " should be of type array");
                }
            }

            if (Value != null && Type == S4JFieldType.OBJECT)
            {
                if (!(MyTypeHelper.IsClass(Value.GetType()) || Value is IDictionary <String, Object>) || Value is IList)
                {
                    throw new S4JInvalidParameterTypeException("Parameter " + Name + " should be of type object");
                }
            }

            return(Value);
        }