Advertisement
Guest User

Untitled

a guest
Jun 25th, 2019
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.41 KB | None | 0 0
  1. public static class Guard
  2. {
  3. public static void IsNotNull<T>(Expression<Func<T>> expression)
  4. {
  5. var param = (MemberExpression)expression.Body;
  6. var fieldInfo = (FieldInfo)param.Member;
  7. var paramValue = fieldInfo.GetValue(((ConstantExpression)param.Expression).Value);
  8.  
  9. if (paramValue == null)
  10. {
  11. throw new ArgumentNullException(fieldInfo.Name);
  12. }
  13. }
  14. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement