Skip to content

Instantly share code, notes, and snippets.

View karenpayneoregon's full-sized avatar
🎯
Focusing

Karen Payne karenpayneoregon

🎯
Focusing
View GitHub Profile
@karenpayneoregon
karenpayneoregon / Person.cs
Created December 11, 2025 13:36
SetsRequiredMembers
[method: SetsRequiredMembers]
public record Person(string FirstName, string LastName, DateOnly BirthDate)
{
public int Id { get; set; }
public required string FirstName { get; set; } = FirstName;
public required string LastName { get; set; } = LastName;
public required DateOnly BirthDate { get; set; } = BirthDate;
}
public readonly struct EllipsisNumericFormattable<T> : IFormattable where T : struct, IFormattable
{
private readonly T _value;
private readonly int _width;
private readonly char _paddingChar;
public EllipsisNumericFormattable(T value, int width, char paddingChar)
{
_value = value;
_width = width;
@karenpayneoregon
karenpayneoregon / Category.cs
Last active November 21, 2025 17:02
Demonstrates the use of the `with` expression
public class Category
{
public int Id { get; set; }
public required string Name { get; set; }
}
var $debugHelper = $debugHelper || {};
$debugHelper = function () {
const debugStyleId = "debugger-inline-style";
function addCss() {
if (document.getElementById(debugStyleId)) return; // prevent duplicates
const style = document.createElement("style");
style.id = debugStyleId;
using Microsoft.AspNetCore.Mvc.ModelBinding.Metadata;
using System.Text.RegularExpressions;
namespace TODO.Classes;
/// <summary>
/// Provides a custom implementation of <see cref="IDisplayMetadataProvider"/>
/// to format property names in PascalCase into a more readable format by inserting spaces.
/// </summary>
/// <remarks>
@karenpayneoregon
karenpayneoregon / QueryExtensions.cs
Created October 29, 2025 04:28
EF Core TagWithDebugInfo
using Microsoft.EntityFrameworkCore;
using System.Runtime.CompilerServices;
namespace EntityFrameworkLibrary;
public static class QueryExtensions
{
/// <summary>
/// Adds a debug tag to the query, providing information about the calling method, file, and line number.
@karenpayneoregon
karenpayneoregon / Program.cs
Last active October 25, 2025 16:21
Remove apostrophes from FluentValidation error messages for ASP.NET Core
public class Program
{
public static void Main(string[] args)
{
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddRazorPages();
...
@karenpayneoregon
karenpayneoregon / Demo.cs
Created October 22, 2025 03:08
ASP.NET Core get current page name
public string CurrentPageName { get; private set; }
public void OnGet()
{
CurrentPageName = PageHelpers.GetCurrentPageName(HttpContext.Request);
}
@karenpayneoregon
karenpayneoregon / Info.cs
Last active October 18, 2025 13:15
Project copyright
/// <summary>
/// Provides utility methods to retrieve assembly metadata such as company, product, copyright, and version information.
/// </summary>
public class Info
{
private static Assembly Assembly => Assembly.GetExecutingAssembly();
public static string GetCopyright()
{
var attr = Assembly
.GetCustomAttribute<AssemblyCopyrightAttribute>();
@karenpayneoregon
karenpayneoregon / readme.md
Last active October 16, 2025 15:06
ASP.NET Core navigation markers

For the record, this is what Copilot recommended.

document.addEventListener('DOMContentLoaded', () => {
    const normalizePath = (path) => {
        if (!path) return '';
        const q = path.indexOf('?');
        const h = path.indexOf('#');
        const end = Math.min(q === -1 ? path.length : q, h === -1 ? path.length : h);
        let p = path.slice(0, end).toLowerCase();