Esempio n. 1
0
        // Chainable version
        public static TValue N <TParent, TMiddle, TValue>(
            TParent o,
            Func <TParent, TMiddle> midAccessor,
            Func <TMiddle, TValue> valAccessor
            )
            where TMiddle : class
            where TValue : class
        {
            var mid = NN.N(o, midAccessor);

            return(NN.N(mid, valAccessor));
        }
Esempio n. 2
0
 public static string AppendSpace <T>(T o)
 {
     return(NN.S(o, _ => _ + " "));
 }
Esempio n. 3
0
 public static string PrependSpace <T>(T o)
 {
     return(NN.S(o, _ => " " + _));
 }
Esempio n. 4
0
 /// <summary>
 /// Guarantees return of null or value, given a prop you want to access, even if the parent in the first argument
 /// is null (instead of throwing).
 ///
 /// Usage:
 ///
 /// NN.N(myObjThatCouldBeNull, o => o.ChildPropIWant)
 /// </summary>
 /// <returns>Null if that prop is null, or if the child prop is null. The value of the prop if both are set.</returns>
 public static TValue N <TParent, TValue>(TParent o, Func <TParent, TValue> accessor)
     where TValue : class
 {
     return(NN.N(o, accessor, null));
 }
Esempio n. 5
0
 /// <summary>
 /// Returns 0 if parent is null
 /// </summary>
 public static int Z <T>(T o, Func <T, int> accessor)
 {
     return(NN.N(o, accessor, 0));
 }
Esempio n. 6
0
 /// <summary>
 /// If the string argument is null, returns an empty string.
 /// If it's not, runs formatter on it and returns the result.
 /// Useful for situations like:
 ///
 /// @Model.Address.City where Address could be null. Use:
 ///
 /// @NN.S(Model.Address, a => a.City)
 ///
 /// Will return an empty string or City, depending on whether Address is null.
 ///
 /// You can make it even shorter if you want by aliasing in the page like:
 ///
 /// var nn = NN.S;
 /// @nn(Model.Address, a => a.City)
 ///
 /// "blah " + myString + " blah" where myString could be null and blow up the whole thing.
 /// Becomes:
 /// "blah" + NN.S(myString, s => " " + s) + " blah"
 ///
 /// Shorthand for:
 /// "blah" + (myString == null ? "" : " " + myString) + " blah"
 /// </summary>
 /// <param name="s"></param>
 /// <param name="accessor"></param>
 /// <returns></returns>
 public static string S <T>(T o, Func <T, string> accessor)
 {
     return(NN.N(o, accessor, ""));
 }