using Unosquare.Swan.Reflection; using System; using System.Collections.Generic; using System.Linq; using System.Net; namespace Unosquare.Swan { /// /// Contains useful constants and definitions. /// public static partial class Definitions { #region Main Dictionary Definition /// /// The basic types information. /// public static readonly Dictionary BasicTypesInfo = new Dictionary { // Non-Nullables {typeof(DateTime), new ExtendedTypeInfo()}, {typeof(Byte), new ExtendedTypeInfo()}, {typeof(SByte), new ExtendedTypeInfo()}, {typeof(Int32), new ExtendedTypeInfo()}, {typeof(UInt32), new ExtendedTypeInfo()}, {typeof(Int16), new ExtendedTypeInfo()}, {typeof(UInt16), new ExtendedTypeInfo()}, {typeof(Int64), new ExtendedTypeInfo()}, {typeof(UInt64), new ExtendedTypeInfo()}, {typeof(Single), new ExtendedTypeInfo()}, {typeof(Double), new ExtendedTypeInfo()}, {typeof(Char), new ExtendedTypeInfo()}, {typeof(Boolean), new ExtendedTypeInfo()}, {typeof(Decimal), new ExtendedTypeInfo()}, {typeof(Guid), new ExtendedTypeInfo()}, // Strings is also considered a basic type (it's the only basic reference type) {typeof(String), new ExtendedTypeInfo()}, // Nullables {typeof(DateTime?), new ExtendedTypeInfo()}, {typeof(Byte?), new ExtendedTypeInfo()}, {typeof(SByte?), new ExtendedTypeInfo()}, {typeof(Int32?), new ExtendedTypeInfo()}, {typeof(UInt32?), new ExtendedTypeInfo()}, {typeof(Int16?), new ExtendedTypeInfo()}, {typeof(UInt16?), new ExtendedTypeInfo()}, {typeof(Int64?), new ExtendedTypeInfo()}, {typeof(UInt64?), new ExtendedTypeInfo()}, {typeof(Single?), new ExtendedTypeInfo()}, {typeof(Double?), new ExtendedTypeInfo()}, {typeof(Char?), new ExtendedTypeInfo()}, {typeof(Boolean?), new ExtendedTypeInfo()}, {typeof(Decimal?), new ExtendedTypeInfo()}, {typeof(Guid?), new ExtendedTypeInfo()}, // Additional Types {typeof(TimeSpan), new ExtendedTypeInfo()}, {typeof(TimeSpan?), new ExtendedTypeInfo()}, {typeof(IPAddress), new ExtendedTypeInfo()}, }; #endregion /// /// Contains all basic types, including string, date time, and all of their nullable counterparts. /// /// /// All basic types. /// public static List AllBasicTypes { get; } = new List(BasicTypesInfo.Keys.ToArray()); /// /// Gets all numeric types including their nullable counterparts. /// Note that Booleans and Guids are not considered numeric types. /// /// /// All numeric types. /// public static List AllNumericTypes { get; } = new List( BasicTypesInfo .Where(kvp => kvp.Value.IsNumeric) .Select(kvp => kvp.Key).ToArray()); /// /// Gets all numeric types without their nullable counterparts. /// Note that Booleans and Guids are not considered numeric types. /// /// /// All numeric value types. /// public static List AllNumericValueTypes { get; } = new List( BasicTypesInfo .Where(kvp => kvp.Value.IsNumeric && kvp.Value.IsNullableValueType == false) .Select(kvp => kvp.Key).ToArray()); /// /// Contains all basic value types. i.e. excludes string and nullables. /// /// /// All basic value types. /// public static List AllBasicValueTypes { get; } = new List( BasicTypesInfo .Where(kvp => kvp.Value.IsValueType) .Select(kvp => kvp.Key).ToArray()); /// /// Contains all basic value types including the string type. i.e. excludes nullables. /// /// /// All basic value and string types. /// public static List AllBasicValueAndStringTypes { get; } = new List( BasicTypesInfo .Where(kvp => kvp.Value.IsValueType || kvp.Key == typeof(String)) .Select(kvp => kvp.Key).ToArray()); /// /// Gets all nullable value types. i.e. excludes string and all basic value types. /// /// /// All basic nullable value types. /// public static List AllBasicNullableValueTypes { get; } = new List( BasicTypesInfo .Where(kvp => kvp.Value.IsNullableValueType) .Select(kvp => kvp.Key).ToArray()); } }