How to make data annotations for an object in another assembly?

I have an abstract domain object that is used by both a web application and Windows . This domain object is in the old namespace along with any derived classes.

For my web application, I would like to use data annotations . Usually I created a partial class for the domain object and provided it with the MetaData strong> class . However, I cannot touch the namespace where the domain objects are located , and there is my problem.

Is there any solution for providing partial classes / metadata to domain objects in another namespace? Remember that I cannot touch the namespace of domain objects at all.

+3
source share
2 answers

DataAnnotations works by decorating type properties with attributes, or decorating the actual type with a MetadataTypeAttributethat points to the actual class that contains the validation attributes.

If you cannot touch it, you cannot use DataAnnotations. It is so simple. You can try a code conversion technique such as CCI to change the assembly without touching the code, but in the end you touch it anyway.

. , : " " , (XML).

.

+1

, , .

, -. . , , MetadataTypeAttribute, , , , ..

, .

0

Source: https://habr.com/ru/post/1767911/


All Articles