Mis indispensables de C#. Parte 2: Extensiones
Esta es una serie de 3 artículos cortos sobre características de C# que uso en todas mis aplicaciones. Extensiones… Muchas extensiones Me gusta usar extension methods para validaciones. Aquí hay algunas básicas. public static class ValueExtensions { public static string ThrowIfEmpty ( this string value ) { return string . IsNullOrWhiteSpace ( value ) ? throw new ArgumentNullException () : value . Trim (); } public static string TrimOrThrow ( this string value ) { return value ?. Trim () ?? throw new ArgumentNullException (); } public static Guid ThrowIfEmpty ( this Guid value ) { return value == Guid . Empty ? throw new ArgumentNullException () : value ; } public static DateTime ThrowIfInPast ( this DateTime value ) { return value <= DateTime . Now ? throw new