.NET Portable TypeCast  3.1.0.4
A, easy-to-use tested, generic, portable, runtime-extensible, arbitrary type converter library
ConvertContext.cs
Go to the documentation of this file.
1 // <copyright file=mitlicense.md url=http://lsauer.mit-license.org/ >
2 // Lo Sauer, 2013-2016
3 // </copyright>
4 // <summary> A tested, generic, portable, runtime-extensible type converter library </summary
5 // <language> C# > 6.0 </language>
6 // <version> 3.1.0.2 </version>
7 // <author> Lorenz Lo Sauer; people credited in the sources </author>
8 // <project> https://github.com/lsauer/dotnet-portable-type-cast </project>
9 using System.Reflection;
10 using System.Linq;
11 using System;
12 
13 using System.Runtime.CompilerServices;
14 using System.Runtime.InteropServices;
15 
16 namespace Core.TypeCast.Base
17 {
18  using System.Collections.Generic;
19  using System.Text;
20  using Extensions;
21 
22 
26  public class ConvertContext<TIn, TOut> : ConvertContext
27  {
32  public ConvertContext(object modelValue)
33  : base(modelValue)
34  {
35  this.From = typeof(TIn);
36  this.To = typeof(TOut);
37  }
38  }
39 
44  public class ConvertContext : IConvertContext
45  {
50  public ConvertContext(object modelValue)
51  {
52  this.Value = modelValue;
53  }
54 
58  public Type From { get; set; }
59 
63  public Type To { get; set; }
64 
68  public Type Argument { get; set; }
69 
73  public object Value { get; }
74 
78  public Converter Converter { get; set; }
79 
83  public string Caller { get; set; }
84 
88  public bool? Nullable { get; set; }
89 
93  public bool? ThrowExceptions { get; set; }
94 
98  public object Method { get; set; }
99 
103  public MethodInfo MethodInfo { get; set; }
104 
111  public override string ToString()
112  {
113  var ret = new StringBuilder("{" + Environment.NewLine);
114  foreach(var property in this.GetType().GetRuntimeProperties())
115  {
116  ret.Append($"\t {property.Name} {{{property.PropertyType}}}: '{property.GetValue(this)}'" + Environment.NewLine);
117  }
118  return ret.ToString() + "}";
119  }
120  }
121 
122 
123 }
override string ToString()
A string representation of the current instance.
ConvertContext(object modelValue)
Creates a new instance of ConvertContext<TIn, TOut>
The common IConvertContext interface.
Wraps the model value for the converter in a conversion-context
The Converter base class, providing a simple container for conversion types, ConverterAttribute and c...
Definition: Converter.cs:22