Skip to content

Instantly share code, notes, and snippets.

View martincostello's full-sized avatar
🚀
Coding stuff

Martin Costello martincostello

🚀
Coding stuff
View GitHub Profile
@martincostello
martincostello / Program.cs
Last active May 21, 2022 10:54
Converts C# source files to use file-scoped namespaces
// There may be corner cases where the naive string matching incorrectly
// changes your source file. Check your diff before committing any changes.
using System.Text;
// Change to whatever your favourite indentation is
const string Indent = " ";
// Get all the C# files in the specified directory
var fileNames = Directory.GetFiles(args[0], "*.cs", SearchOption.AllDirectories);
@martincostello
martincostello / NSubstituteExtensions.cs
Last active August 11, 2023 11:05
Mocking Moq for NSubstitute
// Copyright (c) Martin Costello, 2023. All rights reserved.
// Licensed under the Apache 2.0 license.
using System.Linq.Expressions;
using NSubstitute.Core;
using NSubstitute.ExceptionExtensions;
namespace NSubstitute;
/// <summary>
@martincostello
martincostello / SystemTextJsonContentSerializerForSourceGenerator.cs
Last active February 6, 2024 09:10
A class for plugging the JSON source generator with Refit
using System.Net;
using System.Reflection;
using System.Text.Json;
using System.Text.Json.Serialization;
namespace Refit;
/// <summary>
/// A class representing an implementation of <see cref="IHttpContentSerializer"/> that can be
/// used with the <c>System.Text.Json</c> source generators. This class cannot be inherited.