I’ve noticed recently I take for granted some extensions methods I’ve been using for a while now that I use on a fairly frequent basis. From getting a file as base64 quickly to to just doing simple JSON operations, here are 5 day to day extension methods that hopefully prove helpful to your projects.

Feel free to look at the examples below or if you simply want to use the methods, they’re all contained in the following NuGet package (along with A LOT more but I haven’t had time to properly document the whole toolkit yet so that’s for another day, and yes it will be open sourced when it’s properly documented too!):

 

DarkIce.Toolkit.Core

https://www.nuget.org/packages/DarkIce.Toolkit.Core/

1. Get a file as Base64 data from a file path string

Usage:

Code:

2. Quickly convert back and forth from JSON

Usage:

Code:

Usage:

Code:

3. Get file size (or any value) categorised into a particular range. I’ve found this invaluable when it comes to analytics that involve file uploads where you want the overall ranges but not exact values

Usage:

4. Get a HttpResponseMessage returned as a typed object

Usage:

Code:

5. Get the MIME type of a file from a string of the file path

Usage:

Code:

And that’s it, just a few handy helpers for day to day use that I’ve personally found a lot of benefit from with the projects I work with.