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 / .filenesting.json
Last active September 5, 2025 19:55
C# partial properties
{
"help": "https://go.microsoft.com/fwlink/?linkid=866610",
"root": true,
"dependentFileProviders": {
"add": {
"fileToFile": {
"add": {
"Client.Sets.cs": [
"Client.cs"
]
public static partial class Helpers
{
public static string NextValue1(string sender, int incrementBy = 1)
{
var index = sender.Length - 1;
while (index >= 0 && char.IsDigit(sender[index]))
index--;
if (index == sender.Length - 1)
return sender + incrementBy.ToString();
@karenpayneoregon
karenpayneoregon / DemoCode.cs
Created August 31, 2025 09:46
C# CommaDelimitedStringCollection
AnsiConsole.MarkupLine("[yellow]Comma delimited full month names[/]");
CommaDelimitedStringCollection result1 = [];
result1.AddRange(DateTimeFormatInfo.CurrentInfo.MonthNames[..^1]);
Console.WriteLine($"{result1}");
AnsiConsole.MarkupLine("[yellow]Using an int array[/]");
int[] items = [1, 2, 3];
CommaDelimitedStringCollection result2 = new();
result2.AddRange(items.ToStringArray());
@karenpayneoregon
karenpayneoregon / DateTimeHelpers.cs
Created August 25, 2025 13:50
Date Time Helpers
public static class DateTimeHelpers
{
/// <summary>
/// Generates a list of dates representing the next week's dates starting from the upcoming Sunday.
/// </summary>
/// <returns>A list of <see cref="DateOnly"/> objects representing the dates of the next week.</returns>
public static List<DateOnly> NextWeeksDates()
{
var start = DateTime.Now;
var nextSunday = DateOnly.FromDateTime(start).Next(DayOfWeek.Sunday);
@karenpayneoregon
karenpayneoregon / SetupLogging.cs
Created August 14, 2025 13:52
EF Core slow query Interceptor
using Serilog;
using static System.DateTime;
namespace TODO.Classes;
public class SetupLogging
{
public static void Development()
{
@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.