Beispiel #1
0
        public static object GetNullKey(Type type)
        {
            type = TypeHelper.CheckNullable(type);
            if (type.IsEnum)
            {
                return(Enum.ToObject(type, int.MinValue));
            }
            if (nullKeys.TryGetValue(type, out var value))
            {
                return(value);
            }

            return(FormatterServices.GetUninitializedObject(type));
        }
Beispiel #2
0
        private string FormatValue()
        {
            if (Invoker == null)
            {
                return(Value.ToString());
            }
            if (Value == null)
            {
                return("null");
            }
            if (Value is IQueryFormatable formatable)
            {
                return(formatable.Format());
            }
            if (Value is DateTime date)
            {
                return($"'{date.ToString("yyyy.MM.dd")}'");
            }
            var type = TypeHelper.CheckNullable(Invoker.DataType);

            if (Value is string stringValue)
            {
                if (Comparer.Type == CompareTypes.Like && stringValue.IndexOf('%') < 0)
                {
                    return($"'%{stringValue}%'");
                }
                else if (Comparer.Type == CompareTypes.In)
                {
                    return(stringValue);
                }
                return($"'{stringValue}'");
            }
            else if (Value is IEnumerable enumerable)
            {
                return(string.Concat('(', string.Join(", ", enumerable.Cast <object>().Select(p => p is string ps ? $"'{ps}'" : p?.ToString())), ')'));
            }
            else
            {
                return(Value.ToString());
            }
        }
Beispiel #3
0
        public static object GetNullKey(Type type)
        {
            type = TypeHelper.CheckNullable(type);
            if (type == typeof(string))
            {
                return("magic ZeRo String Va!@#;)(*&ue");//, (IEqualityComparer<K>)StringComparer.OrdinalIgnoreCase);
            }

            if (type.IsEnum)
            {
                return(Enum.ToObject(type, int.MinValue));
            }
            if (type == typeof(bool))
            {
                return(false);
            }
            if (type == typeof(long))
            {
                return(long.MinValue);
            }
            else if (type == typeof(int))
            {
                return(int.MinValue);
            }
            else if (type == typeof(short))
            {
                return(short.MinValue);
            }
            else if (type == typeof(char))
            {
                return(char.MinValue);
            }
            else if (type == typeof(sbyte))
            {
                return(sbyte.MinValue);
            }
            else if (type == typeof(ulong))
            {
                return(ulong.MinValue);
            }
            else if (type == typeof(uint))
            {
                return(uint.MinValue);
            }
            else if (type == typeof(ushort))
            {
                return(uint.MinValue);
            }
            else if (type == typeof(byte))
            {
                return(byte.MinValue);
            }
            else if (type == typeof(decimal))
            {
                return(decimal.MinValue);
            }
            else if (type == typeof(double))
            {
                return(double.MinValue);
            }
            else if (type == typeof(float))
            {
                return(float.MinValue);
            }
            return(FormatterServices.GetUninitializedObject(type));
        }