We are writing a dll that other teams can access. One of our requirements is that every passed DateTime has DateTimeKind.Utc.
However, we do not apply this requirement, which leads to errors. Therefore, we were wondering how we can ensure that this is done .
We had a few ideas:
Write an aspect that checks each parameter passed to the method. Throw an exception when Kind! = UTC. This works, but does not work, when you pass an object containing a DateTime.
Change all of our DateTimes to a custom object, UtcDateTime.
This may work, but you will need to make sure that we replace every DateTime and all calls with our dates. It will look something like this:
public class UtcDateTime
{
private DateTime _dateTime;
public UtcDateTime(DateTime dateTime)
{
if(dateTime.Kind != DateTimeKind.Utc)
{
throw new ArgumentException();
}
_dateTime = dateTime;
}
}
?