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# OutputCache with subdomains C# OutputCache with subdomains

Published on May 4, 2018 by Jamie Munro

The other day I was working on a project that was leveraging OutputCache. This little attribute is a fantastic way to implement caching in an MVC project. It was being used as follows but it was not working when we had multiple subdomains sharing the same controllers and actions:



[OutputCache(CacheProfile="CacheProfile")]

public ActionResult Index()

{

return View();

}

Read more >

Tags: Optimization | ASP.NET

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

Unit Testing Data Validation with MVC Unit Testing Data Validation with MVC

Published on May 11, 2015 by Jamie Munro

Removing Data Validation from MVC Controllers Removing Data Validation from MVC Controllers

Published on May 6, 2015 by Jamie Munro

Integrating Automapper with an MVC Result Filter Integrating Automapper with an MVC Result Filter

Published on May 4, 2015 by Jamie Munro

ASP.NET MVC 5 with Bootstrap and Knockout.js ASP.NET MVC 5 with Bootstrap and Knockout.js

Published on Apr 21, 2015 by Jamie Munro

Speeding up my unit tests Speeding up my unit tests

Published on Apr 28, 2014 by Jamie Munro

Advanced Automatic Ninject Bindings Advanced Automatic Ninject Bindings

Published on Jan 13, 2014 by Jamie Munro

Automatic Ninject Bindings Automatic Ninject Bindings

Published on Jan 7, 2014 by Jamie Munro

Iím hooked on test-driven development (TDD) Iím hooked on test-driven development (TDD)

Published on Aug 6, 2013 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

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

What I Learned This Summer What I Learned This Summer

Published on Sep 7, 2012 by Jamie Munro

A Simple But Effective Speed Comparison A Simple But Effective Speed Comparison

Published on Sep 4, 2012 by Jamie Munro

MVC 3 Routing Example MVC 3 Routing Example

Published on Oct 17, 2011 by Jamie Munro

20 Recipes for Programming MVC 3 20 Recipes for Programming MVC 3

Published on Oct 12, 2011 by Jamie Munro

20 Recipes for Programming MVC 3 20 Recipes for Programming MVC 3

Published on Oct 12, 2011 by Jamie Munro

ToLower-ToUpper and the CurrentCulture.CultureInfo ToLower-ToUpper and the CurrentCulture.CultureInfo

Published on Aug 8, 2011 by Jamie Munro

ToLower-ToUpper and the CurrentCulture.CultureInfo ToLower-ToUpper and the CurrentCulture.CultureInfo

Published on Aug 8, 2011 by Jamie Munro