xpo-devexpress-dot-xpo-8324e8c2.md
Specifies a custom attribute for a class or a class member.
Namespace : DevExpress.Xpo
Assembly : DevExpress.Xpo.v25.2.dll
NuGet Package : DevExpress.Xpo
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Interface, Inherited = true, AllowMultiple = true)]
public sealed class CustomAttribute :
Attribute
<AttributeUsage(AttributeTargets.Class Or AttributeTargets.Property Or AttributeTargets.Field Or AttributeTargets.Interface, Inherited:=True, AllowMultiple:=True)>
Public NotInheritable Class CustomAttribute
Inherits Attribute
The CustomAttribute class allows you to provide custom parameters for a class or a class member. The attribute’s name is specified by the CustomAttribute.Name property. Its value is specified by the CustomAttribute.Value property.
The code below shows how to declare this attribute:
using DevExpress.Xpo;
namespace DXSample {
public class Person :XPObject {
public Person(Session session) : base(session) { }
//...
private int fAge;
[Custom("Validation", "Age between (20, 40)|The age can be between 20 and 40 years old")]
public int Age {
get {
return fAge;
}
set {
SetPropertyValue("Age", ref fAge, value);
}
}
}
}
To get the attribute value, use the following code:
using DevExpress.Xpo;
using DevExpress.Xpo.DB;
//...
var uow = new UnitOfWork();
var person = new Person(uow);
var ageMember = person.ClassInfo.FindMember(nameof(Person.Age));
CustomAttribute attribute = (CustomAttribute)ageMember.FindAttributeInfo("Validation");
string attributeValue = attribute.Value;
Object Attribute CustomAttribute
See Also