Mar 4, 2015

Arranging an array of flat paths into a JSON tree like structure

I recently worked on a project where I was required to take an array of flat paths separated by slashes and arrange them into a JSON object in order to display them in a tree from the front end. To be clear, the paths that I was provided looked something like this. The following example utilizes lodash, but could also be accomplished with Array.prototype.forEach(). I, unfortunately, had to support IE8....

May 23, 2014

How To: ASP.NET MVC HtmlHelper Extension Methods

Creating extension methods for our HtmlHelpers is a great way to minimize a lot of logic in our view. HtmlHelper extensions minimize unnecessary clutter and keep our view focused on how the page is displayed to our user rather than the logic behind it. Create a Helper Extension Method using System.Net; using System.Web.Mvc; namespace SomeProject.HtmlExtensions { public static class Helper { public static bool RemoteFileExists(this HtmlHelper helper, string remoteUrl) {...

May 19, 2014

C#: Passing parameters to a thread with ParameterizedThreadStart

Much like the name applies, ParameterizedThreadStart provides a way to pass parameters to a thread upon start. In the following example, the variable name is being passed to the SayHello method when myThread.Start(name) is called. using System; using System.Threading; namespace Sample { class Program { static void Main(string[] args) { string name = "Bob"; // Pass a new ParameterizedThreadStart object to the Thread class constructor. // The ParameterizedThreadStart construcotr takes...

May 19, 2014

.NET Delegates (Typed Function Pointers)

A delegate is the .NET version of a type safe function pointer. All threads require an entry point to start execution. By definition when a primary thread is created it always runs Main() as it’s entry point. Any additional threads you create will need an explicitly defined entry point - a pointer to the function where they should begin execution. So threads always require a delegate. Delegates are often used...

Apr 18, 2014

C#: Performing GET and deserializing a restful web service endpoint returning json

HTTP requests can be made a number of different ways in .NET. The HttpRequest and WebClient (older) both provide functionality for creating HTTP requests. Below illustrates how to use each of these classes. using Newtonsoft.Json; using System.Collections.Generic; using System.Net; using System.Net.Http; using System.Web.Mvc; namespace WebApiTestApp.Controllers { public class HomeController : Controller { // Using HttpClient class public ActionResult Index() { string temp = ""; HttpClient client = new HttpClient(); string...

Previous Page: 4 of 5 Next