Coder Social home page Coder Social logo

stringify's Introduction

Stringify is a type safe string transformation utility. It is very common to have the ability to convert string data back and forth to primitive types. Stringify lets to do this and more by extending the idea to any type and providing a overly simple api hiding all complexities.

#1 Convert to primitive types from string

  • Converter.ConvertTo<System.Int32>("5")
  • Converter.ConvertTo("$1,000")
  • Converter.ConvertTo(" 0xCA ", new ConverterOptions { NumberStyles = NumberStyles.HexNumber})
  • Converter.ConvertTo("28071981", new ConverterOptions { FormatString = "ddMMyyyy"} )

#2 Convert to primitive nullable types from string

  • Converter.ConvertTo<int?>("5")

#3 Convert to Enumerable types from string

  • Converter.ConvertTo<IEnumerable<System.Int32>>("1, 2, 3, 4, 5")
  • Converter.ConvertTo<IList<System.String>>("1, 2, 3, 4, 5")
  • Converter.ConvertTo<List<System.String>>("1, 2, 3, 4, 5")
  • Converter.ConvertTo<float[]>("1 2 3 4 5", new ConverterOptions { Delimiter = ' ' })
  • Converter.ConvertTo<ICollection>("1| 2| 3|4 | 5", new ConverterOptions { Delimiter = '|' })
  • Converter.ConvertTo<Collection>("1_2_3_4_5", new ConverterOptions { Delimiter = '_' })

#4 In-built support for converting from logical boolean values

  • Converter.ConvertTo("1") // 1,t,y,yes are considered True irrespective of case
  • Converter.ConvertTo("0") // 0,f,n,no are considered False irrespective of case
  • Converter.ConvertTo<IEnumerable>("true,false")

#5 Register your own type conversion and seamlessly convert using the api TypeConverterFactory.RegisterTypeConverter(typeof(bool), new SomeCustomConverter()); //Handle the conversions as you like

  • Converter.ConvertTo("some value")

#6 All above variants are also available to convert into a string

  • Converter.ConvertFrom(1234.56, new ConverterOptions { FormatString = "#,#.00" })
  • Converter.ConvertFrom(new[] { 1, 2, 3, 4, 5 }, new ConverterOptions { Delimiter = '_' }) //returns "1_2_3_4_5"

#7 Opportunities are endless. You can implemenent your own string conversion for specific types and register your type converter with the api and let it take care of the specific conversions as and when required by your client code

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.