CustomAttribute Class
Specifies a custom attribute for a class or a class member.
Namespace: DevExpress.Xpo
Assembly: DevExpress.Xpo.v19.2.dll
Declaration
[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
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Field | AttributeTargets.Interface | AttributeTargets.Property, Inherited = true, AllowMultiple = true)]
public sealed class CustomAttribute :
Attribute
<AttributeUsage(AttributeTargets.Class Or AttributeTargets.Field Or AttributeTargets.Interface Or AttributeTargets.Property, 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.
Example
This sample demonstrates how to load metadata from a string in XML format.
public bool IsDisplayNameAttributeSpecified(string className) {
string xmlMetaData =
"<Model xmlns=\"http://www.devexpress.com/products/xpo/schemas/1.9/xpometadata.xsd\">" +
"<Class assembly=\"" + "WindowsApplication" + "\" type=\"" + className + "\">" +
" <Attributes>" +
" <CustomAttribute Name=\"DisplayName\" Value=\"Test person\"/>" +
" <CustomAttribute Name=\"ReadOnly\" Value=\"true\"/>" +
" </Attributes>" +
"</Class>" +
"</Model>";
ReflectionDictionary dict = new ReflectionDictionary();
dict.LoadXmlMetadata(new System.IO.StringReader(xmlMetaData));
XPClassInfo ci = dict.GetClassInfo("WindowsApplication", className);
if (ci.HasAttribute("DisplayName"))
return true;
return false;
}
Public Function IsDisplayNameAttributeSpecified(ByVal className As String) As Boolean
Dim xmlMetaData As String = _
"<Model xmlns=""http://www.devexpress.com/products/xpo/schemas/1.9/xpometadata.xsd"">" & _
"<Class assembly=""WindowsApplication"" type=""" & className & """>" & _
"<Attributes>" & _
"<CustomAttribute Name=""DisplayName"" Value=""Test person""/>" & _
"<CustomAttribute Name=""ReadOnly"" Value=""true""/>" & _
"</Attributes>" & _
"</Class>" & _
"</Model>"
Dim dict As New ReflectionDictionary()
dict.LoadXmlMetadata(New System.IO.StringReader(xmlMetaData))
Dim ci As XPClassInfo = dict.GetClassInfo("WindowsApplication", className)
If ci.HasAttribute("DisplayName") Then
Return True
End If
Return False
End Function
See Also