Transformations 1.0.1

dotnet add package Transformations --version 1.0.1
                    
NuGet\Install-Package Transformations -Version 1.0.1
                    
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="1.0.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Transformations" Version="1.0.1" />
                    
Directory.Packages.props
<PackageReference Include="Transformations" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Transformations --version 1.0.1
                    
#r "nuget: Transformations, 1.0.1"
                    
#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.
#:package Transformations@1.0.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Transformations&version=1.0.1
                    
Install as a Cake Addin
#tool nuget:?package=Transformations&version=1.0.1
                    
Install as a Cake Tool
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
.NET Core netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.1 is compatible. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETStandard 2.1

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.1 580 4/17/2023
1.0.0 963 3/25/2020
0.0.145 3,127 7/4/2017
0.0.144 2,887 5/19/2017
0.0.143 2,831 5/18/2017
0.0.142 2,856 5/16/2017
0.0.140 3,336 11/4/2016
0.0.139 3,167 11/4/2016
0.0.138 3,112 11/3/2016
0.0.137 3,099 11/3/2016
0.0.136 3,144 11/3/2016
0.0.135 3,101 11/2/2016
0.0.134 3,068 11/2/2016
0.0.133 3,092 11/2/2016
0.0.132 3,104 11/2/2016
0.0.131 3,160 11/2/2016
0.0.130 2,995 11/2/2016
0.0.129 3,032 12/14/2015
0.0.128 3,164 12/11/2015
0.0.127 2,941 12/10/2015
0.0.126 3,209 12/9/2015
0.0.125 2,988 11/20/2015
0.0.124 2,939 11/20/2015
0.0.123 2,955 11/20/2015
0.0.122 2,987 11/20/2015
0.0.121 2,972 11/20/2015
0.0.120 2,987 11/20/2015
0.0.119 2,985 11/17/2015
0.0.118 3,020 11/17/2015
0.0.117 3,005 11/17/2015
0.0.116 2,982 11/17/2015
0.0.115 2,970 11/17/2015
0.0.114 3,632 11/16/2015
0.0.113 2,925 11/16/2015
0.0.112 3,100 11/16/2015
0.0.111 2,968 11/12/2015
0.0.110 2,917 11/12/2015
0.0.109 2,906 11/3/2015
0.0.108 2,932 11/3/2015
0.0.107 2,964 11/3/2015
0.0.106 2,962 11/2/2015
0.0.105 2,934 11/2/2015
0.0.104 2,908 10/30/2015
0.0.103 2,930 10/30/2015
0.0.102 2,930 10/30/2015
0.0.101 2,928 10/30/2015
0.0.100 2,926 10/30/2015
0.0.99 2,892 10/23/2015
0.0.98 2,923 10/23/2015
0.0.97 2,919 10/19/2015
0.0.96 2,932 10/16/2015
0.0.95 2,985 10/16/2015
0.0.94 2,890 10/16/2015
0.0.93 2,938 10/16/2015
0.0.92 2,921 10/13/2015
0.0.91 2,949 10/13/2015
0.0.90 2,940 10/13/2015
0.0.89 3,010 9/16/2015
0.0.88 2,968 9/16/2015
0.0.87 3,001 8/20/2015
0.0.86 2,905 8/17/2015
0.0.85 3,264 8/6/2015
0.0.84 3,106 7/29/2015
0.0.83 3,117 7/29/2015
0.0.82 3,118 7/29/2015
0.0.81 3,073 7/28/2015
0.0.80 3,092 7/28/2015
0.0.79 3,036 7/27/2015
0.0.78 3,036 7/20/2015
0.0.77 3,090 7/20/2015
0.0.76 2,972 7/10/2015
0.0.75 2,946 7/10/2015
0.0.74 2,976 7/2/2015
0.0.73 2,975 7/2/2015
0.0.72 2,949 6/29/2015
0.0.71 2,926 6/29/2015
0.0.70 2,930 6/24/2015
0.0.69 2,953 6/23/2015
0.0.68 2,981 6/23/2015
0.0.67 2,967 6/22/2015
0.0.66 2,975 6/22/2015
0.0.65 2,950 6/5/2015
0.0.64 2,998 6/4/2015
0.0.63 2,965 6/4/2015
0.0.62 2,957 6/3/2015
0.0.61 2,993 6/2/2015
0.0.60 2,924 6/2/2015
0.0.59 3,253 6/1/2015
0.0.58 2,886 6/1/2015
0.0.57 3,280 6/1/2015
0.0.56 3,648 6/1/2015
0.0.55 2,924 5/29/2015
0.0.53 2,953 5/27/2015
0.0.52 2,893 5/27/2015
0.0.51 2,958 5/22/2015
0.0.50 2,939 5/21/2015
0.0.49 2,951 5/20/2015
0.0.48 2,954 5/20/2015
0.0.47 2,971 5/20/2015
0.0.46 2,939 5/20/2015
0.0.45 2,957 5/19/2015
0.0.44 2,948 5/19/2015
0.0.43 2,940 5/15/2015
0.0.42 2,902 5/14/2015
0.0.41 2,906 5/13/2015
0.0.40 2,936 5/12/2015
0.0.39 2,956 5/11/2015
0.0.38 2,950 5/7/2015
0.0.37 2,901 5/7/2015
0.0.36 2,925 5/7/2015
0.0.35 2,939 5/7/2015
0.0.34 2,904 5/7/2015
0.0.33 3,031 5/7/2015
0.0.32 2,926 5/6/2015
0.0.31 3,030 5/6/2015
0.0.30 2,929 5/6/2015
0.0.29 2,948 5/6/2015
0.0.28 3,029 5/6/2015
0.0.27 3,043 5/5/2015
0.0.26 2,926 5/5/2015
0.0.25 3,065 4/27/2015
0.0.24 3,077 4/24/2015
0.0.23 3,541 4/23/2015
0.0.22 3,363 4/2/2015
0.0.21 2,958 4/2/2015
0.0.20 2,981 4/1/2015
0.0.19 3,023 3/31/2015
0.0.18 3,070 3/31/2015
0.0.17 3,053 3/31/2015
0.0.16 3,021 3/31/2015
0.0.15 2,985 3/31/2015
0.0.14 3,023 3/31/2015
0.0.13 2,996 3/31/2015
0.0.12 2,925 3/30/2015
0.0.11 2,951 3/30/2015
0.0.10 2,960 3/30/2015

* 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&lt;newType&gt;(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&lt;Guid&gt;(Guid.Empty);
// where Guid.Empty is the default value if the conversion fails.
// -----------------------------------------------
string valueInput = "0.1";
float actual = valueInput.ConvertTo&lt;float&gt;(0.0f);
// where 0.0f is the default value if the conversion fails.
// result = 0.1f;
// -----------------------------------------------
string valueInput = "15/02/2014";
DateTime actual = valueInput.ConvertTo&lt;DateTime&gt;(new DateTime(2000, 01, 01));
// where 2000-01-01 is the default value if the conversion fails.
// result = new DateTime(2014, 02, 15);
// -----------------------------------------------
float? f = 123.524f;
int? i = f.ConvertTo&lt;int&gt;();
// 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&lt;int&gt; l1 = new List&lt;int&gt;(new int[] { 2, 3, 4 });
List&lt;float&gt; l2 = l1.ConvertToList&lt;int, float&gt;();
// -----------------------------------------------



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

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"))
{ ... }

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

.ToSqlParameter() extension methods make 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.

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


Added DataTable.HasRows()
// ie: dataTable != null &amp;&amp; dataTable.Rows.Count &gt; 0

Added DataRow.GetValue&lt;T&gt;()
- Gets the value as required type.

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

New:

Added Some Enum extensions, eg:

YourEnum.EnumElement.ToByte()
// gives an int enum for this enum

Same applies to
[...].ToDecimal()
[...].ToDouble()
[...].ToInt()
[...].ToLong()
etc.