I stumbled on code just the other day, The curious kind, in a curious way.
The kind that makes you sigh, then grin, You shake your head, but you’re pulled right in.
The kind that whispers, “Look again!”
So you scour the codebase, line by line, then— Counting the places it dares to repeat, A pattern so awful, yet so oddly neat.
“Ah well,” I mused, “I’ve seen worse before, Odder patterns and practices, strange to the core”, odd little hacks that I’ve chose to ignore.
And there it was, sitting out, no disguise, Plain old reflection, right in my eyes.
But stop your judging, don’t act so bright, We’ve all done it once, twice, or yet maybe thrice.
[Fact]
void ValidateBar()
{
var foo = new Foo();
var method = typeof(Foo).GetMethod("Bar");
method.Invoke(foo, [1, 2]);
}
A spell in the code, a curious sight, It worked in the dark, but it never felt right.
And then it struck me, clear as the day, an idea so strange, it refused to obey.
I had an awful idea. A wonderful awful idea.
So I pulled up my keyboard, addressed Copilot by name, We plotted and tinkered, oh what a game!
A library to banish reflection’s old fear, To write it with joy, with code crystal clear.
[Fact]
[PrivatesAvailable(typeof(Foo))]
void ValidateBar()
{
var foo = new Foo();
var fG = new Foo_Privates(foo);
fG.Bar(1,2);
}
What a sight, what a sight, what a sight to behold, A trick in the code, both daring and bold. Done with .NET 10 and its magical mix, A wonderful awful idea, with mischievous tricks.
So follow the tale, let curiosity tick, Go read it all here while you wait for Saint Nick.
“Think left and think right and think low and think high. Oh, the thinks you can think up if only you try!” — Dr.Seuss
Happy Holidays and Happy Coding!

Leave a comment