.NET Portable TypeCast
3.1.0.4
A, easy-to-use tested, generic, portable, runtime-extensible, arbitrary type converter library
|
The thread-safe, static collection of Converter items, using Core.Singleton and supporting Core.Singleton.ISingleton More...
Classes | |
class | AddBuilder |
Allows to perform a deferred adding operation of multiple adds using a common Base-Class Type argument, common ConverterCollectionSettings as well as a mutual CancellationToken for the added group of converters. The operation is applied upon invoking End, and can be explicitly canceled by invoking Cancel More... | |
Public Member Functions | |
ConverterCollection () | |
Initializes a new instance of the ConverterCollection class with default-parameters. More... | |
ConverterCollection (Type application) | |
Initializes a new instance of the ConverterCollection class with default-parameters. More... | |
ConverterCollection (Type application, Type converterClass, NumberFormatInfo numberFormatDefault=null) | |
Initializes a new instance of the ConverterCollection class with default-parameters. More... | |
ConverterCollection (Assembly assembly, NumberFormatInfo numberFormatDefault=null) | |
Initializes a new instance of the ConverterCollection class with default-parameters. More... | |
ConverterCollection (Type application=null, params Type[] converterClasses) | |
Initializes a new instance of the ConverterCollection class with default-parameters. More... | |
IConverterCollection | Add (object converterDelegate, Type baseType=null, CancellationToken cancellationToken=default(CancellationToken)) |
Initializes a new instance of the ConverterCollection class with default-parameters. More... | |
IConverterCollection | Add (MethodInfo methodInfo, object converterDelegate=null, Type baseType=null, object baseInstance=null, CancellationToken cancellationToken=default(CancellationToken)) |
Creates and adds a Converter instance to the collection of ConverterCollection.Items using a MethodInfo instance More... | |
IConverterCollection | Add (Converter converter, Type baseType=null, bool allowDisambiguates=false, CancellationToken cancellationToken=default(CancellationToken)) |
Adds a Converter instance to the collection of ConverterCollection.Items More... | |
bool | CanConvertFrom (Type typeFrom) |
Returns bool true if the ConverterCollection supports conversion for a given Type typeFrom , else false . More... | |
bool | CanConvertFrom< TIn > () |
Returns bool true if the ConverterCollection supports conversion for a given Type typeFrom , else false . More... | |
bool | CanConvertTo (Type typeTo) |
Returns bool true if the ConverterCollection supports conversion for a given Type typeTo , else false . More... | |
bool | CanConvertTo< TOut > () |
Returns bool true if the ConverterCollection supports conversion for a given Type typeTo , else false . More... | |
ConverterAttribute | ConverterAttributeFromIConverter (TypeInfo baseType, ConverterAttribute attribute=null, bool update=false) |
Adds or updates an attribute for a Converter if it exists, dependent only on the source and target conversion types More... | |
int | LoadOnDemandConverter (Type typeTo) |
Tries to lookup the namespace obtained from typeTo in loadOnDemandConverters and add the converters. If successful the number of Added Converters are returned, and the NameSpace is removed from the list of loadOnDemandConverters. More... | |
void | Initialize (string applicationNameSpace) |
Initializes all attributed Converter classes, Initialize(Assembly[]) More... | |
void | Initialize (Type applicationClass) |
Initializes all attributed Converter classes, Initialize(Assembly[]) More... | |
void | Initialize (Assembly assembly) |
Initializes all attributed Converter classes, Initialize(Assembly[]) More... | |
void | Initialize (Assembly[] assemblies) |
Initializes all attributed Converter classes, unless the ConverterAttribute parameter ConverterAttribute.LoadOnDemand is false More... | |
void | Initialize (IEnumerable< TypeInfo > types) |
Initializes all attributed Converter classes, unless the ConverterAttribute parameter ConverterAttribute.LoadOnDemand is false More... | |
IEnumerator< Converter > | GetEnumerator () |
Returns an enumerator that iterates through the collection. More... | |
IConverterCollection | Add< TIn, TOut > (Func< TIn, TOut > converterAction, Type baseType=null, CancellationToken cancellationToken=default(CancellationToken)) |
Creates and adds a Converter instance to the collection of ConverterCollection.Items using a Delegate More... | |
IConverterCollection | Add< TIn, TOut, TBase > (Func< TIn, TOut > converterAction, CancellationToken cancellationToken=default(CancellationToken)) |
Creates and adds a Converter instance to the collection of ConverterCollection.Items using a Delegate More... | |
IConverterCollection | Add< TIn, TOut, TBase > (Func< TIn, TOut, TOut > converterAction, CancellationToken cancellationToken=default(CancellationToken)) |
Creates and adds a Converter instance to the collection of ConverterCollection.Items using a Delegate More... | |
IConverterCollection | Add< TIn, TArg, TOut > (Func< TIn, TArg, TOut > converterActionAny, Type baseType=null, CancellationToken cancellationToken=default(CancellationToken)) |
Creates and adds a Converter instance to the collection of ConverterCollection.Items using a Delegate More... | |
IConverterCollection | Add< TBase > (object converterDelegate, CancellationToken cancellationToken=default(CancellationToken)) |
Creates and adds a Converter instance to the collection of ConverterCollection.Items using a Delegate More... | |
Static Public Member Functions | |
static void | AutoInitialize () |
Checks if the ConverterCollection is initialized. Attempts to initialize and load the user-assembly if ConverterCollection.Initialized is false More... | |
Protected Member Functions | |
override void | Dispose (bool disposing) |
Dispose of the Items and underlying static Singleton<TClass> references. More... | |
bool | SetAssemblyInitialized (TypeInfo type) |
Sets the Assembly as initialized in AssemblyInitialized More... | |
bool | SetConverterClassInitialized (TypeInfo converterClass) |
Sets the Converter of the ConverterCollection as initialized More... | |
Properties | |
ConverterCollectionSettings | Settings [get, set] |
The settings for the ConverterCollection. More... | |
ConcurrentDictionary< Assembly, bool > | AssemblyInitialized [get] |
Sets the Assembly as initialized in AssemblyInitialized More... | |
BlockingCollection< Converter > | Items [get] |
The BlockingCollection<Converter> class provides a thread-safe collection with full support of the Producer-Consumer pattern, to store a collection of Converter instances. More... | |
int | Count [get] |
Gets the count of singletons in the list. More... | |
The thread-safe, static collection of Converter items, using Core.Singleton and supporting Core.Singleton.ISingleton
See https://github.com/lsauer/csharp-singleton for more information.
Building the project requires the Singleton-library: https://www.nuget.org/packages/CSharp.Portable-Singleton/
If SingletonAttribute.CreateInternal is set to false
, ConverterCollection must explicitly be instantiated using new ConverterCollection(...)
and not use ConverterCollection.CurrentInstance before instantiation. If SingletonAttribute.CreateInternal is set to true
, lazy-instantiation of the singleton is possible at any time, after the program's assembly entry point is reached.
Definition at line 37 of file ConverterCollection.AddBuilder.cs.
Core.TypeCast.ConverterCollection.ConverterCollection | ( | ) |
Initializes a new instance of the ConverterCollection class with default-parameters.
Instantiation with new ConverterCollection(...)
must only be once and before any functions that require Singleton<ConverterCollection>.CurrentInstance
Definition at line 61 of file ConverterCollection.cs.
Core.TypeCast.ConverterCollection.ConverterCollection | ( | Type | application | ) |
Initializes a new instance of the ConverterCollection class with default-parameters.
Instantiation with new ConverterCollection(...)
must only be once and before any functions that require Singleton<ConverterCollection>.CurrentInstance
application | The TypeInfo.BaseType type which serves as the assembly entry point of the application e.g. Program |
Definition at line 72 of file ConverterCollection.cs.
Core.TypeCast.ConverterCollection.ConverterCollection | ( | Type | application, |
Type | converterClass, | ||
NumberFormatInfo | numberFormatDefault = null |
||
) |
Initializes a new instance of the ConverterCollection class with default-parameters.
Instantiation with new ConverterCollection(...)
must only be once and before any functions that require Singleton<ConverterCollection>.CurrentInstance
application | The TypeInfo.BaseType type which serves as the assembly entry point of the application e.g. Program |
converterClass | The type of a converter class to look for converters and load into the collection |
numberFormatDefault | An optional NumberFormatInfo to provide to any added converters for formatting. |
Definition at line 85 of file ConverterCollection.cs.
Core.TypeCast.ConverterCollection.ConverterCollection | ( | Assembly | assembly, |
NumberFormatInfo | numberFormatDefault = null |
||
) |
Initializes a new instance of the ConverterCollection class with default-parameters.
Instantiation with new ConverterCollection(...)
must only be once and before any functions that require Singleton<ConverterCollection>.CurrentInstance
assembly | An assembly to look for ConverterAttribute to discover and load converters into the collection |
numberFormatDefault | An optional NumberFormatInfo to provide to any added converters for formatting. |
Definition at line 97 of file ConverterCollection.cs.
Core.TypeCast.ConverterCollection.ConverterCollection | ( | Type | application = null , |
params Type[] | converterClasses | ||
) |
Initializes a new instance of the ConverterCollection class with default-parameters.
application | The TypeInfo.BaseType type which serves as the assembly entry point of the application e.g. Program |
converterClass | The type of a converter class to look for converters and load into the collection Items |
Definition at line 108 of file ConverterCollection.cs.
IConverterCollection Core.TypeCast.ConverterCollection.Add | ( | object | converterDelegate, |
Type | baseType = null , |
||
CancellationToken | cancellationToken = default(CancellationToken) |
||
) |
Initializes a new instance of the ConverterCollection class with default-parameters.
Example: Initialize a new ConverterCollection with several custom parameters, before any invocation of a ConverterCollection instance
application | The TypeInfo.BaseType type which serves as the assembly entry point of the application e.g. Program |
numberFormatDefault | An optional NumberFormatInfo to provide to any added converters for formatting. |
converterClass | The types of a converter classes to encapsulate in Converter instances and add into the collection Items |
*/ public ConverterCollection(Type application = null, NumberFormatInfo numberFormatDefault = null, params Type[] converterClasses) { this.Settings = new ConverterCollectionSettings(); this.loadOnDemandConverters = new Dictionary<string, List<Type>>();
this.Factory = new ConverterFactory(); this.FactoryBaseClass = new BaseClassFactoryRT();
this.AssemblyInitialized = new ConcurrentDictionary<Assembly, bool>(); this.ConverterClassInitialized = new ConcurrentDictionary<TypeInfo, bool>(); this.ConstructorAddedClasses = new List<Type>(); this.Items = new BlockingCollection<Converter>(boundedCapacity: this.Settings.BoundedCapacity);
if(application != null) { ApplicationNameSpace = application.Namespace; this.Initialize(ApplicationNameSpace); }
if(numberFormatDefault as NumberFormatInfo != null) { this.Settings.NumberFormat = numberFormatDefault; }
if(converterClasses != null) { foreach(var converterClass in converterClasses) { if(converterClass != null && converterClass.GetTypeInfo().IsClass == true) { ConstructorAddedClasses.Add(converterClass);
this.AddAllConvertersByAttribute(converterClass.GetTypeInfo()); } } }
// Load any declared converters from the own assembly this.Initialize(this.GetType().GetTypeInfo()?.Assembly.DefinedTypes); }
/**
Reference to the ConverterFactory which facilitates the instantiation of any Converter
*/ public ConverterFactory Factory { get; }
/**
Reference to the runtime-creation BaseClassFactoryRT which facilitates the instantiation of any class which declares a converter function and has a ConverterAttribute
*/ public BaseClassFactoryRT FactoryBaseClass { get; }
/**
Stores the namespace of the application namespace. May be set during auto-initialization loading
*/ public string ApplicationNameSpace { get; set; }
/**
Stores a list of classes that were passed into the constructor as a params list of types and have been added to Items
*/ public List<Type> ConstructorAddedClasses { get; }
/**
Stores a list of assemblies which have been scanned for attributes and added to Items
*/ public ConcurrentDictionary<Assembly, bool> AssemblyInitialized { get; }
/**
Stores a list of the types of Converter function declaring-classes which have been instantiated and added to Items
*/ public ConcurrentDictionary<TypeInfo, bool> ConverterClassInitialized { get; }
/**
Gets the count of singletons in the list.
``` var singletonManager = new SingletonManager(new[]{typeof(ParentOfAClass), typeof(IndispensibleClass)});
singletonManager.PropertyChanged += (singleton, arg) => { if(singletonManager.Count < singletonManager.Pool.Count() ){ Console.WriteLine("A Singleton was added to the Manager"); }else{ Console.WriteLine("A Singleton was removed from the Manager"); } } ```
*/ public int Count { get { return this.Items.Count; }
private set { if(value != this.count) { OnPropertyChanged(); this.count = value; } } }
/**
The BlockingCollection<Converter> class provides a thread-safe collection with full support of the Producer-Consumer pattern, to store a collection of Converter instances.
*/ public BlockingCollection<Converter> Items { get; }
/**
Marks the T:System.Collections.Concurrent.BlockingCollection`1 instances as not accepting any more additions.
T:System.ObjectDisposedException | The T:System.Collections.Concurrent.BlockingCollection`1 has been disposed. |
*/ public bool IsAddingCompleted { get { return this.Items.IsAddingCompleted; } set { if(value == true) { this.Items.CompleteAdding(); }
} }
/**
Gets the type of the element(s) that are returned when the expression tree associated with this instance of System.Linq.IQueryable is executed.
*/ public Type ElementType { get { return this.Items.AsQueryable().ElementType; } }
/**
Gets the expression tree that is associated with the instance of System.Linq.IQueryable.
*/ public Expression Expression { get { return this.Items.AsQueryable().Expression; } }
/**
Gets the query provider that is associated with this data source.
*/ public IQueryProvider Provider { get { return this.Items.AsQueryable().Provider; } }
/**
Gets the value for a given index using System.Linq
index | The integer index of the elements starting at zero. |
null
.*/ public Converter this[int index] { get { return this.Items?.Skip(index)?.FirstOrDefault(); } }
/**
Gets a Converter for a given Key by invoking Get(TypeInfo, TypeInfo). If none is found, null
is returned.
null
.*/ public Converter this[Type typeFrom, Type typeTo] { get { return this.Get(typeFrom.GetTypeInfo(), typeTo.GetTypeInfo()); } }
/**
Gets a Converter for a given Key by invoking Get(TypeInfo, TypeInfo). If none is found, null
is returned.
null
.*/ public Converter this[TypeInfo typeFrom, TypeInfo typeTo] { get { return this.Get(typeFrom, typeTo); } }
/**
Looks up all converters that match the source-type argument typeFrom and returns an IEnumerable<Converter>
typeFrom | The source Type to look up in Items |
null
.*/ public IEnumerable<Converter> this[TypeInfo typeFrom] { get { return this.WithFrom(typeFrom); } }
/**
Allows to perform a deferred adding operation of multiple adds using a common Base-Class Type argument, common ConverterCollectionSettings as well as a mutual CancellationToken for the added group of converters. The operation is applied upon invoking End, and can be explicitly canceled by invoking Cancel
TBase | The declaring Type of the converter-functions to add as a group. |
settings | Optional common ConverterCollectionSettings to be applied for the added group of converter-functions |
cancellationToken | Optional mutual CancellationToken to be used for the grouped-adding of converter-functions |
*/ public AddBuilder<TBase> AddStart<TBase>(ConverterCollectionSettings settings = null, CancellationToken cancellationToken = default(CancellationToken)) where TBase : class { return new AddBuilder<TBase>(this, settings: settings, cancellationToken: ref cancellationToken); }
/**
Allows to perform a deferred adding operation of multiple adds using a common Base-Class Type argument, common ConverterCollectionSettings as well as a mutual CancellationToken for the added group of converters. The operation is applied upon invoking End, and can be explicitly canceled by invoking Cancel
TBase | The declaring Type of the converter-functions to add as a group. |
settings | Common ConverterCollectionSettings to be applied for the added group of converter-functions |
cancellationToken | Mutual CancellationToken to be used for the grouped-adding of converter-functions |
*/ public AddBuilder<TBase> AddStart<TBase>(ConverterCollectionSettings settings, ref CancellationToken cancellationToken) where TBase : class { return new AddBuilder<TBase>(this, settings: settings, cancellationToken: ref cancellationToken); }
/**
Creates and adds a Converter instance to the collection of ConverterCollection.Items using a Delegate
converterAction | A function delegate Func<TIn, TOut> to use as the Converter.Function |
cancellationToken | Optional token to propagate notification that operations should be canceled. From System.Threading.Tasks. |
baseType | The Type of the declaring and attributed custom converter class, if one exists |
TIn | The Source- / From- Typefrom which to Converter<TIn,TOut>.Convert(object,object) |
TOut | The Target / To- Type to which to Converter<TIn,TOut>.Convert(object,object) |
ConverterException | Throws a ConverterCause.ConverterCollectionAddFailed with a wrapped Exception.InnerException if an internal error occurred |
*/ public IConverterCollection Add<TIn, TOut>( Func<TIn, TOut> converterAction, Type baseType = null, CancellationToken cancellationToken = default(CancellationToken)) { var converter = Factory.Create<TIn, TOut>(converterAction); return this.Add(converter: converter, baseType: baseType, cancellationToken: cancellationToken); }
/**
Creates and adds a pair of Converter instances to the collection of ConverterCollection.Items using a Delegate, which together form an Inter-converter, for mutual conversion between two types in either conversion direction.
converterActionForward | A source-to-target Type converting function delegate Func<TIn, TOut> to use as the Converter.Function |
converterActionBackward | A target-to-source Type converting function delegate Func<TOut, TIn> to use as the Converter.Function |
cancellationToken | Optional token to propagate notification that operations should be canceled. From System.Threading.Tasks. |
baseType | The Type of the declaring and attributed custom converter class, if one exists |
TIn | The Source- / From- Typefrom which to Converter<TIn,TOut>.Convert(object,object) |
TOut | The Target / To- Type to which to Converter<TIn,TOut>.Convert(object,object) |
ConverterException | Throws a ConverterCause.ConverterCollectionAddFailed with a wrapped Exception.InnerException if an internal error occurred |
*/ public IConverterCollection Add<TIn, TOut>( Func<TIn, TOut> converterActionForward, Func<TOut, TIn> converterActionBackward, Type baseType = null, CancellationToken cancellationToken = default(CancellationToken)) { this.Add(converterAction: converterActionForward, baseType: baseType, cancellationToken: cancellationToken); return this.Add(converterAction: converterActionBackward, baseType: baseType, cancellationToken: cancellationToken); }
/**
Creates and adds a Converter instance to the collection of ConverterCollection.Items using a Delegate
TIn | The Source- / From- Typefrom which to Converter<TIn,TOut>.Convert(object,object) |
TOut | The Target / To- Type to which to Converter<TIn,TOut>.Convert(object,object) |
TBase | The Type of the declaring and attributed custom converter class |
converterAction | A function delegate Func<TIn, TOut> to use as the Converter.Function |
cancellationToken | Optional token to propagate notification that operations should be canceled. From System.Threading.Tasks. |
ConverterException | Throws a ConverterCause.ConverterCollectionAddFailed with a wrapped Exception.InnerException if an internal error occurred |
*/ public IConverterCollection Add<TIn, TOut, TBase>(Func<TIn, TOut> converterAction, CancellationToken cancellationToken = default(CancellationToken)) where TBase : class { var converter = Factory.Create<TIn, TOut>(converterAction); return this.Add(converter: converter, baseType: typeof(TBase), cancellationToken: cancellationToken); }
/**
Creates and adds a Converter instance to the collection of ConverterCollection.Items using a Delegate
TIn | The Source- / From- Typefrom which to Converter<TIn,TOut>.Convert(object,object) |
TOut | The Target / To- Type to which to Converter<TIn,TOut>.Convert(object,object) |
converterActionDefault | A function delegate Func<TIn, TOut, TOut> to use as the Converter.Function |
cancellationToken | Optional token to propagate notification that operations should be canceled. From System.Threading.Tasks. |
ConverterException | Throws a ConverterCause.ConverterCollectionAddFailed with a wrapped Exception.InnerException if an internal error occurred |
*/ public IConverterCollection Add<TIn, TOut, TBase>( Func<TIn, TOut, TOut> converterActionDefault, CancellationToken cancellationToken = default(CancellationToken)) where TBase : class { var converter = Factory.Create<TIn, TOut>(converterActionDefault); return this.Add(converter: converter, baseType: typeof(TBase), cancellationToken: cancellationToken); }
/**
Creates and adds a Converter instance to the collection of ConverterCollection.Items using a Delegate
converterActionAny | A function delegate Func<TIn, TArg, TOut> to use as the Converter.Function |
cancellationToken | Optional token to propagate notification that operations should be canceled. From System.Threading.Tasks. |
TIn | The Source- / From- Typefrom which to Converter<TIn,TOut>.Convert(object,object) |
TOut | The Target / To- Type to which to Converter<TIn,TOut>.Convert(object,object) |
TArg | The Argument Type for generic converters using see ObjectExtension.ConvertTo<TIn, TOut>(TIn, object). |
TBase | The Type of the declaring and attributed custom converter class, if one exists |
ConverterException | Throws a ConverterCause.ConverterCollectionAddFailed with a wrapped Exception.InnerException if an internal error occurred |
*/ public IConverterCollection Add<TIn, TArg, TOut, TBase>( Func<TIn, TArg, TOut> converterActionAny, CancellationToken cancellationToken = default(CancellationToken)) { if(typeof(TOut) == typeof(TArg)) { var converter = Factory.Create<TIn, TOut>((Func<TIn, TOut, TOut>)(object)converterActionAny); return this.Add(converter: converter, baseType: typeof(TBase), cancellationToken: cancellationToken); } return this.Add(converterDelegate: converterActionAny, baseType: typeof(TBase), cancellationToken: cancellationToken); }
/**
Creates and adds a Converter instance to the collection of ConverterCollection.Items using a Delegate
converterActionAny | A function delegate Func<TIn, TArg, TOut> to use as the Converter.Function |
baseType | The Type of the declaring and attributed custom converter class, if one exists |
cancellationToken | Optional token to propagate notification that operations should be canceled. From System.Threading.Tasks. |
TIn | The Source- / From- Typefrom which to Converter<TIn,TOut>.Convert(object,object) | ||
TOut | The Target / To- Type to which to Converter<TIn,TOut>.Convert(object,object) | ||
TArg | The Argument Type for generic converters using see ObjectExtension.ConvertTo<TIn, TOut>(TIn, object).
|
/**
Creates and adds a Converter instance to the collection of ConverterCollection.Items using a Delegate
converterDelegate | An optional function delegate to use as the Converter.Function |
cancellationToken | Optional token to propagate notification that operations should be canceled. From System.Threading.Tasks. |
ConverterException | Throws a ConverterCause.ConverterCollectionAddFailed with a wrapped Exception.InnerException if an internal error occurred |
*/ public IConverterCollection Add<TBase>(object converterDelegate, CancellationToken cancellationToken = default(CancellationToken)) where TBase : class { return this.Add(converterDelegate: converterDelegate, baseType: typeof(TBase), cancellationToken: cancellationToken); }
/**
Creates and adds a Converter instance to the collection of ConverterCollection.Items using a Delegate
converterDelegate | An optional function delegate to use as the Converter.Function |
baseType | The Type of the declaring and attributed custom converter class, if one exists |
cancellationToken | Optional token to propagate notification that operations should be canceled. From System.Threading.Tasks. |
Example: Add a converter to the ConverterCollection cc
, to converter Nullable<int>
to float
Any lambda function or strictly declared function can be added as converterDelegate . For more information visit the MSDN recommendations on lambda expressions: https://msdn.microsoft.com/en-us/library/bb397687.aspx
ConverterException | Throws a ConverterCause.ConverterCollectionAddFailed with a wrapped Exception.InnerException if an internal error occurred |
Implements Core.TypeCast.IConverterCollection.
Definition at line 551 of file ConverterCollection.cs.
IConverterCollection Core.TypeCast.ConverterCollection.Add | ( | MethodInfo | methodInfo, |
object | converterDelegate = null , |
||
Type | baseType = null , |
||
object | baseInstance = null , |
||
CancellationToken | cancellationToken = default(CancellationToken) |
||
) |
Creates and adds a Converter instance to the collection of ConverterCollection.Items using a MethodInfo instance
methodInfo | A MethodInfo instance describing a method to create a delegate from and add to the converter |
converterDelegate | An optional function delegate to use as the Converter.Function |
baseType | The Type of the declaring and attributed custom converter class, if one exists |
baseInstance | An optional base-class instance containing a method which is added to the converter and seves as this reference during invocation. |
cancellationToken | Optional token to propagate notification that operations should be canceled. From System.Threading.Tasks. |
ConverterException | Throws an exception if adding failed |
Definition at line 581 of file ConverterCollection.cs.
IConverterCollection Core.TypeCast.ConverterCollection.Add | ( | Converter | converter, |
Type | baseType = null , |
||
bool | allowDisambiguates = false , |
||
CancellationToken | cancellationToken = default(CancellationToken) |
||
) |
Adds a Converter instance to the collection of ConverterCollection.Items
converter | The Converter instance to add to the ConverterCollection.Items |
baseType | The Type of the declaring and attributed custom converter class, if one exists |
allowDisambiguates | Optional bool value to indicate whether to allow multiple converters with the same return and parameter Types in the collection of Items. Only set to true for transform functions. |
cancellationToken | Optional token to propagate notification that operations should be canceled. From System.Threading.Tasks. |
ConverterCollectionException | Throws an exception if adding failed |
Implements Core.TypeCast.IConverterCollection.
Definition at line 609 of file ConverterCollection.cs.
|
inherited |
Creates and adds a Converter instance to the collection of ConverterCollection.Items using a Delegate
converterDelegate | An optional function delegate to use as the Converter.Function |
cancellationToken | Optional token to propagate notification that operations should be canceled. From System.Threading.Tasks. |
ConverterException | Throws a ConverterCause.ConverterCollectionAddFailed with a wrapped Exception.InnerException if an internal error occurred |
TBase | : | class |
|
inherited |
Creates and adds a Converter instance to the collection of ConverterCollection.Items using a Delegate
TIn | The Source- / From- Typefrom which to Converter<TIn,TOut>.Convert(object,object) | ||||||||
TOut | The Target / To- Type to which to Converter<TIn,TOut>.Convert(object,object) | ||||||||
TArg | The Argument Type for generic converters using see ObjectExtension.ConvertTo<TIn, TOut>(TIn, object).
|
|
inherited |
Creates and adds a Converter instance to the collection of ConverterCollection.Items using a Delegate
TIn | The Source- / From- Typefrom which to Converter<TIn,TOut>.Convert(object,object) |
TOut | The Target / To- Type to which to Converter<TIn,TOut>.Convert(object,object) |
converterAction | A function delegate Func<TIn, TOut> to use as the Converter.Function |
cancellationToken | Optional token to propagate notification that operations should be canceled. From System.Threading.Tasks. |
ConverterException | Throws a ConverterCause.ConverterCollectionAddFailed with a wrapped Exception.InnerException if an internal error occurred |
|
inherited |
Creates and adds a Converter instance to the collection of ConverterCollection.Items using a Delegate
TIn | The Source- / From- Typefrom which to Converter<TIn,TOut>.Convert(object,object) |
TOut | The Target / To- Type to which to Converter<TIn,TOut>.Convert(object,object) |
TBase | The Type of the declaring and attributed custom converter class |
converterAction | A function delegate Func<TIn, TOut> to use as the Converter.Function |
cancellationToken | Optional token to propagate notification that operations should be canceled. From System.Threading.Tasks. |
ConverterException | Throws a ConverterCause.ConverterCollectionAddFailed with a wrapped Exception.InnerException if an internal error occurred |
TBase | : | class |
|
inherited |
Creates and adds a Converter instance to the collection of ConverterCollection.Items using a Delegate
TIn | The Source- / From- Typefrom which to Converter<TIn,TOut>.Convert(object,object) |
TOut | The Target / To- Type to which to Converter<TIn,TOut>.Convert(object,object) |
converterActionDefault | A function delegate Func<TIn, TOut, TOut> to use as the Converter.Function |
baseType | The Type of the declaring and attributed custom converter class, if one exists |
cancellationToken | Optional token to propagate notification that operations should be canceled. From System.Threading.Tasks. |
ConverterException | Throws a ConverterCause.ConverterCollectionAddFailed with a wrapped Exception.InnerException if an internal error occurred |
TBase | : | class |
|
static |
Checks if the ConverterCollection is initialized. Attempts to initialize and load the user-assembly if ConverterCollection.Initialized is false
ConverterException | If the Reflection required for the Initialization failed an exception is caused of exception-cause: ConverterCause.ConverterAutoInitializationFailed |
Definition at line 776 of file ConverterCollection.cs.
bool Core.TypeCast.ConverterCollection.CanConvertFrom | ( | Type | typeFrom | ) |
Returns bool true
if the ConverterCollection supports conversion for a given Type typeFrom , else false
.
typeFrom | The source Type to look up in Items |
The function is a wrapper for ConverterCollectionFilters.WithFrom(IQueryable<Converter>, TypeInfo).
true
if the source Type is supported as source type by any converter in the ConverterCollection, else false
Definition at line 676 of file ConverterCollection.cs.
bool Core.TypeCast.ConverterCollection.CanConvertFrom< TIn > | ( | ) |
Returns bool true
if the ConverterCollection supports conversion for a given Type typeFrom , else false
.
TIn | The source Type to look up in Items |
The function is a wrapper for ConverterCollectionFilters.WithFrom(IQueryable<Converter>, TypeInfo).
true
if the source Type is supported as source type by any converter in the ConverterCollection, else false
Definition at line 687 of file ConverterCollection.cs.
bool Core.TypeCast.ConverterCollection.CanConvertTo | ( | Type | typeTo | ) |
Returns bool true
if the ConverterCollection supports conversion for a given Type typeTo , else false
.
typeTo | The target Type to look up in Items |
The function is a wrapper for ConverterCollectionFilters.WithTo(IQueryable<Converter>, TypeInfo).
true
if the target Type is supported as source type by any converter in the ConverterCollection, else false
Definition at line 698 of file ConverterCollection.cs.
bool Core.TypeCast.ConverterCollection.CanConvertTo< TOut > | ( | ) |
Returns bool true
if the ConverterCollection supports conversion for a given Type typeTo , else false
.
TIn | The target Type to look up in Items |
The function is a wrapper for ConverterCollectionFilters.WithTo(IQueryable<Converter>, TypeInfo).
true
if the target Type is supported as source type by any converter in the ConverterCollection, else false
Definition at line 709 of file ConverterCollection.cs.
ConverterAttribute Core.TypeCast.ConverterCollection.ConverterAttributeFromIConverter | ( | TypeInfo | baseType, |
ConverterAttribute | attribute = null , |
||
bool | update = false |
||
) |
Adds or updates an attribute for a Converter if it exists, dependent only on the source and target conversion types
baseType | The Type of the declaring and attributed custom converter class Type if one exists |
attribute | The ConverterAttribute of the converter-class that is to be updated |
update | Whether to update an existing Converter.Attribute |
true
Definition at line 721 of file ConverterCollection.cs.
|
protected |
Dispose of the Items and underlying static Singleton<TClass> references.
disposing | The state of the object disposal, to avoid unnecessary invocations during the disposing invocation. |
Invocation is only required in a few rare cases
warning CA2213 can be ignored: http://stackoverflow.com/questions/34583417/code-analysis-warning-ca2213-call-dispose-on-idisposable-backing-field
Definition at line 910 of file ConverterCollection.cs.
IEnumerator<Converter> Core.TypeCast.ConverterCollection.GetEnumerator | ( | ) |
Returns an enumerator that iterates through the collection.
Definition at line 1038 of file ConverterCollection.cs.
void Core.TypeCast.ConverterCollection.Initialize | ( | string | applicationNameSpace | ) |
Initializes all attributed Converter classes, Initialize(Assembly[])
applicationNameSpace | The class that holds the entry point of the application. Usually public static Main(){...} |
Example:
Definition at line 813 of file ConverterCollection.cs.
void Core.TypeCast.ConverterCollection.Initialize | ( | Type | applicationClass | ) |
Initializes all attributed Converter classes, Initialize(Assembly[])
applicationClass | The class that holds the entry point of the application. Usually public static Main(){...} |
Example:
Definition at line 832 of file ConverterCollection.cs.
void Core.TypeCast.ConverterCollection.Initialize | ( | Assembly | assembly | ) |
Initializes all attributed Converter classes, Initialize(Assembly[])
assembly | The Assembly to look for attributed Converter classes |
Example:
Definition at line 852 of file ConverterCollection.cs.
void Core.TypeCast.ConverterCollection.Initialize | ( | Assembly[] | assemblies | ) |
Initializes all attributed Converter classes, unless the ConverterAttribute parameter ConverterAttribute.LoadOnDemand is false
assemblies | An Array of Assembly to look for ConverterAttribute to discover and add converters into the collection |
Example:
Definition at line 869 of file ConverterCollection.cs.
void Core.TypeCast.ConverterCollection.Initialize | ( | IEnumerable< TypeInfo > | types | ) |
Initializes all attributed Converter classes, unless the ConverterAttribute parameter ConverterAttribute.LoadOnDemand is false
types | The Array of Assembly within to look for attributed Converter classes |
Example:
Definition at line 894 of file ConverterCollection.cs.
int Core.TypeCast.ConverterCollection.LoadOnDemandConverter | ( | Type | typeTo | ) |
Tries to lookup the namespace obtained from typeTo in loadOnDemandConverters and add the converters. If successful the number of Added Converters are returned, and the NameSpace is removed from the list of loadOnDemandConverters.
typeTo | The converter target Type to obtain the namespace from. |
Any compatible Converter.Standard converters will have merged after loading, as such the returned number of loaded converters does not have a direct relationship to the Count
0
if the Converters of the namespace from typeTo were successfully added, otherwise returns 0
Definition at line 750 of file ConverterCollection.cs.
|
protected |
Sets the Assembly as initialized in AssemblyInitialized
type | The TypeInfo instance from which to lookup the TypeInfo.Assembly |
Definition at line 921 of file ConverterCollection.cs.
|
protected |
Sets the Converter of the ConverterCollection as initialized
converterClass | The class instance of a custom converter implementation that is to be marked initialized |
true
if the concurrent dictionary update succeededThe class can support IConverter
Definition at line 932 of file ConverterCollection.cs.
|
getinherited |
Sets the Assembly as initialized in AssemblyInitialized
type | the TypeInfo instance from which to lookup the TypeInfo.Assembly |
Definition at line 25 of file IConverterCollection.cs.
|
getinherited |
Gets the count of singletons in the list.
Definition at line 34 of file IConverterCollection.cs.
|
getinherited |
The BlockingCollection<Converter> class provides a thread-safe collection with full support of the Producer-Consumer pattern, to store a collection of Converter instances.
Definition at line 31 of file IConverterCollection.cs.
|
getset |
The settings for the ConverterCollection.
Definition at line 44 of file ConverterCollection.cs.