У меня есть два пользовательских атрибута, определенные как так:
internal class SchemaAttribute : Attribute {
internal SchemaAttribute(string schema) {
Schema = schema;
}
internal string Schema { get; private set; }
}
internal class AttributeAttribute : Attribute {
internal AttributeAttribute(string attribute) {
Attribute = attribute;
}
internal string Attribute { get; private set; }
}
Я хотел бы ограничить SchemaAttribute классами и AttributeAttribute к свойствам.
Действительно ли это выполнимо?
См. AttributeUsage и AttributeTargets .
Это будет примерно так:
[AttributeUsage(AttributeTargets.Class)]
internal class SchemaAttribute : Attribute
{
// Implementation
}
[AttributeUsage(AttributeTargets.Property)]
internal class AttributeAttribute : Attribute
{
// Implementation
}
Посмотрите на AttributeTargetAttribute
[AttributeTarget(AttributeTargets.Class)]
internal class SchemaAttribute : Attribute
...
[AttributeTarget(AttributeTargets.Property)]
internal class AttributeAttribute: Attribute
...