Exemplo n.º 1
0
        private static bool IsEmpty(this object value)
        {
            if (value == null)
            {
                return(true);
            }
#if !SKIP_FSHARP
            if (ReflectionHelper.IsFSharpOptionType(value.GetType()) && !FSharpOptionHelper.IsSome(value))
            {
                return(true);
            }
#endif
            if (value is ValueType && value.Equals(value.GetType().GetDefaultValue()))
            {
                return(true);
            }
            if (value is string && ((string)value).Length == 0)
            {
                return(true);
            }
            if (value is IEnumerable && !((IEnumerable)value).GetEnumerator().MoveNext())
            {
                return(true);
            }
            return(false);
        }
        private static bool IsEmpty(this object value, Specification specification, bool skipDefault)
        {
            if (value == null)
            {
                return(true);
            }

            if (skipDefault && value.Equals(specification.DefaultValue.FromJust()))
            {
                return(true);
            }
            if (Nullable.GetUnderlyingType(specification.ConversionType) != null)
            {
                return(false);                                                                  //nullable
            }
#if !SKIP_FSHARP
            if (ReflectionHelper.IsFSharpOptionType(value.GetType()) && !FSharpOptionHelper.IsSome(value))
            {
                return(true);
            }
#endif
            if (value is ValueType && value.Equals(value.GetType().GetDefaultValue()))
            {
                return(true);
            }
            if (value is string && ((string)value).Length == 0)
            {
                return(true);
            }
            if (value is IEnumerable && !((IEnumerable)value).GetEnumerator().MoveNext())
            {
                return(true);
            }
            return(false);
        }
Exemplo n.º 3
0
 private static object NormalizeValue(this object value)
 {
     if (value != null &&
         ReflectionHelper.IsFSharpOptionType(value.GetType()) &&
         FSharpOptionHelper.IsSome(value))
     {
         return(FSharpOptionHelper.ValueOf(value));
     }
     return(value);
 }