Transformations 0.0.38

dotnet add package Transformations --version 0.0.38
NuGet\Install-Package Transformations -Version 0.0.38
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Transformations" Version="0.0.38" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Transformations --version 0.0.38
#r "nuget: Transformations, 0.0.38"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Transformations as a Cake Addin
#addin nuget:?package=Transformations&version=0.0.38

// Install Transformations as a Cake Tool
#tool nuget:?package=Transformations&version=0.0.38

Conversion between data types. Envisaged as a possible alternative to the Universal Type Converter http://www.codeproject.com/Articles/248440/Universal-Type-Converter, with the provision for default values, and some extra features.

Product Compatible and additional computed target framework versions.
.NET Framework net is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

This package has no dependencies.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
0.0.38 72 5/7/2015
0.0.37 73 5/7/2015
0.0.36 59 5/7/2015
0.0.35 63 5/7/2015
0.0.34 69 5/7/2015
0.0.33 53 5/7/2015
0.0.32 72 5/6/2015
0.0.31 62 5/6/2015
0.0.30 65 5/6/2015
0.0.29 66 5/6/2015
0.0.28 52 5/6/2015
0.0.27 67 5/5/2015
0.0.26 71 5/5/2015
0.0.25 71 4/27/2015
0.0.24 67 4/24/2015
0.0.23 86 4/23/2015
0.0.22 88 4/2/2015
0.0.21 64 4/2/2015
0.0.20 74 4/1/2015
0.0.19 67 3/31/2015
0.0.18 67 3/31/2015
0.0.17 62 3/31/2015
0.0.16 71 3/31/2015
0.0.15 67 3/31/2015
0.0.14 55 3/31/2015
0.0.13 61 3/31/2015
0.0.12 74 3/30/2015
0.0.11 68 3/30/2015
0.0.10 62 3/30/2015
0.0.9 67 3/30/2015
0.0.8 53 3/30/2015
0.0.7 61 3/30/2015
0.0.6 140 5/2/2014
0.0.5 90 5/2/2014
0.0.4 87 4/24/2014
0.0.3 91 4/23/2014
0.0.2 64 4/23/2014
0.0.1 104 4/17/2014

* You don't need to reference the transformations namespace with Using statement (type conversions are meant to be universal if you choose to use this).

Generally you would just do:

 var newValue = oldValue.ConvertTo<newType>(optionalDefaultValue);

* You can use TryConvertTo if you need to get the result of the conversion process.

* You can do some conversions on DataTables and Lists , for example convert a data table to an object list, if the names of the columns match the object properties.

* The date conversion is set to British date format by default, not the project's current format. This may have to change to make the library more "universal".

* From some basic tests I have performed on universal type converter and this library, I found it to be a bit faster than the universal type converter...

********************************************
Some examples of use:
********************************************
string valueInput = "7F8C14B6-B3A8-4F71-8EFC-E5A7B35923B6";
Guid actual = valueInput.ConvertTo<Guid>(Guid.Empty);
// -----------------------------------------------
string valueInput = "0.1";
float actual = valueInput.ConvertTo<float>(0.0f);
// result = 0.1f;
// -----------------------------------------------
string valueInput = "15/02/2014";
DateTime actual = valueInput.ConvertTo<DateTime>(new DateTime(2000, 01, 01));
// result = new DateTime(2014, 02, 15);
// -----------------------------------------------
float? f = 123.524f;
int? i = f.ConvertTo<int>();
// result = 124;
// -----------------------------------------------

* You can convert date to 'excel'-type value:
DateTime d = new DateTime(2005, 5, 5);
d.ToDouble();
// or d.ToInt();

List conversions examples:
// -----------------------------------------------
List<int> l1 = new List<int>(new int[] { 2, 3, 4 });
List<float> l2 = l1.ConvertToList<int, float>();
// -----------------------------------------------



**************************************************

Some additional helper methods are added as extensions as well:

// -----------------------------------------------

*Proper Case*

string name = "mr john smith";
name.ProperCase();
// result = "Mr John Smith";

// -----------------------------------------------

*Insert Spaces*

string name = "MrJohnSmith";
name.InsertSpaces();
// result = "Mr John Smith";

// -----------------------------------------------

*Remove Chars* - removes multiple instances of the same string pattern from the string.

string name = "Mr John John Smith";
name.RemoveChars("John ");
// result = "Mr Smith";

// -----------------------------------------------

*Replace Ex* - replace multiple instances of the same string pattern in the string.
string s = "12345678901234567890";
s.ReplaceEx("2", "X");
// result = "1X345678901X34567890";

// -----------------------------------------------

*Is Date* - check if string is a date! assumes en-Gb as default culture at present..

string s = "14/02/2014";
if (IsDate(s))
{ ... }
if (IsDate(s, "en-GB"))
{ ... }

// -----------------------------------------------

New in version 22: I have recently added .ToSqlParameter() extension methods.

It makes it easier to effectively make the swift conversion to SqlParameters from most types, but please always check that the correct SqlDbType is supplied...

For example, if you wanted to supply myChar parameter to a stored procedure - a char conversion could be:

char c = 'a';
c.ToSqlParameter('myChar');
- and you would probably want to add SqlParameter to the list of parameters.

When converting a string to a varchar / nvarchar, a size of the string is required. It's usually the best practice to supply the string size to avoid runtime errors.

I'm thinking of adding a completely separate validation method to SqlParameter list, which will test that each conversion can be performed correctly.