Transformations 0.0.38
dotnet add package Transformations --version 0.0.38
NuGet\Install-Package Transformations -Version 0.0.38
<PackageReference Include="Transformations" Version="0.0.38" />
paket add Transformations --version 0.0.38
#r "nuget: Transformations, 0.0.38"
// 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 | Versions Compatible and additional computed target framework versions. |
---|---|
.NET Framework | net is compatible. |
This package has no dependencies.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
0.0.38 | 74 | 5/7/2015 |
0.0.37 | 74 | 5/7/2015 |
0.0.36 | 61 | 5/7/2015 |
0.0.35 | 67 | 5/7/2015 |
0.0.34 | 71 | 5/7/2015 |
0.0.33 | 55 | 5/7/2015 |
0.0.32 | 74 | 5/6/2015 |
0.0.31 | 65 | 5/6/2015 |
0.0.30 | 67 | 5/6/2015 |
0.0.29 | 69 | 5/6/2015 |
0.0.28 | 54 | 5/6/2015 |
0.0.27 | 69 | 5/5/2015 |
0.0.26 | 72 | 5/5/2015 |
0.0.25 | 73 | 4/27/2015 |
0.0.24 | 69 | 4/24/2015 |
0.0.23 | 88 | 4/23/2015 |
0.0.22 | 92 | 4/2/2015 |
0.0.21 | 66 | 4/2/2015 |
0.0.20 | 76 | 4/1/2015 |
0.0.19 | 71 | 3/31/2015 |
0.0.18 | 69 | 3/31/2015 |
0.0.17 | 63 | 3/31/2015 |
0.0.16 | 72 | 3/31/2015 |
0.0.15 | 68 | 3/31/2015 |
0.0.14 | 56 | 3/31/2015 |
0.0.13 | 62 | 3/31/2015 |
0.0.12 | 75 | 3/30/2015 |
0.0.11 | 70 | 3/30/2015 |
0.0.10 | 63 | 3/30/2015 |
0.0.9 | 68 | 3/30/2015 |
0.0.8 | 54 | 3/30/2015 |
0.0.7 | 62 | 3/30/2015 |
0.0.6 | 141 | 5/2/2014 |
0.0.5 | 91 | 5/2/2014 |
0.0.4 | 91 | 4/24/2014 |
0.0.3 | 95 | 4/23/2014 |
0.0.2 | 65 | 4/23/2014 |
0.0.1 | 105 | 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.