Dynamic Properties. Learn More
DynamicPropertiesObject and XAF validation
If necessary, it is possible to apply validation mechanism to DynamicPropertiesObject objects. To do this verifiable Dynamic Property must have special rule attributes derived from RuleBaseAttribute.
- c#
- VB
public class DynamicPropertiesValidationSupport : BaseObject
{
public DynamicPropertiesValidationSupport(Session session)
: base(session)
{
}
public CreateDynamicObjectWithValidationRule()
{
var dpl = new DynamicPropertyList();
var rule = new List<Attribute>();
//Add validation rule to list of attributes
rule.Add(new RuleRequiredFieldAttribute());
//Add new Dynamic Property to list
dpl.Add(new DynamicProperty("RuleRequiredField", typeof(string), "1", true, /*rule contains added validation rule*/ rule));
//Create dynamic object, pass Dynamic properties collection
this.Dpo = DynamicPropertiesObject.CreateObject<DynamicPropertiesObject>(dpl);
}
public DynamicPropertiesObject Dpo { get; private set; }
}
Public Class DynamicPropertiesValidationSupport
Inherits BaseObject
Private _Dpo As DynamicPropertiesObject
Public Sub New(ByVal session As Session)
MyBase.New(session)
End Sub
Public Sub New()
Dim dpl = New DynamicPropertyList()
Dim rule = New List(Of Attribute)()
'Add validation rule to list of attributes
rule.Add(New RuleRequiredFieldAttribute())
'Add new Dynamic Property to list
dpl.Add(New DynamicProperty("RuleRequiredField", GetType(String), "1", True, 'rule contains added validation rulerule))
'Create dynamic object, pass Dynamic properties collection
Me._Dpo = DynamicPropertiesObject.CreateObject(Of DynamicPropertiesObject)(dpl)
End Sub
Public ReadOnly Property Dpo As DynamicPropertiesObject
Get
Return _Dpo
End Get
End Property
End Class
Thus, when creating Dynamic Property it is sufficient to specify constructor parameters properly, you should specify a such DynamicProperty.Attributes collection, which contains the validation attributes. No additional manipulation to initialize Dynamic Property do not need. If the standard validation Actions for some reason are not active, then to check the validity of the object is sufficient to use one of the validation methods of DevExpress.Persistent.Validation.RuleSet class. Use static property of the DevExpress.Persistent.Validation.Validator class to access RuleSet class. The following code snippet demonstrates how to call RuleSet.Validate for Dpo object.
obj represent DynamicPropertiesValidationSupport and Dpo - DynamicPropertiesObject.