Skip to content

Instantly share code, notes, and snippets.

View sahgilbert's full-sized avatar

Simon Gilbert sahgilbert

View GitHub Profile
@sahgilbert
sahgilbert / NumericalExtensions.cs
Created May 22, 2019 13:37
Numerical Extension Methods - C# .Net Core
using System;
namespace SimonGilbert.Blog
{
public static class NumericalExtensions
{
public static double RoundByDecimalPlaces(this double number, int numberOfDecimalPlaces = 2)
{
return Math.Round(number, numberOfDecimalPlaces);
}
@sahgilbert
sahgilbert / DateTimeExtensions.cs
Created May 22, 2019 13:48
DateTime Extension Methods - C# .Net Core
using System;
namespace SimonGilbert.Blog
{
public static class DateTimeExtensions
{
public static string ToRelativeDate(this DateTime dateTime)
{
var timeSpan = DateTime.Now - dateTime;
@sahgilbert
sahgilbert / UnifiedController.cs
Created June 3, 2019 20:50
C# ASP.Net Core - Unified MVC & Web Api Controller
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
namespace SimonGilbert.Blog.Controllers
{
public class UnifiedController : Controller
{
[HttpGet]
public IActionResult Index()
{