public static void ObjectNotNull(Expression <Func <object> > propertyExpression) { var func = propertyExpression.Compile(); var obj = func(); if (obj == null) { var propertyName = ExpressionHandler.GetPropertyName(propertyExpression); throw new ArgumentException($"Object {propertyName} must not be null."); } }
public static void StringNotNullorEmpty(Expression <Func <string> > propertyExpression) { var func = propertyExpression.Compile(); var stringValue = func(); if (string.IsNullOrEmpty(stringValue)) { var propertyName = ExpressionHandler.GetPropertyName(propertyExpression); throw new ArgumentException($"String {propertyName} must not be null or empty."); } }
public static void StringNotNullOrEmpty(Expression <Func <string> > propertyExpression) { var func = propertyExpression.Compile(); var stringValue = func(); if (!string.IsNullOrEmpty(stringValue)) { return; } var propertyName = ExpressionHandler.GetPropertyName(propertyExpression); var exceptionMessage = string.Format(StringNullOrEmptyExceptionMessage, propertyName); throw new ArgumentException(exceptionMessage); }
public static void ObjectNotNull(Expression <Func <object> > propertyExpression) { var func = propertyExpression.Compile(); var obj = func(); if (obj != null) { return; } var propertyName = ExpressionHandler.GetPropertyName(propertyExpression); var exceptionMessage = string.Format(NullObjectExceptionMessage, propertyName); throw new ArgumentException(exceptionMessage); }