Skip to content

Instantly share code, notes, and snippets.

@karenpayneoregon
Last active November 19, 2024 21:04
Show Gist options
  • Save karenpayneoregon/65c5bea1db0f306bd300b5bbc609781e to your computer and use it in GitHub Desktop.
Save karenpayneoregon/65c5bea1db0f306bd300b5bbc609781e to your computer and use it in GitHub Desktop.
C# OverloadResolutionPriority Attribute
public partial class Demo
{
[OverloadResolutionPriority(2)]
public static void DisplayInvoice(string invoice )
{
Console.WriteLine($"invoice: {NextValue(invoice)}");
}
[OverloadResolutionPriority(-1)]
public static void DisplayInvoice(string invoice, int count = 3)
{
var value = invoice;
for (var index = 0; index < count; index++)
{
value = NextValue(value);
Console.WriteLine($"invoice: {value}");
}
}
public static string NextValue(string sender, int incrementBy = 1)
{
var value = NumbersPattern().Match(sender).Value;
return sender[..^value.Length] + (long.Parse(value) + incrementBy)
.ToString().PadLeft(value.Length, '0');
}
[GeneratedRegex("[0-9]+$")]
private static partial Regex NumbersPattern();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment