Καλώς ορίσατε στο dotNETZone.gr - Σύνδεση | Εγγραφή | Βοήθεια

Παρουσίαση με Ετικέτες

Όλες οι Ετικέτε... » Design-Patterns   (RSS)
There are many solutions on the net for avoiding the null check. Here is mine: public interface Option<T> { } public struct Nothing<T> : Option<T> { } public struct Just<T> : Option<T> {     public readonly T Value;     public Just(T value) { Value = value; } } public static class OptionExtentions {     public static Option<T> ToOption<T>(this T value)     {         return (value == null)             ? new Nothing<T>() as Option<T>             : new Just<T>(value);     }     public static U Select<T, U>(this Option<T> option,       Func<T, U> func) where U : class     {         return option.Select(func, () => null);     }     public static U Select<T, U>(this Option<T> option,        Func<T, U> whereJust, Func<U> whereNothing)       where U : class     {         return option is Just<T>             ? whereJust(((Just<T>)option).Value)             : whereNothing();     } } And implementation return from h [...]
Δημοσιεύτηκε στις Τρίτη, 20 Δεκεμβρίου 2011 5:42 μμ από napoleon | 0 σχόλια
Δημοσίευση στην κατηγορία: ,
General reference in fp patterns and idioms. More
Δημοσιεύτηκε στις Τετάρτη, 15 Ιουνίου 2011 10:55 πμ από napoleon | 0 σχόλια
Δημοσίευση στην κατηγορία: , ,