private static Func <T, int> MakeGetHashCodeNotNull <T>() where T : struct { var param = Expression.Parameter(typeof(T), "input"); return(Expression.Lambda <Func <T, int> >(NullSafetyExpression.Create(param, p => p.Call(nameof(GetHashCode))), param).Compile()); }
/// <summary> /// Creates a new safe navigation expression. /// </summary> /// <param name="target">The expression that is guarded by <see langword="null"/> check.</param> /// <param name="body">The body to be executed if <paramref name="target"/> is not <see langword="null"/>. </param> /// <returns>The expression representing safe navigation.</returns> public static NullSafetyExpression Create(Expression target, Func <ParameterExpression, Expression> body) { var result = new NullSafetyExpression(target); result.Body = body(result.Target); return(result); }
private static Func <T, string> MakeToString <T>() { var param = Expression.Parameter(typeof(T), "input"); return(Expression.Lambda <Func <T, string> >(NullSafetyExpression.Create(param, p => p.Call(nameof(ToString))), param).Compile()); }