.NET Portable TypeCast  3.1.0.4
A, easy-to-use tested, generic, portable, runtime-extensible, arbitrary type converter library
Core.TypeCast.Base.Converter Class Referenceabstract

The Converter base class, providing a simple container for conversion types, ConverterAttribute and corresponding conversion functions More...

+ Collaboration diagram for Core.TypeCast.Base.Converter:

Public Member Functions

abstract object Convert (object value, object defaultValue=null)
 The converter function as part of the IConverter interface support. More...
 
override string ToString ()
 Overrides object.ToString() to provide a string representation of the underlying conversion types More...
 
string ToString (bool fullName)
 Overrides object.ToString() to provide information about the conversion types More...
 

Protected Member Functions

 Converter (Type from, Type to, Type argument=null, Type baseType=null, ConverterAttribute attribute=null)
 Initializes a new instance of the Core.TypeCast.Base.Converter class. More...
 
abstract void CheckConvertTypes (object value, object defaultValue)
 Checks the types being in the correct source and target format, if not an Exception is thrown. More...
 

Properties

TypeInfo Argument [get, set]
 The

See also
Type

of the argument passed to Converter.FunctionDefault More...

 
virtual TypeInfo ArgumentStandard [get]
 Returns true if the Argument-Typeis the default value object. As all converters are contained in strongly typed Converter<TIn, TOut, TArg> 's the argument is set to object if unused. However explicit conversion to the object is still possible. More...
 
ConverterAttribute Attribute = typeof(object).GetTypeInfo() [get, set]
 Gets or sets the ConverterAttribute if the custom converter class has one defined, else it is set null. More...
 
object Base [get, set]
 Gets the reference to the Base instance of Type BaseType if one exists, otherwise the value is null. More...
 
TypeInfo BaseType [get, set]
 Gets the underlying Type of the custom converter class if one exists, otherwise the value is null. More...
 
IConverterCollection Collection [get, set]
 Gets or sets the underlying ConverterCollection if the converter has been added to one, otherwise the value is null. More...
 
bool AllowDisambiguates [get, set]
 Optional bool value to indicate whether a ConverterCollection is allowed to contain multiple converters with the same source and target Types in the collection of Items. Only set to true for transform functions. More...
 
bool DefaultValueAnyType [get, set]
 Gets or sets a value indicating whether the second argument of Converter.FunctionDefault is Type-checked to enforce type quality with the return Type of the Function More...
 
TypeInfo From [get]
 Gets the Type of the object instance which is to be converted. More...
 
object Function [get, set]
 The boxed converter function of Type.DeclaringType IConverter<TIn,TOut>.Convert More...
 
MethodInfo FunctionInfo [get, set]
 Gets an instance of MethodInfo describing the Function. May be null if the converter constructor was not passed a MethodInfo instance. More...
 
ConverterMethodAttribute FunctionAttribute [get, set]
 Gets an instance of ConverterMethodAttribute of the Function if it exists. May also be null if the attribute property has not been set. More...
 
object FunctionDefault [get, set]
 The boxed converter function with an additional second argument value that allows passing a any arbitrary or default-value which may be returned in case of conversion failure or the conversion result yielding null. It may also be used as an essential argument for ObjectExtension.ConvertTo<TIn, TOut>(TIn, object) More...
 
MethodInfo FunctionDefaultInfo [get, set]
 Gets an instance of MethodInfo describing the FunctionDefault. May be null if the converter constructor was not passed a MethodInfo instance. More...
 
ConverterMethodAttribute FunctionDefaultAttribute [get, set]
 Gets an instance of ConverterMethodAttribute of the FunctionDefault if it exists. May also be null if the attribute property has not been set. More...
 
bool HasDefaultFunction [get]
 Gets a value indicating whether the converter has a FunctionDefault set. More...
 
bool HasDefaultFunctionOnly [get]
 Gets a value indicating whether the converter has only a FunctionDefault set. More...
 
bool HasFunction [get]
 Gets a value indicating whether the converter has either Function or FunctionDefault set. More...
 
bool Standard [get]
 Gets a value indicating whether the Converter instance is strictly typed such that the

See also
Argument

Type is set to the Type of To. More...

 
string NameSpace [get]
 Gets the Type.Namespace that the Converter instance is assigned to, with the possibility of many converters declaring the same namespace , that is using a one to many relationship. The handling of the NameSpace lies within the responsibility of the ConverterCollection More...
 
TypeInfo To [get]
 Gets the Type that the instance will be converted to. More...
 
bool UseFunctionDefaultWrapper [get, set]
 Gets or sets a value indicating whether to use a default-value wrapper function if a default-value was passed but no conversion function taking a default-value exists More...
 

Detailed Description

The Converter base class, providing a simple container for conversion types, ConverterAttribute and corresponding conversion functions

The Converter is usually invoked through ObjectExtension.CastTo<TOut> and ObjectExtension.TryCast<TIn,TOut>

See also
Converter<TIn,TOut>, ConverterCollection

Definition at line 22 of file Converter.cs.

Constructor & Destructor Documentation

Core.TypeCast.Base.Converter.Converter ( Type  from,
Type  to,
Type  argument = null,
Type  baseType = null,
ConverterAttribute  attribute = null 
)
protected

Initializes a new instance of the Core.TypeCast.Base.Converter class.

Parameters
fromThe source/from conversion Type
toThe target/to conversion Type
argumentThe
See also
Type
of the argument passed to Converter.FunctionDefault
baseTypeThe Type of any underlying converter class if one exists
attributeThe ConverterAttribute of the converter-class if present.

Only invoked by Converter<TIn,TOut>

See also
Converter<TIn,TOut>

Definition at line 39 of file Converter.cs.

40  {
41  this.From = from?.GetTypeInfo();
42  this.To = to?.GetTypeInfo();
43  this.Argument = argument?.GetTypeInfo();
44  this.BaseType = baseType?.GetTypeInfo();
45  if(attribute != null)
46  {
47  this.Attribute = attribute;
48  this.NameSpace = attribute.NameSpace;
49  }
50  }
TypeInfo BaseType
Gets the underlying Type of the custom converter class if one exists, otherwise the value is null...
Definition: Converter.cs:84
TypeInfo From
Gets the Type of the object instance which is to be converted.
Definition: Converter.cs:106
TypeInfo To
Gets the Type that the instance will be converted to.
Definition: Converter.cs:216
ConverterAttribute Attribute
Gets or sets the ConverterAttribute if the custom converter class has one defined, else it is set null.
Definition: Converter.cs:67
TypeInfo Argument
The Typeof the argument passed to Converter.FunctionDefault
Definition: Converter.cs:55
string NameSpace
Gets the Type.Namespace that the Converter instance is assigned to, with the possibility of many conv...
Definition: Converter.cs:212

Member Function Documentation

abstract void Core.TypeCast.Base.Converter.CheckConvertTypes ( object  value,
object  defaultValue 
)
protectedpure virtual

Checks the types being in the correct source and target format, if not an Exception is thrown.

Parameters
valueThe value to be converted.
defaultValueThe optional default value to be passed if the conversion fails or is null.
Exceptions
ConverterExceptionThrows exceptions based on mismatching types or null references

Implemented in Core.TypeCast.Converter< TIn, TOut, TArg >.

abstract object Core.TypeCast.Base.Converter.Convert ( object  value,
object  defaultValue = null 
)
pure virtual

The converter function as part of the IConverter interface support.

Parameters
valueThe value to be converted.
defaultValueThe optional default value to be passed if the conversion fails or is null.
Returns
The converted value as a boxed object.

The actual implementation and use of the second parameter lies solely within the scope of the programmer implementing the converter logic

Implemented in Core.TypeCast.Converter< TIn, TOut, TArg >.

override string Core.TypeCast.Base.Converter.ToString ( )

Overrides object.ToString() to provide a string representation of the underlying conversion types

Returns
Returns a string containing information about the conversion types From and To as well as the BaseType

Definition at line 260 of file Converter.cs.

261  {
262  return
263  $"{this.GetType().Name}[({this.From?.Name}, {this.Argument?.Name}) => {this.To?.Name}] BaseType: {this.BaseType?.Name}, Attribute: {this.Attribute}";
264  }
string Core.TypeCast.Base.Converter.ToString ( bool  fullName)

Overrides object.ToString() to provide information about the conversion types

Parameters
fullNameWhether to show the full reflected name information
Returns
Returns a string containing information about the conversion types From and To as well as the BaseType
See also
ToString()

Definition at line 271 of file Converter.cs.

272  {
273  if(fullName == false)
274  {
275  return this.ToString();
276  }
277 
278  return
279  $"{this.GetType().FullName}[({this.From?.FullName}, {this.Argument?.FullName}) => {this.To?.FullName}] BaseType: {this.BaseType?.FullName}, Attribute: {this.Attribute}";
280  }
override string ToString()
Overrides object.ToString() to provide a string representation of the underlying conversion types...
Definition: Converter.cs:260

Property Documentation

bool Core.TypeCast.Base.Converter.AllowDisambiguates
getset

Optional bool value to indicate whether a ConverterCollection is allowed to contain multiple converters with the same source and target Types in the collection of Items. Only set to true for transform functions.

Definition at line 94 of file Converter.cs.

TypeInfo Core.TypeCast.Base.Converter.Argument
getset

The

See also
Type

of the argument passed to Converter.FunctionDefault

Definition at line 55 of file Converter.cs.

virtual TypeInfo Core.TypeCast.Base.Converter.ArgumentStandard
get

Returns true if the Argument-Typeis the default value object. As all converters are contained in strongly typed Converter<TIn, TOut, TArg> 's the argument is set to object if unused. However explicit conversion to the object is still possible.

Definition at line 61 of file Converter.cs.

ConverterAttribute Core.TypeCast.Base.Converter.Attribute = typeof(object).GetTypeInfo()
getset

Gets or sets the ConverterAttribute if the custom converter class has one defined, else it is set null.

The value is set once upon first access and is not updated thereafter, unless reset to null

See also
ConverterCollection.GetConverterAttributeFromIConverter(System.Reflection.TypeInfo,Core.TypeCast.ConverterAttribute,bool)

Definition at line 67 of file Converter.cs.

object Core.TypeCast.Base.Converter.Base
getset

Gets the reference to the Base instance of Type BaseType if one exists, otherwise the value is null.

Definition at line 79 of file Converter.cs.

TypeInfo Core.TypeCast.Base.Converter.BaseType
getset

Gets the underlying Type of the custom converter class if one exists, otherwise the value is null.

Definition at line 84 of file Converter.cs.

IConverterCollection Core.TypeCast.Base.Converter.Collection
getset

Gets or sets the underlying ConverterCollection if the converter has been added to one, otherwise the value is null.

Definition at line 87 of file Converter.cs.

bool Core.TypeCast.Base.Converter.DefaultValueAnyType
getset

Gets or sets a value indicating whether the second argument of Converter.FunctionDefault is Type-checked to enforce type quality with the return Type of the Function

See also
ConverterCollectionSettings.DefaultValueAnyType

Definition at line 102 of file Converter.cs.

TypeInfo Core.TypeCast.Base.Converter.From
get

Gets the Type of the object instance which is to be converted.

Definition at line 106 of file Converter.cs.

object Core.TypeCast.Base.Converter.Function
getset

The boxed converter function of Type.DeclaringType IConverter<TIn,TOut>.Convert

Returns
null if no function is set

Definition at line 112 of file Converter.cs.

ConverterMethodAttribute Core.TypeCast.Base.Converter.FunctionAttribute
getset

Gets an instance of ConverterMethodAttribute of the Function if it exists. May also be null if the attribute property has not been set.

Returns
null if no function is set

Definition at line 126 of file Converter.cs.

object Core.TypeCast.Base.Converter.FunctionDefault
getset

The boxed converter function with an additional second argument value that allows passing a any arbitrary or default-value which may be returned in case of conversion failure or the conversion result yielding null. It may also be used as an essential argument for ObjectExtension.ConvertTo<TIn, TOut>(TIn, object)

Returns
null if no function is set

The actual implementation and use of the second parameter lies solely within the scope of the programmer implementing the converter logic

Definition at line 135 of file Converter.cs.

ConverterMethodAttribute Core.TypeCast.Base.Converter.FunctionDefaultAttribute
getset

Gets an instance of ConverterMethodAttribute of the FunctionDefault if it exists. May also be null if the attribute property has not been set.

Returns
null if no function is set

Definition at line 149 of file Converter.cs.

MethodInfo Core.TypeCast.Base.Converter.FunctionDefaultInfo
getsetprotected

Gets an instance of MethodInfo describing the FunctionDefault. May be null if the converter constructor was not passed a MethodInfo instance.

Returns
null if no function is set

Definition at line 142 of file Converter.cs.

MethodInfo Core.TypeCast.Base.Converter.FunctionInfo
getsetprotected

Gets an instance of MethodInfo describing the Function. May be null if the converter constructor was not passed a MethodInfo instance.

Returns
null if no function is set

Definition at line 119 of file Converter.cs.

bool Core.TypeCast.Base.Converter.HasDefaultFunction
get

Gets a value indicating whether the converter has a FunctionDefault set.

Definition at line 154 of file Converter.cs.

bool Core.TypeCast.Base.Converter.HasDefaultFunctionOnly
get

Gets a value indicating whether the converter has only a FunctionDefault set.

Definition at line 164 of file Converter.cs.

bool Core.TypeCast.Base.Converter.HasFunction
get

Gets a value indicating whether the converter has either Function or FunctionDefault set.

Definition at line 174 of file Converter.cs.

string Core.TypeCast.Base.Converter.NameSpace
get

Gets the Type.Namespace that the Converter instance is assigned to, with the possibility of many converters declaring the same namespace , that is using a one to many relationship. The handling of the NameSpace lies within the responsibility of the ConverterCollection

The namespace is used for grouping, filtering and on-demand loading purposes.

See also
ConverterAttribute.LoadOnDemand

Definition at line 212 of file Converter.cs.

bool Core.TypeCast.Base.Converter.Standard
get

Gets a value indicating whether the Converter instance is strictly typed such that the

See also
Argument

Type is set to the Type of To.

See also
Converter<TIn,TOut>, Converter<TIn,TOut,TArg>, FunctionDefault

inherits from . Due to the strictly-typed nature of the converter instances the is only passes a default-value if the passed value is of the same type as To. This property allows quick lookups.

Definition at line 192 of file Converter.cs.

TypeInfo Core.TypeCast.Base.Converter.To
get

Gets the Type that the instance will be converted to.

Definition at line 216 of file Converter.cs.

bool Core.TypeCast.Base.Converter.UseFunctionDefaultWrapper
getset

Gets or sets a value indicating whether to use a default-value wrapper function if a default-value was passed but no conversion function taking a default-value exists

See also
ConverterCollectionSettings.UseFunctionDefaultWrapper, FunctionDefault

Definition at line 225 of file Converter.cs.


The documentation for this class was generated from the following file: