Skip to content
This repository was archived by the owner on Oct 4, 2023. It is now read-only.

DevFast: Program Declaratively

Divya Sarthi Maheshwari edited this page May 28, 2018 · 4 revisions

Simplest way to understand what this lib can do for you is to:

  • Reference it in your project
  • Take a string and type .T to find possibilities

Sample codes of following PNG snapshots are available as Dot.Net.DevFast.Sample

Many more articles on the library can be found HERE


DevFast (NuGet)

Hello DevFast

DevFast takes a mile to provide the most declarative way to program your C#.Net solutions.

DevFast stands for "Develop Fast", without compromising the code quality. Library is equipped with extensive documentation and features set of, expressive & simplest to use, methods any programmer requires almost all the time.

Naming convention of these methods make sure that code stays highly readable. In the v1, we cover simple extension methods on string, ValueTypes, stream and more... Let's have a look.

String.T variants

Before we look are those methods, first let's see if we would like to write following program:

"Create a function that accepts a string, parses it as DateTime, if parsing fails returns 12 Jan, 2000 as value"

To write such a simple program, we might need to consider null values, perform unit testing, maintain it throughout the project lifetime and so on... The interesting thing is we need to spend time writing it! It means during that time we CANNOT do something else! Furthermore, such parsing requirements are SELDOM project specific; so if you missed packetized it you need to reinvent the wheel again.

On the other hand, what if you can do all this in one-liner code? With DevFast added as reference, this code is as simple as:

myString.ToOrDefault(new DateTime(2000, 1, 12));

Following picture shows some trivial comparison: toordef

Following are available methods on string:

  • .TryTo => string parsing to bool,int,long,decimal,DateTime,Enum,Type etc
  • .ToOrDefault => string parsing to bool,int,long,decimal,DateTime,Enum,Type etc with given default value
  • .To variants => string parsing to 'FileInfo', DirectoryInfo, bool,int,long,decimal,DateTime,Enum,Type etc. Throws Exception when parsing fails.
  • .Trim variants => string trim specific methods
  • .Throw variants => Exception throwing methods when string satisfies certain conditions.
  • .ToBase64 / .FromBase64 variants => Base64 string conversion methods
  • .Transform variants => String transformation methods (Base64 is a special case)

Below picture shows some sample use cases: stringvar

.Throw variants

  • .ThrowIf / .ThrowIfNot => on bool. throws when true (ThrowIf) or false (ThrowIfNot). Though might look trivial but very powerful. Almost all other Throws fallbacks on it.
  • .ThrowIfNull => On any T which is class (ReferenceType).
  • .ThrowIfNullOrEmpty => On any T which is ICollection (Array, List etc).
  • .ThrowOnMiss => On Dictionary / Collections type. When supplied Key / valye is not in it.
  • .ThrowIfZero / .ThrowIfNotZero => as the name suggests (int / long)
  • .ThrowIfEqual / .ThrowIfNotEqual => Any T which is IEquatable
  • .ThrowIfLess / .ThrowIfGreater => Any T which is IComparable
  • .ThrowIfBounded / .ThrowIfNotBounded => Any T which is IComparable

Below picture shows some sample use cases: throwvar

.ToBase64 variants

  • .ToBase64 / .FromBase64 => on string, byte[], ArraySegment<byte>
  • .ToBase64Async/ .FromBase64Async => on string, byte[], ArraySegment<byte>, StringBuilder, Stream

Below picture shows some sample use cases: base64var

Miscellaneous Methods

  • .TransformAsync => on string, byte[], ArraySegment<byte>, StringBuilder, Stream to perform various Crypto transformations
  • .CreateFileInfo => on DirectoryInfo to create FileInfo object.
  • .CreateBytes => on ArraySegment<byte> to create byte[]

Below picture shows some sample use cases: transformvar

Json Methods

For detailed usage, please see Simply DevFast article series.

  • .ToJson/.FromJson => on string, byte[], ArraySegment<byte>, StringBuilder, Stream to perform JSON serialization/deserialization
  • .ToJsonArray/.FromJsonAsEnumerable => on string, byte[], ArraySegment<byte>, StringBuilder, Stream to perform JSON serialization/deserialization based on generic IEnumerable<T>
  • .ToJsonArrayParallely/.FromJsonArrayParallely => on string, byte[], ArraySegment<byte>, StringBuilder, Stream to perform JSON serialization/deserialization based on generic BlockingCollection<T> in order to realize parallel producer-consumer pattern.

Compression Methods

For detailed usage, please see Simply DevFast article series.

  • .CompressAsync => on string, byte[], ArraySegment<byte>, StringBuilder, Stream to perform Deflate/GZip compression.
  • .DecompressXXXAsync => on string, byte[], ArraySegment<byte>, StringBuilder, Stream to perform Deflate/GZip decompression.

More to come in next releases... let us know your requirements, on the way we'll prioritize those. Thanks!