.NET Portable TypeCast  3.1.0.4
A, easy-to-use tested, generic, portable, runtime-extensible, arbitrary type converter library
ConverterAttribute.cs
Go to the documentation of this file.
1 // <copyright file=mitlicense.md url=http://lsauer.mit-license.org/ >
2 // Lo Sauer, 2016
3 // </copyright>
4 // <summary> A generic, portable and easy to use Converter pattern library </summary
5 // <language> C# > 6.0 </language>
6 // <version> 3.1.0.2 </version>
7 // <author> Lo Sauer; people credited in the sources </author>
8 // <project> https://github.com/lsauer/csharp-Converter </project>
9 namespace Core.TypeCast
10 {
11  using System;
12  using System.Diagnostics.CodeAnalysis;
13  using System.Reflection;
14  using System.Runtime.CompilerServices;
15  using Base;
16 
41  [AttributeUsage(AttributeTargets.Class | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
42  public sealed class ConverterAttribute : Attribute
43  {
51  public ConverterAttribute(string nameSpace = "", string name = "", bool loadOnDemand = false, bool dependencyInjection = false)
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  }
59 
60  [MethodImpl(MethodImplOptions.AggressiveInlining)]
61  public ConverterAttribute(string nameSpace, Enum name, bool loadOnDemand = false, bool dependencyInjection = false)
62  : this(loadOnDemand: loadOnDemand, nameSpace: nameSpace, name: name.ToString(), dependencyInjection: dependencyInjection)
63  {
64  }
65 
66 
70  public Guid Id { get; }
71 
75  public TypeInfo BaseType { get; set; }
76 
80  public bool DependencInjection { get; set; }
81 
97  public bool LoadOnDemand { get; }
98 
116  public string NameSpace { get; }
117 
118 
123  public string Name { get; set; }
124 
125  public override string ToString()
126  {
127  return $"[LoD:{this.LoadOnDemand},Base:{this.BaseType?.Name},DepInj:{this.DependencInjection},NamSp:{this.NameSpace},Name:{this.Name}]";
128  }
129 
130  }
131 }
ConverterAttribute(string nameSpace="", string name="", bool loadOnDemand=false, bool dependencyInjection=false)
Initializes a new instance of the ConverterAttribute class, to declare a custom Converter ...
ConverterAttribute(string nameSpace, Enum name, bool loadOnDemand=false, bool dependencyInjection=false)
Use ConverterAttribute to declare a class as a logical Type Converter. As such the only contingent de...