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,

Reply to this discussion

Internal reply

Formatting help / Preview (switch to plain text) No formatting (switch to Markdown)

Attaching KB article:


Attached Files

You can attach files up to 10MB

If you don't have an account yet, we need to confirm you're human and not a machine trying to post spam.

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