End Your If

Helping you solve those tough coding problems!

Learn some great development tips and techniques through recipes that clearly define the problem being solved with a working solution.
Popular Tags: cakephp | theory | optimization | javascript-development | asp-net | ajax | sql | php-development | jquery-development | css

Search:
Follow @endyourif rss Facebook LinkedIn
My Books

C# HtmlExtension to display SVGs C# HtmlExtension to display SVGs

Published on Feb 16, 2019 by Jamie Munro

Problem


You have SVGs that you wish to display on your website but you want to be able to re-use them without copying and pasting the code or creating a shared view.

Solution


Read more >

Tags: ASP.NET | c# | htmlextension | svg

C# Improving string.IsNullOrEmpty readability C# Improving string.IsNullOrEmpty readability

Published on Feb 5, 2019 by Jamie Munro

I often find myself using this great C# function: string.IsNullOrEmpty. It is the assured way to confirm whether a string is empty - null or otherwise.
However, I often find myself wanting to know when it is not empty. Thus I have to write an if statement that reads more like this:


if (!string.IsNullOrEmpty(myString)) {

// Do something

}


I personally do not find this very readable because of the ! at the start of the if statement.
Enter this little handy tidbit of code - a string extension - to improve readability:

Read more >

Tags: ASP.NET | c# | string.isnullorempty | extensions

C# Convert date from UTC to EST C# Convert date from UTC to EST

Published on Jun 7, 2017 by Jamie Munro

Every now and then I need to convert a date from Coordinated Universal Time (UTC) to Eastern Standard Time (EST).† I always found myself trying to remember "Where did I use this last?".† To avoid asking myself, I have now immortalized it on my blog.

Read more >

Tags: ASP.NET | c# | timezones

How to return a CSV from ASP.NET Web API using C# How to return a CSV from ASP.NET Web API using C#

Published on May 4, 2017 by Jamie Munro

ASP.NET Web API is a framework that is built upon the MVC (Model View Controller) principal to assist in rapidly building a RESTful API using the .NET framework.


By default Web API makes it easy to return common HTML content types, such as: JSON and XML.† However, it requires a little bit more work to return a CSV using Web API.† Read on to learn how.

Read more >

Tags: ASP.NET | c# | web api | csv

Advanced Automatic Ninject Bindings Advanced Automatic Ninject Bindings

Published on Jan 13, 2014 by Jamie Munro

Problem


You have a common interface that is used by multiple concrete classes and you donít want to specify each Ninject binding manually.

Solution


The solution to this problem is very similar to my previous post on Automatic Ninject Bindings because it also leverages the NuGet package Ninject.extensions.conventions.

In this example, letís assume you have a single interface called IService<T>.† This interface contains a generic reference to a class or object (e.g. a database model).† Then you have multiple classes that implement the interface.† E.g. UserService : IService<User>.

With the following line of code, all of your classes that implement the IService interface will automatically bind to the corresponding class:


 ††††††††††† var kernel = new StandardKernel();

 ††††††††††† kernel.Bind(x =>

 ††††††††††† {

 †††† †††††††††††x.FromThisAssembly()

 ††††††††††††††††††† .SelectAllClasses()

 ††††††††††††††††††† .InheritedFrom(typeof(IService<>))

 ††††††††††† ††††††††.BindSingleInterface();

 ††††††††††† });

 

Read more >

Tags: Uncategorized | ASP.NET | c# | mvc | ninject

Automatic Ninject Bindings Automatic Ninject Bindings

Published on Jan 7, 2014 by Jamie Munro

Automapper Performance Testing Automapper Performance Testing

Published on May 27, 2013 by Jamie Munro

Why the Repository Pattern Why the Repository Pattern

Published on May 20, 2013 by Jamie Munro

Entity Framework Beginnerís Guide Done Right Entity Framework Beginnerís Guide Done Right

Published on May 13, 2013 by Jamie Munro

Why Java Makes Me Tremble In My Boots Why Java Makes Me Tremble In My Boots

Published on May 6, 2013 by Jamie Munro

My First Experiences with Kinect for Windows - @KinectWindows My First Experiences with Kinect for Windows - @KinectWindows

Published on Mar 5, 2013 by Jamie Munro

Javascript, the Back Button, and Windows Phone 8 Development Javascript, the Back Button, and Windows Phone 8 Development

Published on Feb 18, 2013 by Jamie Munro

The Best Way to Prevent SQL Injection The Best Way to Prevent SQL Injection

Published on Sep 19, 2012 by Jamie Munro