Giter Club home page Giter Club logo

safeconvert's Introduction

SafeConvert

The SafeConvert is a .NET library used to convert data between data types safely. SafeConvert class diagram

Install and Requirements

In order to use this library, your application needs the .NET Framework 3.5 or higher. If okay, you can install via two following ways:

  • Via Nuget: Install-Package SafeConvert
  • Via Github: git clone https://github.com/congdongdotnet/SafeConvert.git

Usages

After refering to the SafeConvert library, remember that you need to include the library by using keyword:

using SafeConvert;

Samples

Convert from string "1" to byte

var b = "1".ToByte(); // Print 1

Convert from string "10" to short

var s = "10".ToShort(); // Print 10

Convert from string "100" to int

var n = "100".ToInt(); // Print 100

Convert from string "1000" to long

var l = "1000".ToLong(); // Print 1000

Convert from string "6.5" to float

var f = "6.5".ToFloat(); // Print 6.5

Convert from string "6.5" to decimal

var d = "6.5".ToDecimal(); // Print 6.5

Convert from string "6.5" to double

var d = "6.5".ToDouble(); // Print 6.5

Convert from string "2014-12-02 11:00:00" to DateTime

var dateTime = "2014-12-02 11:00:00".ToDateTime();

Convert from string "20" to int using generic

var n = "20".To<int>();

Each extension methods has the default value in case of failing to parse. E.g: convert from string "abc" to int using default value

var n = "abc".ToInt(10); // Print default value 10 because of failing to parse

Tests

This library has been tested Passed using NUnit Test Framework. If any issue or bug, please push a new issue here.

Copyright and License

Copyright 2015 by CongDongDotNet - MIT License

safeconvert's People

Contributors

1001binary avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.