Exemplo n.º 1
0
        private void Throw(bool forceToThrowException)
        {
            if (this.m_ErrorMessages.Count <= 0)
            {
                return;
            }

            ErrorMessageScope <T> outsideValidationScope = ErrorMessageManager <T> .Peek();

            if (forceToThrowException || outsideValidationScope == null)
            {
                throw (Exception)Invoker.CreateInstance <T>(m_MergeMessageHandler(this.m_ErrorMessages));
            }
            else
            {
                outsideValidationScope.m_ErrorMessages.AddRange(this.m_ErrorMessages);
            }
        }
Exemplo n.º 2
0
        public ErrorMessageScope(Func <IEnumerable <string>, string> mergeMessageHandler, bool forceToThrowExceptionIfHasErrorsWhenDisposing = false)
        {
            ConstructorInfo constructor = typeof(T).GetConstructor(new Type[] { typeof(string) });

            if (constructor == null)
            {
                throw new ArgumentException(string.Format("The exception type {0} with generic agument doesn't include an constructor in prototype \"ctor (string)\".", typeof(T)));
            }

            if (mergeMessageHandler == null)
            {
                m_MergeMessageHandler = new Func <IEnumerable <string>, string>(list => RemoveInterpunctionThenMerge(list));
            }
            else
            {
                m_MergeMessageHandler = mergeMessageHandler;
            }

            this.ForceToThrowExceptionIfHasErrorsWhenDisposing = forceToThrowExceptionIfHasErrorsWhenDisposing;
            ErrorMessageManager <T> .Push(this);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Dispose current validation scope.
        /// </summary>
        public void Dispose()
        {
            ErrorMessageManager <T> .Pop();

            this.Throw(this.ForceToThrowExceptionIfHasErrorsWhenDisposing);
        }