26 lines
636 B
Plaintext
26 lines
636 B
Plaintext
[source,csharp]
|
|
----
|
|
using System;
|
|
|
|
public sealed class NotNullAttribute : Attribute { } // The alternative name 'ValidatedNotNullAttribute' is also supported
|
|
|
|
public static class Guard
|
|
{
|
|
public static void NotNull<T>([NotNull] T value, string name) where T : class
|
|
{
|
|
if (value == null)
|
|
{
|
|
throw new ArgumentNullException(name);
|
|
}
|
|
}
|
|
}
|
|
|
|
public static class Utils
|
|
{
|
|
public static string Normalize(string value)
|
|
{
|
|
Guard.NotNull(value, nameof(value)); // Will throw if value is null
|
|
return value.ToUpper(); // Compliant: value is known to be not null here.
|
|
}
|
|
}
|
|
---- |