Skip to content

Instantly share code, notes, and snippets.

View Dkowald's full-sized avatar

Derek Kowald Dkowald

  • Brisbane, Australia
View GitHub Profile
@Dkowald
Dkowald / PrivateSetterContractResolver.cs
Last active January 5, 2019 00:34
Newtonsoft.Json contract resolver to allow non-public property setters.
using System.Reflection;
using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;
// ReSharper disable once CheckNamespace
namespace kwd.gist
{
/// <summary>
/// Support serialize properties with non-public setters
@Dkowald
Dkowald / CaseAwareFileProvider.cs
Last active January 3, 2019 05:32
Case aware FileProvider
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Microsoft.Extensions.FileProviders;
using Microsoft.Extensions.Primitives;
// ReSharper disable once CheckNamespace
namespace kwd.gist
@Dkowald
Dkowald / CaseAwarePath.cs
Last active January 3, 2019 05:22
Resolve case-aware path.
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
// ReSharper disable once CheckNamespace
namespace kwd.gist
{
/// <summary>
/// Utility to resolve file system path with case.
@Dkowald
Dkowald / FileProviderConvertersExtensions.cs
Last active January 3, 2019 03:51
Convert IFileInfo to FileInfo or DirectoryInfo objects.
using System;
using System.IO;
using Microsoft.Extensions.FileProviders;
// ReSharper disable once CheckNamespace
namespace kwd.gist
{
/// <summary>
/// Extensions to convert <see cref="IFileInfo"/> to
@Dkowald
Dkowald / CryptoWrapper.cs
Last active October 13, 2023 17:36
Dispose associated ICryptoTransform and algorithm along with CryptoStream
using System;
using System.IO;
using System.Security.Cryptography;
namespace kwd.gist
{
/// <summary>
/// Dispose associated <see cref="ICryptoTransform"/> and algorithm along with <see cref="CryptoStream"/>.
/// </summary>
/// <remarks>
@Dkowald
Dkowald / ResponseBuffering.cs
Last active January 22, 2019 15:33
ResponseBuffering for Asp.Net core
using System;
using System.IO;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
// ReSharper disable once CheckNamespace
namespace kwd.gist
{
/// <summary>
@Dkowald
Dkowald / DirectoryInfoDirectoryExtensions.cs
Last active October 10, 2019 04:24
Extensions so FileInfo and DirectoryInfo include functions from Path and File
using System;
using System.IO;
using System.Linq;
namespace kwd.gist
{
/// <summary>
/// Extensions for <see cref="DirectoryInfo"/> to include missing functions from <see cref="Directory"/>.
/// </summary>
public static class DirectoryInfoDirectoryExtensions
@Dkowald
Dkowald / HttpError.cs
Last active October 25, 2018 08:36
MVC Exception based Http Error
using System;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Filters;
namespace kwd.gist
{
public class HttpError : Exception
{
public HttpError(IActionResult result)
{
@Dkowald
Dkowald / PocoDemoController.cs
Created September 4, 2017 04:09
Demo POCO Controller for ASP.NET Core v2
using System.Security.Claims;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Infrastructure;
using Microsoft.AspNetCore.Mvc.ModelBinding;
using Microsoft.AspNetCore.Mvc.ModelBinding.Internal;
using Microsoft.AspNetCore.Mvc.ModelBinding.Validation;
using Microsoft.AspNetCore.Mvc.Routing;
using Microsoft.AspNetCore.Mvc.ViewFeatures;
@Dkowald
Dkowald / UrlAbsoluteExtensions.cs
Last active October 25, 2018 08:37
UrlAbsolute
using Microsoft.AspNetCore.Mvc;
namespace kwd.gist {
/// <summary>
/// Provide Absolute versions of URL helper methods.
/// </summary>
/// <remarks>
/// Source: https://gist.github.com/383acd462242194024981fbe53a84980.git
/// These cannot be used to change host or protocol,
/// use inbuilt MVC UrlHelper for that.