.NET Portable TypeCast  3.1.0.4
A, easy-to-use tested, generic, portable, runtime-extensible, arbitrary type converter library
Core.TypeCast Namespace Reference

Namespaces

namespace  Base
 
namespace  Converters
 

Classes

class  Converter
 The generic, strictly-typed converter class, for type casting and simple conversions. More...
 
class  ConverterAttribute
 Use ConverterAttribute to declare a class as a logical Type Converter. As such the only contingent declaration contract requirement is adherence to implement a public constructor which takes a IConverterCollection collection parameter More...
 
class  ConverterCollection
 The thread-safe, static collection of Converter items, using Core.Singleton and supporting Core.Singleton.ISingleton More...
 
class  ConverterCollectionException
 The Exception-type which is raised exclusively by the Converter<T> Library More...
 
class  ConverterCollectionFilters
 A set of IQueryable<Converter> extension methods for filtering ConverterCollection items using System.Linq
 
class  ConverterCollectionLookup
 A set of IQueryable<Converter> extension methods for filtering ConverterCollection items using System.Linq
 
class  ConverterCollectionSettings
 The settings for the ConverterCollection. More...
 
class  ConverterException
 The Exception-type which is raised exclusively by the Converter<TIn,TOut> Library More...
 
class  ConverterExtension
 The Converter extension methods
 
class  ConverterMethodAttribute
 Use ConverterMethodAttribute to declare a method in an arbitrary class as a logical Converter function. The only restriction towards the attributed method is a maximum of two defined function parameters. This limitation is by design, to advocate the use of the single responsibility principle, and building complex converters out of smaller ones, as implemented by a different library. Take a look at the examples and documentation for more information. More...
 
struct  ConverterParameters
 Container with sequentially assigned type-parameters of a strictly typed Converter-Function, in the sequence of Types for: In, Out, Argument More...
 
class  DependencyInjectionException
 The Exception-type which is raised exclusively by the DependencyInjection<TDependency> class More...
 
interface  IConvertContext
 The common IConvertContext interface. More...
 
interface  IConverter
 The Base Converter interface. More...
 
interface  IConverterCollection
 
interface  IException
 The common Exceptioninterface. More...
 
interface  IFactory
 The generic, common factory interface for declaring factories creating arbitrary object instances requiring up to two arguments. Use a container type such as Tuple or struct as second parameter TIn2 if more parameters are required. More...
 
interface  IRepository
 The base repository interface More...
 
interface  IRepositoryEnumerable
 The generic repository interface with one lookup identifier More...
 
class  ObjectExtension
 The object extension methods to convert an object of an unrestricted unknown type TIn to an unrestricted known type TOut.
 

Enumerations

enum  ConverterCause : ulong {
  ConverterCause.None = 0,
  ConverterCause.Unknown = 1 << 0,
  ConverterCause.Default = 1 << 1,
  ConverterCause.ConverterFunctionNull = 1 << 2,
  ConverterCause.ConverterArgumentNull = 1 << 3,
  ConverterCause.ConverterArgumentGenericType = 1 << 4,
  ConverterCause.ConverterArgumentWrongType = 1 << 5,
  ConverterCause.ConverterExists = 1 << 6,
  ConverterCause.ConvertFailed = 1 << 7,
  ConverterCause.ConverterWrapperError = 1 << 8,
  ConverterCause.InternalError = 1 << 9,
  ConverterCause.ConstructorInjectionNull = 1 << 10,
  ConverterCause.ConverterCollectionAddFailed = 1 << 11,
  ConverterCause.InstanceRequiresParameters = 1 << 12,
  ConverterCause.ConverterNotImplemented = 1 << 13,
  ConverterCause.ConverterTypeInIsExplicitObject = 1 << 14,
  ConverterCause.ConverterArgumentDelegateTooManyParameters = 1 << 15,
  ConverterCause.ConverterArgumentDelegateNoParameters = 1 << 16,
  ConverterCause.ConverterAutoInitializationFailed = 1 << 17,
  ConverterCause.TransformRequiresEqualInOutTypes = 1 << 18,
  ConverterCause.InvalidCast = 1 << 19,
  ConverterCause.DelegateArgumentWrongType = 1 << 20,
  ConverterCause.LogicError = 1 << 21,
  ConverterCause.BadInputFormat = 1 << 21,
  ConverterCause.ConverterFunctionDefaultNull = Default | ConverterFunctionNull
}
 Contains the reasons for a ConverterException to be raised. More...
 
enum  ConverterCollectionCause {
  ConverterCollectionCause.None = 0,
  ConverterCollectionCause.Unknown = 1 << 0,
  ConverterCollectionCause.Default = 1 << 1,
  ConverterCollectionCause.InternalError = 1 << 2,
  ConverterCollectionCause.AddFailed = 1 << 3,
  ConverterCollectionCause.CollectionIsNull = 1 << 4,
  ConverterCollectionCause.ConverterExists = 1 << 5,
  ConverterCollectionCause.ConverterArgumentNull = 1 << 6,
  ConverterCollectionCause.ConverterArgumentWrongType = 1 << 7,
  ConverterCollectionCause.ConverterClassExists = 1 << 8,
  ConverterCollectionCause.InstanceRequiresParameters = 1 << 9,
  ConverterCollectionCause.ConverterFunctionsNull = 1 << 10,
  ConverterCollectionCause.AddFailedConverterExists = AddFailed | ConverterExists
}
 Contains the reasons for a ConverterCollectionException to be raised. More...
 

Class Documentation

class Core::TypeCast::Converter

The generic, strictly-typed converter class, for type casting and simple conversions.

Template Parameters
TInThe Source- / From- Typefrom which to Converter<TIn,TOut>.Convert(object,object)
TOutThe Target / To- Type to which to Converter<TIn,TOut>.Convert(object,object)

the class is declared sealed as the only converter implementation must be herein and no further implementation must be allowed, to enforce decoupling between arbitrary converter logic with a guaranteed implementation of the underlying converter-container in question

Definition at line 25 of file Converter_2T.cs.

+ Collaboration diagram for Core.TypeCast.Converter< TIn, TOut >:
struct Core::TypeCast::ConverterParameters

Container with sequentially assigned type-parameters of a strictly typed Converter-Function, in the sequence of Types for: In, Out, Argument

Definition at line 20 of file ConverterParameters.cs.

+ Collaboration diagram for Core.TypeCast.ConverterParameters:
Class Members
Type Arg
int Count
Type In
Type Out
interface Core::TypeCast::IRepository

The base repository interface

Implemented by any instantiable object which can provide data by passing an Identifier to facilitate lookup

Definition at line 18 of file IRepository.cs.

+ Collaboration diagram for Core.TypeCast.IRepository:
interface Core::TypeCast::IRepositoryEnumerable

The generic repository interface with one lookup identifier

Implemented by any instantiable object which can provide data by passing one Identifier to facilitate lookup

@code{cs}
ConverterCollection.CurrentInstance.Add( (int[] a, IModelWeather model) => {
...repo...
});
IRepositoryEnumerable<IModelWeather> repositoryQuery = new []{40420,52000,80801,20030}
.ConvertTo<IRepositoryEnumerable<IModelWeather>>( modelInstance );
foreach( var item in repositoryQuery)
{
...
}
@endcode
Type Constraints
TOut :IEnumerable 

Definition at line 31 of file IRepositoryEnumerable.cs.

+ Collaboration diagram for Core.TypeCast.IRepositoryEnumerable< out out TOut >:

Enumeration Type Documentation

enum Core.TypeCast.ConverterCause : ulong
strong

Contains the reasons for a ConverterException to be raised.

Enumerator
None 

Indicates the default or unspecified value

Unknown 

Indicates an unknown or undefined flag

Default 

Indicates a default or normal flag

ConverterFunctionNull 

Indicates that the Converter.Function property is not set and null

ConverterArgumentNull 

Indicates that the Converter<TIn, TOut> or an passed argument to a Converter method is null

ConverterArgumentGenericType 

Indicates a generic input type Converter.From was passed, whilst being explicitly disallowed in the ConverterCollectionSettings instance

ConverterArgumentWrongType 

Indicates that a Converter<TIn, TOut> method got passed an argument of a System.TypeT that does not match TIn or TOut respectively

ConverterExists 

Indicates that the Converter<TIn, TOut>, defined by the Input and Output conversion Types TIn --> TOut already exists

ConvertFailed 

Indicates that the Converter<TIn,TOut>.Convert(object,object) method failed near or at the custom convert Function invocation

ConverterWrapperError 

Indicates that the custom converter function wrapper yielded an error

See also
ConverterExtension.FunctionDefaultWrapper<TIn,TOut>(Core.TypeCast.Base.Converter)
InternalError 

Indicates an internal error state that may be specified further in the Exception.InnerException property

Can be raised when the Converter's constructor must be explicitly called with parameters

ConstructorInjectionNull 

Dependency Injection failed due to a null reference

Indicates that a conversion related class constructor was injected with an argument that is null

ConverterCollectionAddFailed 

The Converter could not be added to the ConverterCollection

The Converter instance was not added to the BlockingCollection<T> ConverterCollection.Items

See also
ConverterCollection.Add<TIn,TOut>(System.Func<TIn,TOut>,System.Type,System.Threading.CancellationToken)
InstanceRequiresParameters 

Indicates that the constructor of a parent Converter<TIn, TOut> class T requires parameters for proper instancing, yet was invoked parameter-less.

User-thrown exception in the custom parameter-less constructor of the logical Converter class

ConverterNotImplemented 

Indicates that a method in a converter or conversion-related class instance does not possess a logical implementation.

Make sure methods marked as virtual are overwritten.

ConverterTypeInIsExplicitObject 

Indicates that the conversion source type is set to object, which is not sensible. Omit setting both target type parameters instead

ConverterArgumentDelegateTooManyParameters 

Indicates that passed converter function takes too many parameters. A maximum of two is permitted.

ConverterArgumentDelegateNoParameters 

Indicates that the passed converter function takes no parameters. At least one up two a maximum of two is required.

ConverterAutoInitializationFailed 

Indicates that the reflection of the loading assembly failed, likely due to changes or security fixes for newer portable library class releases

TransformRequiresEqualInOutTypes 

Indicates that the source and target types do not match. If they do not match use other functions instead, like CastTo and ConvertTo.

InvalidCast 

Indicates that the cast failed, likely due to a missing converter. These exceptions can be suppressed with a function argument.

DelegateArgumentWrongType 

Indicates that the argument types of a given delegate do not match the return type and / or types of the provided parameters.

LogicError 

Indicates that the converter logic raised an InvalidOperationException, OverflowException or ArithmeticException which was caught.

BadInputFormat 

Indicates that the input argument was badly formatted.

ConverterFunctionDefaultNull 

Indicates a null-reference for an existing Converter default function

Flag Combinations

Definition at line 20 of file ConverterCause.cs.

20  : ulong
21  {
25  [Description("Indicates the default or unspecified value")]
26  None = 0,
27 
31  [Description("Indicates the default or unspecified value")]
32  Unknown = 1 << 0,
33 
37  [Description("Indicates the default or unspecified value")]
38  Default = 1 << 1,
39 
43  [Description("Indicates that the Converter function is not set and null")]
44  ConverterFunctionNull = 1 << 2,
45 
49  [Description("Indicates that the Converter or an passed argument to the converter is `null`")]
50  ConverterArgumentNull = 1 << 3,
51 
55  [Description("Indicates a generic input type was passed, whilst being explicitly disallowed in the ConverterCollectionSettings instance")]
57 
61  [Description("Indicates that a Converter method got passed an argument of a Type `T` that does not match TIn or TOut respectively")]
63 
67  [Description("Indicates that the Converter, defined by the Input and Output conversion Types TIn --> TOut already exists")]
68  ConverterExists = 1 << 6,
69 
73  [Description("Indicates that the convert method failed near or at the custom convert Function invocation ")]
74  ConvertFailed = 1 << 7,
75 
80  [Description("Indicates that the custom converter function wrapper yielded an error")]
81  ConverterWrapperError = 1 << 8,
82 
87  [Description("Indicates an internal error state that may be specified further in the InnerException property")]
88  InternalError = 1 << 9,
89 
94  [Description("Indicates that a conversion related class constructor was injected with an argument that is null")]
95  ConstructorInjectionNull = 1 << 10,
96 
102  [Description("The converter could not be added to the ConverterCollection")]
103  ConverterCollectionAddFailed = 1 << 11,
104 
109  [Description("Indicates that the constructor of a conversion-related class requires parameters for proper instancing, yet was invoked parameterless.")]
110  InstanceRequiresParameters = 1 << 12,
111 
116  [Description("Indicates that a method in a converter or conversion-related class instance does not possess a logical implementation.")]
117  ConverterNotImplemented = 1 << 13,
118 
122  [Description("Indicates that the conversion source type is set to object, which is not sensible. Omit setting both target type parameters instead")]
124 
128  [Description("Indicates that passed converter function takes too many parameters. A maximum of two is permitted.")]
130 
134  [Description("Indicates that the passed converter function takes no parameters. At least one up two a maximum of two is required.")]
136 
140  [Description("Indicates that the reflection of the loading assembly failed, likely due to changes or security fixes for newer portable library class releases")]
142 
146  [Description("Indicates that the source and target types do not match. If they do not match use other functions instead, like CastTo and ConvertTo.")]
148 
152  [Description("Indicates that the cast failed, likely due to a missing converter. These exceptions can be suppressed with a function argument.")]
153  InvalidCast = 1 << 19,
154 
158  [Description("Indicates that the argument types of a given delegate do not match the return type and / or types of the provided parameters.")]
159  DelegateArgumentWrongType = 1 << 20,
160 
161 
165  [Description("Indicates that the converter logic raised an `InvalidOperationException`, `OverflowException` or `ArithmeticException` which was caught.")]
166  LogicError = 1 << 21,
167 
171  [Description("Indicates that the input argument was badly formatted.")]
172  BadInputFormat = 1 << 21,
173 
179  [Description("Indicates a null-reference for an existing Converter default function")]
181  }
Indicates that a method in a converter or conversion-related class instance does not possess a logica...
Indicates that the constructor of a parent Converter<TIn, TOut> class T requires parameters for prope...
Indicates the default or unspecified value
The Converter could not be added to the ConverterCollection
Indicates an unknown or undefined flag
Indicates that passed converter function takes too many parameters. A maximum of two is permitted...
Indicates that the argument types of a given delegate do not match the return type and / or types of ...
Indicates that the input argument was badly formatted.
Dependency Injection failed due to a null reference
Indicates that the Converter<TIn, TOut> or an passed argument to a Converter method is null ...
Indicates an internal error state that may be specified further in the Exception.InnerException prope...
Indicates a generic input type Converter.From was passed, whilst being explicitly disallowed in the C...
Indicates a default or normal flag
Indicates that the source and target types do not match. If they do not match use other functions ins...
Indicates that the conversion source type is set to object, which is not sensible. Omit setting both target type parameters instead
Indicates that the converter logic raised an InvalidOperationException, OverflowException or Arithmet...
Indicates that the passed converter function takes no parameters. At least one up two a maximum of tw...
Indicates that the reflection of the loading assembly failed, likely due to changes or security fixes...
Indicates that the Converter<TIn,TOut>.Convert(object,object) method failed near or at the custom con...
Indicates that a Converter<TIn, TOut> method got passed an argument of a System.TypeT that does not m...
Indicates that the Converter.Function property is not set and null
Indicates that the Converter<TIn, TOut>, defined by the Input and Output conversion Types TIn --> TOu...
Indicates that the custom converter function wrapper yielded an error
Indicates a null-reference for an existing Converter default function
Indicates that the cast failed, likely due to a missing converter. These exceptions can be suppressed...

Contains the reasons for a ConverterCollectionException to be raised.

Enumerator
None 

Indicates the default or unspecified value

Unknown 

Indicates an unknown or undefined flag

Default 

Indicates a default or normal flag

InternalError 

Indicates an internal error state that may be specified further in the Exception.InnerException property

Can be raised when the Converter's constructor must be explicitly called with parameters

AddFailed 

The converter could not be added to the ConverterCollection

See also
ConverterCollection.Add<TIn,TOut>(System.Func<TIn,TOut>,System.Type,System.Threading.CancellationToken)
CollectionIsNull 

Indicates a null reference for the collection argument

ConverterExists 

Indicates that the Converter<TIn, TOut>, defined by the Input and Output conversion Types TIn --> TOut already exists

ConverterArgumentNull 

Indicates that the Converter<TIn, TOut> or an passed argument to a Converter method is null

ConverterArgumentWrongType 

Indicates that a ConverterCollection method got passed an argument of a System.TypeT that does not match TIn or TOut respectively

ConverterClassExists 

The custom converter / conversion-related class has already been instantiated and added to the to the ConverterCollection

InstanceRequiresParameters 

Indicates that the constructor the ConverterCollection class requires parameters for proper instancing, yet was invoked without parameters.

User-thrown exception in the custom parameter-less constructor of the logical Converter class

ConverterFunctionsNull 

Indicates that the Converter.Function property and Converter.FunctionDefault is not set to a Delegate and null

AddFailedConverterExists 

The converter could not be added to the ConverterCollection because another converter for the specified input/output types already exists

Flag Combinations

Definition at line 19 of file ConverterCollectionCause.cs.

20  {
24  [Description("Indicates the default or unspecified value")]
25  None = 0,
26 
30  [Description("Indicates the default or unspecified value")]
31  Unknown = 1 << 0,
32 
36  [Description("Indicates the default or unspecified value")]
37  Default = 1 << 1,
38 
43  [Description("Indicates an internal error state that may be specified further in the InnerException property")]
44  InternalError = 1 << 2,
45 
50  [Description("The converter could not be added to the ConverterCollection")]
51  AddFailed = 1 << 3,
52 
56  [Description("Indicates a null reference for the collection argument")]
57  CollectionIsNull = 1 << 4,
58 
62  [Description("Indicates that the Converter, defined by the Input and Output conversion Types TIn --> TOut already exists")]
63  ConverterExists = 1 << 5,
64 
68  [Description("Indicates that the Converter or an passed argument to the converter is `null`")]
69  ConverterArgumentNull = 1 << 6,
70 
74  [Description("Indicates that a ConverterCollection method got passed an argument of a Type `T` that does not match TIn or TOut respectively")]
76 
80  [Description("The custom converter / conversion-related class has already been instantiated and added to the to the ConverterCollection")]
81  ConverterClassExists = 1 << 8,
82 
87  [Description(
88  "Indicates that the constructor the ConverterCollection class requires parameters for proper instancing, yet was invoked without parameters")]
90 
94  [Description("Indicates that the Converter function and default-value function is not set to a Delegate and null")]
95  ConverterFunctionsNull = 1 << 10,
96 
102  [Description("Indicates a Converter already exists for the specified input and output Types and was thus not added to the ConverterCollection")]
104  }
The converter could not be added to the ConverterCollection because another converter for the specifi...
Indicates that the constructor of a parent Converter<TIn, TOut> class T requires parameters for prope...
Indicates the default or unspecified value
Indicates an unknown or undefined flag
The custom converter / conversion-related class has already been instantiated and added to the to the...
Indicates that the Converter<TIn, TOut> or an passed argument to a Converter method is null ...
Indicates that the Converter.Function property and Converter.FunctionDefault is not set to a Delegate...
The converter could not be added to the ConverterCollection
Indicates an internal error state that may be specified further in the Exception.InnerException prope...
Indicates a null reference for the collection argument
Indicates a default or normal flag
Indicates that a Converter<TIn, TOut> method got passed an argument of a System.TypeT that does not m...
Indicates that the Converter<TIn, TOut>, defined by the Input and Output conversion Types TIn --> TOu...