Is there a way to create interface with attribute which has to be used by the class that implements interface?
I.e. if class Foo implements interface IFoo, and IFoo is defined to must have ObserveMeAttribute, then Foo must have ObserveMe defined on it in order to implement IFoo.
Edit:
Attribute is called EntityTypeAttribute and is used to specify entity type for the view model, with usage:
[EntityType(typeof(User))]
public class UserViewModel
{
...
}
Attribute is used in an extension method AddModel(T TModel) where attribute is read from TModel, and it's property Type entityType is used to create entity stub object.
Simple answer is "no". If every object must have this value to implement IFoo why don't you make it part of the IFoo interface?
Attributes are primarily a mechanism for finding additional declarative information about a class/method/parameter at run-time by using reflection.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With