Can I write code with an expiration date?

Mark the code with the System.ObsoleteAttribute attribute, you’ll get a compiler warning, which will nag you to fix the code

[Obsolete("You've an ugly hack here")]
public void MyUglyHack()
{
...
}

Alternatively . . .

Write your own attribute, passing it an expiration date on the constructor, in the constructor throw an exception if DateTime.Now >= expirationDate.

The compile will fail until you fix the code (or more likely increase the expiration date, or far more likely you just remove the Attribute.

Leave a Comment