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