Validation of model

jurica.penjgusic's Avatar


15 Feb, 2017 10:44 AM


I was wondering, is it possible to create validation on class ?
For example, we have class Person and we want to validate all properties of that class.
But we do not want to throw exception on setter functions, we want to aggregate all errors on that class and after that return to caller method,
Situable solution is that we have method in class e.g Validate(), that will on explicit call , validate all properties that contains validation attribute in class.


  1. Support Staff 1 Posted by PostSharp Techn... on 19 Feb, 2017 08:38 PM

    PostSharp Technologies's Avatar


    sorry for the late response. We currently don't provide any aspect solving this problem so you would need to implement it yourself.

    I'm attaching a sample project solving this problem. It is not meant for production use and need a lot of polishing, but should demonstrate all concepts needed to have a usable solution. Basically usage would be to have classes derived from [ValidatorAttribute] and Validator. The main aspect [Validated] is provided automatically to the class by [ValidatorAttribute].

    If you have any question regarding the sample code, please don't hesitate to ask.

    All the best,

  2. Support Staff 2 Posted by PostSharp Techn... on 28 Feb, 2017 02:43 PM

    PostSharp Technologies's Avatar


    We are going to close this request as we believe it was solved. Please feel free to reopen the discussion if you need more help.

    Best regards,
    PostSharp Team

  3. PostSharp Technologies closed this discussion on 28 Feb, 2017 02:43 PM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts


? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac