czetsuya
czetsuya

Reputation: 5093

C# MVC3 storing MetaData in a single class

Is it possible to store the metadata information of 2 models in a single class?

For example I'm working on Login and Registration model, both has username and password. Usually we create another class that will contain the meta data information: LoginMetadata and RegistrationMetadata. Or put the metadata information in the Login and Registration class.

What I want to do is to create a single UserMetadata class then store the combined metadata information from Login and Registration model in it. In this case I have a single validation rule for username, password, etc. Is that possible?

Regards, czetsuya

Upvotes: 0

Views: 194

Answers (1)

Espen Burud
Espen Burud

Reputation: 1881

It´s not possible to store metadata for multiple classes in one class.

The MetaDataTypeAttribute is decorated with [AttributeUsageAttribute(AttributeTargets.Class, AllowMultiple = false)], so it can only be used on classes and can only be used once. It means that you cannot not define a class as a metadata placeholder for multiple classes.

Link to MSDN Documentation for MetaDataTypeAttribute.

Upvotes: 1

Related Questions