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

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...

+ Collaboration diagram for Core.TypeCast.ConverterAttribute:

Public Member Functions

 ConverterAttribute (string nameSpace="", string name="", bool loadOnDemand=false, bool dependencyInjection=false)
 Initializes a new instance of the ConverterAttribute class, to declare a custom Converter More...
 
 ConverterAttribute (string nameSpace, Enum name, bool loadOnDemand=false, bool dependencyInjection=false)
 

Properties

Guid Id [get]
 Gets a unique ID of the converter based on an underlying Guid. More...
 
TypeInfo BaseType [get, set]
 Gets or sets the base type i.e. the declaring type (see: Type.DeclaringType containing or declaring the converter-functions. More...
 
bool DependencInjection [get, set]
 Gets or sets a value indicating whether dependency injection should be used during instancing of a new custom converter />. More...
 

Detailed Description

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

The attribute provides collective initialization through the ConverterCollection class.

Example:

@code{cs}
[Converter(loadOnDemand: false, nameSpace: nameof(Program.NameSpace))]
public class StringToDNA : IConverter, IConverter<string, DNA>{
...
public StringToDNA(IConverterCollection collection){ ... collection.Add((Func<string, DNA>)this.Convert); ...}
public object Convert(object valueIn){ ... }
public DNA Convert(string valueIn) { ... }
[ConverterMethod]
public object ToProtein(string valueIn){
}
...
}
@endcode

Definition at line 42 of file ConverterAttribute.cs.

Constructor & Destructor Documentation

Core.TypeCast.ConverterAttribute.ConverterAttribute ( string  nameSpace = "",
string  name = "",
bool  loadOnDemand = false,
bool  dependencyInjection = false 
)

Initializes a new instance of the ConverterAttribute class, to declare a custom Converter

Parameters
loadOnDemandSet to true to allow joint initialization by the lazy instancing of the ConverterCollection Core.Singleton
nameSpaceThe namespace as a string, ideally set via the nameof operator to group converters and enable lazy-loading upon first use.
nameA custom label for the converter or null if none is set, particularly used for Transform function disambiguates (i.e. identical In/Out parameters)
dependencyInjectionWhether the declaring converter class is instantiated via dependency Injection.

Definition at line 51 of file ConverterAttribute.cs.

52  {
53  this.Id = Guid.NewGuid();
54  this.LoadOnDemand = loadOnDemand;
55  this.NameSpace = nameSpace ?? string.Empty;
56  this.Name = name ?? string.Empty;
57  this.DependencInjection = dependencyInjection;
58  }
bool DependencInjection
Gets or sets a value indicating whether dependency injection should be used during instancing of a ne...
Guid Id
Gets a unique ID of the converter based on an underlying Guid.
Core.TypeCast.ConverterAttribute.ConverterAttribute ( string  nameSpace,
Enum  name,
bool  loadOnDemand = false,
bool  dependencyInjection = false 
)

Definition at line 61 of file ConverterAttribute.cs.

62  : this(loadOnDemand: loadOnDemand, nameSpace: nameSpace, name: name.ToString(), dependencyInjection: dependencyInjection)
63  {
64  }

Property Documentation

TypeInfo Core.TypeCast.ConverterAttribute.BaseType
getset

Gets or sets the base type i.e. the declaring type (see: Type.DeclaringType containing or declaring the converter-functions.

Definition at line 75 of file ConverterAttribute.cs.

bool Core.TypeCast.ConverterAttribute.DependencInjection
getset

Gets or sets a value indicating whether dependency injection should be used during instancing of a new custom converter />.

Definition at line 80 of file ConverterAttribute.cs.

Guid Core.TypeCast.ConverterAttribute.Id
get

Gets a unique ID of the converter based on an underlying Guid.

Definition at line 70 of file ConverterAttribute.cs.


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