Пример #1
0
        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.");
            }
        }
Пример #2
0
        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.");
            }
        }
Пример #3
0
        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);
        }
Пример #4
0
        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);
        }