示例#1
0
文件: Guard.cs 项目: JASGames/IsSharp
        public static void Is <TException>(Expression <Func <bool> > condition) where TException : Exception
        {
            if (condition.Compile().Invoke())
            {
                return;
            }
            var conditionString = ConditionToEnglish.Translate(condition.Body);

            throw (Exception)Activator.CreateInstance(typeof(TException), conditionString);
        }
示例#2
0
        public IsCondition <T> Check <TException>(Expression <Func <T, bool> > expression) where TException : Exception
        {
            if (!(expression.Compile().Invoke(_value)))
            {
                var conditionString = ConditionToEnglish.Translate(expression.Body, _name, _value);
                throw (Exception)Activator.CreateInstance(typeof(TException), conditionString);
            }

            return(this);
        }