Skip to content

Instantly share code, notes, and snippets.

View chrisfcarroll's full-sized avatar
🤹‍♂️
🌍...☕...🖥️...⏳...⛪...🛌🏼

Chris F Carroll chrisfcarroll

🤹‍♂️
🌍...☕...🖥️...⏳...⛪...🛌🏼
View GitHub Profile
@chrisfcarroll
chrisfcarroll / LogActions.cs
Last active June 6, 2025 10:35
LogAction uses [CallerMemberName] to make application level logging briefer, easier, and more useful
using System.Runtime.CompilerServices;
using Microsoft.Extensions.Logging;
public static class LogActions
{
/// <summary>
/// Log the current Method call and any relevant
/// parameter(s) <paramref name="loggableState"/> at log level <see cref="LogLevel.Information"/>
/// </summary>
/// <param name="log">the ILogger.</param>
@chrisfcarroll
chrisfcarroll / CSharpKeywordRequiredAttributes.cs
Created May 28, 2025 08:29
CompilerServices and Diagnostics.CodeAnalysis Attribute polyfills for the required keyword in .NetStandard2, .Net5, .Net6
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
//
// License statement and more attributes source code at
// https://github.com/dotnet/runtime/tree/main/src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices
//
// ReSharper disable CheckNamespace
using System.ComponentModel;
namespace System.Runtime.CompilerServices
@chrisfcarroll
chrisfcarroll / Parse.cs
Last active May 8, 2025 12:42
Parse.cs : Parse things without throwing an Exception by returning a default value on failure
using System;
/// <summary>
/// Parse things without throwing an Exception by returning a default value on failure
/// </summary>
public static class Parse
{
public static int ToInt(this string value, int defaultValue=0) => IntElse(value,defaultValue);
/// <summary>
@chrisfcarroll
chrisfcarroll / DisposableArray.cs
Created April 30, 2025 14:48
DotNet C# DisposableArray<T>, DisposableList<T>. Simplify creating and disposing an array or list of disposable elements by having the container be disposable.
using System.Collections;
/// <summary>
/// A <see cref="IDisposable"/> wrapper for a <see cref="T[]"/> which, when it is disposed,
/// disposes each of its non-null elements.
/// </summary>
public class DisposableArray<T> : Array<T>, IDisposable where T : IDisposable
{
public DisposableArray(IEnumerable<T> items):base(items){}
public DisposableArray(int size):base(size){}
@chrisfcarroll
chrisfcarroll / SqlScriptFileMigration.cs
Last active June 6, 2025 09:41
An EntityFrameworkCore Migration base class for Sql Script File-backed Migrations.
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
// ReSharper disable InconsistentNaming
#region migrations
[Migration(nameof(Script1))]public class Script1 : MigrationConfiguredWithScriptDirectoryAndDbContext{}
[Migration(nameof(Script2))]public class Script2 : MigrationConfiguredWithScriptDirectoryAndDbContext{}
#endregion
@chrisfcarroll
chrisfcarroll / FakeClaimsIdentity.cs
Last active March 27, 2025 18:30
A Fake Claims Identity for testing, with claims settable in code.
using System.Collections.Generic;
using System.Security.Claims;
using System.Security.Principal;
public class FakeClaimsIdentity : ClaimsIdentity
{
public readonly List<Claim> ClaimsValue = new List<Claim>();
public bool IsAuthenticatedSet;
@chrisfcarroll
chrisfcarroll / DevAzureReleaseVariableTransform.Tests.ps1
Created March 11, 2025 12:05
Dev Azure Release Pipeline Web.*.config Variable Transform PowerShell Script
using namespace System.Diagnostics
using namespace System.Collections
using namespace System.Collections.Generic
using namespace System.IO.Compression
param ( [switch]$NoRun )
function Assert( [bool]$condition, [string]$message = "Assertion failed" ){
if( -not $condition ) {
Get-PSCallStack | ForEach-Object { Write-Host $_.FunctionName $_.Location $_.Arguments }
@chrisfcarroll
chrisfcarroll / DevAzureReleaseNetCoreWebConfigTransformStep.ps1
Created March 11, 2025 11:24
DevAzure Release Pipeline NetCore Web.Config Transform Step for Environment Variables Substitution
# Populate Web.config EnvironmentVariables from Pipeline variables
#
# Usage: Copy-paste this script into a Powershell Task, as an inline script, in your release pipeline.
#
# -----------------------------------------------------
# Known Variables:
# DOTNET_ENVIRONMENT
# TraceTransforms
# -----------------------------------------------------
# Editing this script:
@chrisfcarroll
chrisfcarroll / DevAzure tasks and GOTCHAS.yml
Last active October 11, 2024 16:57
DevAzure tasks and GOTCHAS
task: PowerShell@2
displayName: "Dev Azure tasks and GOTCHAS"
inputs:
targetType: 'inline'
script: |
# Write your PowerShell commands here.
@"
DevAzure tasks and GOTCHAS: NuGet.config, MsBuild Path, Unit Tests, Integration Tests
"@
@chrisfcarroll
chrisfcarroll / SoftDictionary.cs
Last active March 27, 2025 10:31
A .Net SoftDictionary<K,V> is a Dictionary<K,V> which, if you try to read an empty entry, returns default(V) instead of throwing an exception.
/// <summary>
/// A SoftDictionary is a <see cref="Dictionary{TKey,TValue}"/> which does not
/// throw if you try to to access a non-existent entry. Instead, it returns <c>default(TValue)</c>
/// </summary>
/// <typeparam name="TKey"></typeparam>
/// <typeparam name="TValue"></typeparam>
public class SoftDictionary<TKey,TValue> : Dictionary<TKey,TValue> where TKey : notnull
{
/// <inheritdoc cref="IDictionary{TKey,TValue}"/>
/// <remarks>