I have an Address class that is used for both a MailingAddress and BillingAddress property in my Model. I want the MailingAddress to be required, but not the BillingAddress, but am not seeing a way to do this with DataAnnotations.
If I were able to set the [Required] attribute on the MailingAddress property and somehow define the logic for how the Address class is supposed to handle the required logic, I feel like that would be a simple solution.
Any ideas?
If your question is how to use the Required attribute in your own logic, the answer is by use of reflection. Forgive me if that is not your question.
Get all properties from the type in question, then see if it is decorated with a RequiredAttribute or not.
Edit: Fixed a typo in code
Edit 2: Extended code example