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 / SeasonColorHelper.cs
Created August 12, 2025 14:22
C# get a different color for each season
using System.Drawing;
namespace SingletonLibrary.Classes;
public class SeasonColorHelper
{
/// <summary>
/// Gets the predefined color corresponding to the current season.
/// </summary>
private static readonly Dictionary<Season, Color> SeasonColors = new()
@karenpayneoregon
karenpayneoregon / QueryExtensions.cs
Created August 11, 2025 17:39
EF Core custom TagWit
using System.Runtime.CompilerServices;
using Microsoft.EntityFrameworkCore;
namespace TODO;
public static class QueryExtensions
{
/// <summary>
/// Adds a debug tag to the query, providing information about the calling method, file, and line number.
@karenpayneoregon
karenpayneoregon / GenericExtensions.cs
Created August 1, 2025 11:20
C# index for foreach prior to NET9
public static class GenericExtensions
{
/// <summary>
/// Enumerates a sequence and returns each element along with its index.
/// </summary>
/// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
/// <param name="source">The sequence to enumerate.</param>
/// <returns>An <see cref="IEnumerable{T}"/> of tuples, where each tuple contains the index and the corresponding element from the source sequence.</returns>
/// <exception cref="ArgumentNullException">Thrown if the <paramref name="source"/> is <c>null</c>.</exception>
@karenpayneoregon
karenpayneoregon / CopilotPrompt.md
Last active July 20, 2025 16:46
Working with ChatGPT to create C# code that ChatGPT writes faster than any developer can

Using C# create a class with a method to read a .csproj file.

  1. Check if UserSecretsId node exists in a method named Exists
  2. If UserSecretsId node exists return the value in a method named GetValue
<Project Sdk="Microsoft.NET.Sdk">

	<PropertyGroup>
 net9.0
@karenpayneoregon
karenpayneoregon / AssemblyHelper.cs
Last active July 1, 2025 14:49
Get calling assembly
using System.Diagnostics;
using System.Reflection;
namespace TODO;
public class AssemblyHelper
{
/// <summary>
/// Retrieves the namespace of the calling assembly that references the current assembly.
@karenpayneoregon
karenpayneoregon / styles.css
Last active July 14, 2025 21:15
Bootstrap 5.x date picker disabled dates color
/* Re-tint out-of-month or disabled days */
.datepicker table tr td.old,
.datepicker table tr td.new,
.datepicker table tr td.disabled,
.datepicker table tr td.disabled:hover {
color: #b22222; /* Firebrick red – pick your poison */
}
@karenpayneoregon
karenpayneoregon / styles.css
Created May 9, 2025 22:11
Provides styles for HTML placeholder
input[type="text"],
input[type="email"],
input[type="password"] {
all: unset;
box-sizing: border-box;
display: block;
width: 100%;
max-width: 400px;
padding: 10px 12px;
font-size: 1rem;
@karenpayneoregon
karenpayneoregon / Program.cs
Last active April 18, 2025 15:48
C# Get date time with hour and minutes in 24h format
namespace InputsDemo;
internal partial class Program
{
static void Main(string[] args)
{
var value = Prompts.GetDate();
Console.WriteLine(value.Year == 1 ? "Cancelled" : $"Selected date: {value:MM/dd/yyyy HH:mm}");
Console.ReadLine();
}
public class CatalogInfo
{
public string ProductDisplayVersion { get; set; }
}
@karenpayneoregon
karenpayneoregon / ProjectUpdater.cs
Created April 7, 2025 10:20
Update Framework in project file
using System.Xml.Linq;
namespace UpdateFrameworkApp.Classes;
public class ProjectUpdater
{
public static string UpdateTargetFramework(string csprojPath, string oldFramework = "net7.0", string newFramework = "net9.0")
{
if (!File.Exists(csprojPath))
{