view SilverlightGlimpse/Models/ExceptionWrapper.cs @ 60:fc62c971a117

upload to blog
author Steven Hollidge <stevenhollidge@hotmail.com>
date Sat, 21 Apr 2012 21:19:39 +0100
parents 3591c26bd63e
children
line wrap: on
line source

using System;
using System.Windows.Controls;

namespace SilverlightGlimpse.Models
{
    public class ExceptionWrapper
    {
        #region Fields

        private bool _isValidationException = false;
        private ValidationErrorEventAction _enumAction = ValidationErrorEventAction.Added;
        private Exception _exception;
        private string _controlName = string.Empty;

        #endregion

        #region Constructor

        public ExceptionWrapper(Exception e)
        {
            _exception = e;
        }

        #endregion

        #region Properties

        public ExceptionWrapper(ValidationErrorEventAction enumAction, string controlName, Exception validationException)
        {
            _enumAction = enumAction;
            _controlName = controlName;
            _exception = validationException;
            _isValidationException = true;
        }

        public ValidationErrorEventAction Action { get { return _enumAction; } }
        public string ControlName { get { return _controlName; } }
        public Exception Exception { get { return _exception; } }
        public bool IsValidationException { get { return _isValidationException; } }

        #endregion

        #region Methods

        public override string ToString()
        {
            return _isValidationException
                ? string.Format("({0}) - {1}", this.Action, Exception.Message)
                : Exception.Message;
        }

        #endregion
    }
}