3 posts · rss

C# Reflection and Attributes

Reflection and custom attributes in C#: logging without boilerplate, mapping entities to lists, and generating audit trails from type metadata.

The oldest posts on this blog, and the only ones that are not really about Microsoft 365. They come from a stretch of writing plumbing in C#, using reflection and custom attributes to avoid writing the same code in every method.

Logging that you switch on with an attribute rather than a try block in every controller action. Mapping list items onto typed objects the way an ORM would. Generating an audit trail from type metadata and a database trigger rather than hand-written history code.

I am leaving these up because the techniques still hold and people still search for them. Be aware they predate the current voice of the blog by a couple of years. The code works; the writing is greener.

SQL save changes w. trigger

Feb 3, 2024 · 6 min

SQL save changes w. trigger

Easiest way to keep track of which changes have been made to an object, and likewise, who has carried out these changes.