This thread looks to be a little on the old side and therefore may no longer be relevant. Please see if there is a newer thread on the subject and ensure you're using the most recent build of any software if your question regards a particular product.
This thread has been locked and is no longer accepting new posts, if you have a question regarding this topic please email us at support@mindscape.co.nz
|
I have a rather interesting requirement: A client wants some validation rules run over all strings entered into the system. Since we are using LightSpeed already for our validation (e.g. required fields) I'd like to hook this into the LightSpeed validation system. Is there a way to resolve or add validators against a field at runtime? That way I could inspect the various fields and make the decission to add the validator if it is a string in code. |
|
|
I can't see any way of doing that. The validation model runs directly off field attributes, so you can't even wedge in synthetic attributes using the TypeDescriptor family (because even if we did consult TypeDescriptor, it only supports properties, not fields). PostSharp? |
|
|
Damn. Ok, how do you add a custom validator in the designer to a field? Is it through the custom attributes screen? |
|
|
No, custom attributes end up on the CLR properties, not the fields: they're useful for things like DescriptionAttribute, BrowsableAttribute and all that jazz. Custom validations can only be added through the LightSpeed Model explorer. Right-click the property in the tree view, choose Add New Custom Validation, and enter the attribute declaration exactly as you want it to appear in the output code (excluding the square brackets) e.g. MyCompany.MyProject.MyStringValidation(true, 123, "Hello mum") |
|