Back to Devexpress

CustomAttribute Class

xpo-devexpress-dot-xpo-8324e8c2.md

latest2.6 KB
Original Source

CustomAttribute Class

Specifies a custom attribute for a class or a class member.

Namespace : DevExpress.Xpo

Assembly : DevExpress.Xpo.v25.2.dll

NuGet Package : DevExpress.Xpo

Declaration

csharp
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Interface, Inherited = true, AllowMultiple = true)]
public sealed class CustomAttribute :
    Attribute
vb
<AttributeUsage(AttributeTargets.Class Or AttributeTargets.Property Or AttributeTargets.Field Or AttributeTargets.Interface, Inherited:=True, AllowMultiple:=True)>
Public NotInheritable Class CustomAttribute
    Inherits Attribute

Remarks

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.

Example

The code below shows how to declare this attribute:

csharp
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:

csharp
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;

Inheritance

Object Attribute CustomAttribute

See Also

CustomAttribute Members

LoadXmlMetadata

Built-In Attributes

DevExpress.Xpo Namespace