.NET Portable TypeCast  3.1.0.4
A, easy-to-use tested, generic, portable, runtime-extensible, arbitrary type converter library
ConverterParameters.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 namespace Core.TypeCast
10 {
11  using System;
12  using System.Reflection;
13  using System.Runtime.InteropServices;
14  using System.Linq;
15 
19  [StructLayout(LayoutKind.Sequential)]
20  public struct ConverterParameters
21  {
22  public int Count;
23  public Type In;
24  public Type Out;
25  public Type Arg;
26 
43  public ConverterParameters(ParameterInfo parameterOut, ParameterInfo[] parameters)
44  : this(parameters: new[] { parameters?.First(), parameterOut, parameters?.Length > 1 ? parameters[1] : parameterOut } )
45  {
46  }
47 
57  public ConverterParameters(params ParameterInfo[] parameters)
58  {
59  this.Count = parameters.Length;
60  this.In = Count > 0 ? parameters[0].ParameterType : null;
61  this.Out = Count > 1 ? parameters[1].ParameterType : null;
62  // with only In/Out parameters assigned i.e. the argument type is null, use `Out` as an argument-type
63  this.Arg = Count > 2 ? parameters[2].ParameterType : this.Out;
64  }
65 
70  public Type[] ToArray()
71  {
72  return new[] { this.In, this.Out, this.Arg };
73  }
74 
79  public override string ToString()
80  {
81  return $"{nameof(ConverterParameters)}: (In:{this.In}, Out:{this.Out}, Arg:{this.Arg})";
82  }
83  }
84 }
Container with sequentially assigned type-parameters of a strictly typed Converter-Function, in the sequence of Types for: In, Out, Argument