Transformations 0.0.145

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.

Install-Package Transformations -Version 0.0.145
dotnet add package Transformations --version 0.0.145
<PackageReference Include="Transformations" Version="0.0.145" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Transformations --version 0.0.145
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

Release Notes

* 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);
// where Guid.Empty is the default value if the conversion fails.
// -----------------------------------------------
string valueInput = "0.1";
float actual = valueInput.ConvertTo<float>(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<DateTime>(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<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"))
{ ... }

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

.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 && dataTable.Rows.Count > 0

Added DataRow.GetValue<T>()
- 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.

Dependencies

This package has no dependencies.

This package is not used by any popular GitHub repositories.

Version History

Version Downloads Last updated
0.0.145 385 7/4/2017
0.0.144 275 5/19/2017
0.0.143 272 5/18/2017
0.0.142 286 5/16/2017
0.0.140 410 11/4/2016
0.0.139 285 11/4/2016
0.0.138 271 11/3/2016
0.0.137 273 11/3/2016
0.0.136 279 11/3/2016
0.0.135 296 11/2/2016
0.0.134 268 11/2/2016
0.0.133 274 11/2/2016
0.0.132 275 11/2/2016
0.0.131 290 11/2/2016
0.0.130 275 11/2/2016
0.0.129 436 12/14/2015
0.0.128 354 12/11/2015
0.0.127 322 12/10/2015
0.0.126 358 12/9/2015
0.0.125 344 11/20/2015
0.0.124 381 11/20/2015
0.0.123 305 11/20/2015
0.0.122 351 11/20/2015
0.0.121 308 11/20/2015
0.0.120 312 11/20/2015
0.0.119 326 11/17/2015
0.0.118 342 11/17/2015
0.0.117 319 11/17/2015
0.0.116 323 11/17/2015
0.0.115 306 11/17/2015
0.0.114 468 11/16/2015
0.0.113 293 11/16/2015
0.0.112 311 11/16/2015
0.0.111 337 11/12/2015
0.0.110 307 11/12/2015
0.0.109 333 11/3/2015
0.0.108 326 11/3/2015
0.0.107 324 11/3/2015
0.0.106 340 11/2/2015
0.0.105 309 11/2/2015
0.0.104 313 10/30/2015
0.0.103 315 10/30/2015
0.0.102 305 10/30/2015
0.0.101 319 10/30/2015
0.0.100 320 10/30/2015
0.0.99 331 10/23/2015
0.0.98 318 10/23/2015
0.0.97 327 10/19/2015
0.0.96 336 10/16/2015
0.0.95 347 10/16/2015
0.0.94 324 10/16/2015
0.0.93 317 10/16/2015
0.0.92 327 10/13/2015
0.0.91 342 10/13/2015
0.0.90 329 10/13/2015
0.0.89 363 9/16/2015
0.0.88 348 9/16/2015
0.0.87 347 8/20/2015
0.0.86 317 8/17/2015
0.0.85 312 8/6/2015
0.0.84 320 7/29/2015
0.0.83 314 7/29/2015
0.0.82 337 7/29/2015
0.0.81 316 7/28/2015
0.0.80 319 7/28/2015
0.0.79 315 7/27/2015
0.0.78 339 7/20/2015
0.0.77 400 7/20/2015
0.0.76 331 7/10/2015
0.0.75 312 7/10/2015
0.0.74 361 7/2/2015
0.0.73 338 7/2/2015
0.0.72 330 6/29/2015
0.0.71 320 6/29/2015
0.0.70 323 6/24/2015
0.0.69 337 6/23/2015
0.0.68 371 6/23/2015
0.0.67 324 6/22/2015
0.0.66 332 6/22/2015
0.0.65 345 6/5/2015
0.0.64 334 6/4/2015
0.0.63 324 6/4/2015
0.0.62 331 6/3/2015
0.0.61 338 6/2/2015
0.0.60 328 6/2/2015
0.0.59 376 6/1/2015
0.0.58 329 6/1/2015
0.0.57 390 6/1/2015
0.0.56 444 6/1/2015
0.0.55 326 5/29/2015
0.0.53 318 5/27/2015
0.0.52 313 5/27/2015
0.0.51 325 5/22/2015
0.0.50 322 5/21/2015
0.0.49 323 5/20/2015
0.0.48 325 5/20/2015
0.0.47 359 5/20/2015
0.0.46 330 5/20/2015
0.0.45 332 5/19/2015
0.0.44 330 5/19/2015
0.0.43 347 5/15/2015
0.0.42 318 5/14/2015
0.0.41 328 5/13/2015
0.0.40 340 5/12/2015
0.0.39 340 5/11/2015
0.0.38 341 5/7/2015
0.0.37 332 5/7/2015
0.0.36 323 5/7/2015
0.0.35 341 5/7/2015
0.0.34 321 5/7/2015
0.0.33 335 5/7/2015
0.0.32 329 5/6/2015
0.0.31 306 5/6/2015
0.0.30 314 5/6/2015
0.0.29 322 5/6/2015
0.0.28 319 5/6/2015
0.0.27 319 5/5/2015
0.0.26 324 5/5/2015
0.0.25 315 4/27/2015
0.0.24 336 4/24/2015
0.0.23 380 4/23/2015
0.0.22 375 4/2/2015
0.0.21 316 4/2/2015
0.0.20 327 4/1/2015
0.0.19 329 3/31/2015
0.0.18 350 3/31/2015
0.0.17 358 3/31/2015
0.0.16 332 3/31/2015
0.0.15 306 3/31/2015
0.0.14 337 3/31/2015
0.0.13 311 3/31/2015
0.0.12 319 3/30/2015
0.0.11 321 3/30/2015
0.0.10 333 3/30/2015