Created
September 8, 2016 14:40
-
-
Save pietrom/edb627cd487a00683ffb4f72f268b990 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static class ObjectHelper { | |
public static T? Min<T>(T? x, T? y) where T : struct, IComparable { | |
if (x.HasValue && y.HasValue) { | |
return x.Value.CompareTo(y.Value) <= 0 ? x : y; | |
} else if (x.HasValue) { | |
return x; | |
} else { | |
return y; | |
} | |
} | |
public static T? MinWith<T>(this T? x, T? y) where T : struct, IComparable { | |
return Min(x, y); | |
} | |
public static T? Max<T>(T? x, T? y) where T : struct, IComparable { | |
if (x.HasValue && y.HasValue) { | |
return x.Value.CompareTo(y.Value) >= 0 ? x : y; | |
} else if (x.HasValue) { | |
return x; | |
} else { | |
return y; | |
} | |
} | |
public static T? MaxWith<T>(this T? x, T? y) where T : struct, IComparable { | |
return Max(x, y); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment