I have created a custom validator that I wish to put on one of my
business objects attributes to do validation before an object is
persisted to the database.

In order for validation to be successful though I need to be able to
pass in the variable to the custom validator, it is NOT a constant
like all the other examples I've seen.  How do you do this???  For
instance where I have ExamType="blah" below, I need to be able to pass
in the actual exam type property from the business object which is
contained in the same class, but I don't see how you can do that.

    public class ActiveContentCodeAttribute : Attribute, IRuleArgs
    {
        private string _examType = string.Empty;
        public string ExamType
        {
            get { return _examType; }
            set { _examType = value; }
        }
    }

    public class ActiveContentCodeValidator :
IInitializableValidator<ActiveContentCodeAttribute>
    {
        private string _examType = string.Empty;
        public bool IsValid(object value)
        {
            //TODO: Check database to see if the examtype is already
active
            return true;
        }
        public void Initialize(ActiveContentCodeAttribute parameters)
        {
            _examType = parameters.ExamType;
        }
    }

And on my business object class I have done this:

        [ActiveContentCode(ExamType="blah")
        public virtual bool Active
        {
            get { return _active; }
            set
            {
                OnActiveChanging();
                _active = value;
                OnActiveChanged();
            }
        }

-- 
You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/nhusers?hl=en.

Reply via email to