9 namespace Core.TypeCast.Converters
12 using System.Globalization;
21 [System.Runtime.InteropServices.ComVisible(
false)]
22 [
Converter(loadOnDemand:
true, nameSpace: nameof(System), dependencyInjection:
true)]
29 private readonly Type
self;
36 this.
self = this.GetType();
42 this.AddObjectConverter(collection: collection);
49 public NumberFormatInfo NumberFormat {
get;
set; }
58 collection.
Add<object,
int>(o =>
int.Parse(o != null ? o.ToString() :
string.Empty, this.NumberFormat), this.
self)
59 .
Add<object, uint>(o => uint.Parse(o != null ? o.ToString() :
string.Empty, this.NumberFormat), this.
self)
60 .
Add<object,
char>(o => Convert.ToChar(o), this.
self)
61 .Add<object, bool>(o => o != null && (
int)o != 0 && o.ToString() !=
"false", this.
self)
62 .Add<object, string>(o => o != null ? o.ToString() :
string.Empty, this.
self)
63 .Add<object, byte>(o => byte.Parse(o != null ? o.ToString() :
string.Empty, this.NumberFormat), this.
self)
64 .
Add<object, sbyte>(o => sbyte.Parse(o != null ? o.ToString() :
string.Empty, this.NumberFormat), this.
self)
65 .
Add<object, decimal>(o => decimal.Parse(o != null ? o.ToString() :
string.Empty, this.NumberFormat), this.
self)
66 .
Add<object,
double>(o =>
double.Parse(o != null ? o.ToString() :
string.Empty, this.NumberFormat), this.
self)
67 .
Add<object,
float>(o =>
float.Parse(o != null ? o.ToString() :
string.Empty, this.NumberFormat), this.
self)
68 .
Add<object,
long>(o =>
long.Parse(o != null ? o.ToString() :
string.Empty, this.NumberFormat), this.
self)
69 .
Add<object, ulong>(o => ulong.Parse(o != null ? o.ToString() :
string.Empty, this.NumberFormat), this.
self)
70 .
Add<object,
short>(o =>
short.Parse(o != null ? o.ToString() :
string.Empty, this.NumberFormat), this.
self)
71 .
Add<object, ushort>(o => ushort.Parse(o != null ? o.ToString() :
string.Empty, this.NumberFormat), this.
self)
72 .
Add<object, Enum>(o => (Enum)Enum.Parse(o?.GetType(), o != null ? o.ToString() :
string.Empty), this.
self)
73 .
Add<object, DateTime>(o => DateTime.Parse(o != null ? o.ToString() :
string.Empty, this.NumberFormat), this.
self);
The converter dependency provides loose implementation of Converters, merely constricting the constru...
IConverterCollection Add(Converter converter, Type baseType=null, bool allowDisambiguates=false, CancellationToken cancellationToken=default(CancellationToken))
Adds a Converter instance to the collection of ConverterCollection.Items
ConverterCollectionSettings Settings
The settings for the ConverterCollection.
ConverterDefaults(IConverterCollection collection)
Initializes a new instance of the ConverterDefaults class, and adds converters for the most common ty...
NumberFormatInfo NumberFormat
Gets or sets the number format used by default for Converter instances.
Converts between object and the most common System types in the System namespace. ...
The Converter base class, providing a simple container for conversion types, ConverterAttribute and c...