9 namespace Core.TypeCast.Base
12 using System.Diagnostics;
13 using System.Reflection;
14 using System.Runtime.Serialization;
20 [DebuggerDisplay(
"{DebuggerDisplay,nq}")]
21 [DataContract(IsReference =
false, Name =
"BaseConverter", Namespace = nameof(Base))]
41 this.From = from?.GetTypeInfo();
42 this.To = to?.GetTypeInfo();
43 this.Argument = argument?.GetTypeInfo();
44 this.BaseType = baseType?.GetTypeInfo();
47 this.Attribute = attribute;
48 this.NameSpace = attribute.NameSpace;
55 public TypeInfo Argument {
get;
set; }
61 public virtual TypeInfo ArgumentStandard {
get; } = typeof(
object).GetTypeInfo();
70 return this.attribute;
74 this.attribute = value;
79 public object Base {
get;
set; }
84 public TypeInfo BaseType {
get;
set; }
94 public bool AllowDisambiguates {
get;
set; }
102 public bool DefaultValueAnyType {
get;
set; }
106 public TypeInfo From {
get;
private set; }
112 public object Function {
get;
set; }
119 protected MethodInfo FunctionInfo {
get;
set; }
135 public object FunctionDefault {
get;
set; }
142 protected MethodInfo FunctionDefaultInfo {
get;
set; }
153 public bool HasDefaultFunction
157 return this.FunctionDefault != null && this.FunctionDefault is Delegate;
163 public bool HasDefaultFunctionOnly
167 return this.Function == null && this.HasDefaultFunction;
173 public bool HasFunction
177 return (this.Function ?? this.FunctionDefault) != null && (this.Function ?? this.FunctionDefault) is Delegate;
195 if(typeof(MulticastDelegate).GetTypeInfo().IsAssignableFrom(this.BaseType) ==
true)
199 return ((this.HasDefaultFunction ==
true) && (this.Argument == this.To))
200 || ((this.HasDefaultFunctionOnly ==
false) && (this.HasFunction ==
true) && (this.Argument == this.To || this.Argument == this.ArgumentStandard));
212 public string NameSpace {
get;
private set; }
216 public TypeInfo To {
get;
private set; }
225 public bool UseFunctionDefaultWrapper {
get;
set; }
240 private string DebuggerDisplay
244 return this.ToString();
255 public abstract object Convert(
object value,
object defaultValue = null);
263 $
"{this.GetType().Name}[({this.From?.Name}, {this.Argument?.Name}) => {this.To?.Name}] BaseType: {this.BaseType?.Name}, Attribute: {this.Attribute}";
273 if(fullName ==
false)
275 return this.ToString();
279 $
"{this.GetType().FullName}[({this.From?.FullName}, {this.Argument?.FullName}) => {this.To?.FullName}] BaseType: {this.BaseType?.FullName}, Attribute: {this.Attribute}";
286 protected abstract void CheckConvertTypes(
object value,
object defaultValue);
string ToString(bool fullName)
Overrides object.ToString() to provide information about the conversion types
override string ToString()
Overrides object.ToString() to provide a string representation of the underlying conversion types...
Use ConverterAttribute to declare a class as a logical Type Converter. As such the only contingent de...
Use ConverterMethodAttribute to declare a method in an arbitrary class as a logical Converter functio...
The Base Converter interface.
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.
The Converter base class, providing a simple container for conversion types, ConverterAttribute and c...