Skip to main content
.NET Framework 4.6.2+

CustomAttribute Class

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

Namespace: DevExpress.Xpo

Assembly: DevExpress.Xpo.v24.2.dll

Declaration

[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Interface, Inherited = true, AllowMultiple = true)]
public sealed class CustomAttribute :
    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:

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;

Inheritance

Object
Attribute
CustomAttribute
See Also