DataMan:
[Sorry for the delay. I attempted to post this on Tuesday, but for whatever reason it doesn't seem to have made it to the forum.]
In order for a verification error to be diagnosed upon *setting* the SortOrder value, you would need a call to BeforeSetValue() in the SortOrder setter. You can code the call to BeforeSetValue() yourself in the setter in your SortOrder override, or you can get the Object Mapper to generate it for you (into the base class).
To do the latter, open the Verifications Options dialog and select the RadioButton to turn verification code generation On. Having done that, you can still turn off the generation of attributed verifiers by unchecking the "Generate predefined verifiers" CheckBox. You can also turn off the generation of BeforeSetValue() or AfterSetValue() calls, as the default, by selecting "Neither" in the Property Setter Options area of the dialog. Then, on the Simple Properties tab on the main Object Mapper dialog, you can turn on the generation of that call for the SortOrder property (only).
None of above, however, is required to make your instance verification work properly. All that is required for that is (a) to add the attribute to define the verifier (as you have done); and (b) to call instance verification and properly deal with the result. Here's an example of using instance verification on an Employee instance:
void mPersMgr_Saving(object sender, EntitySavingEventArgs e) {
foreach (Entity anEntity in e.Entities) { if (anEntity is Employee) { Employee anEmployee = (Employee)anEntity; VerifierResultCollection aVerifierResultCollection = anEmployee.VerifierEngine.Execute(anEmployee); foreach (VerifierResult result in aVerifierResultCollection) { if (!result.IsOk) { MessageBox.Show("Employee [" + anEmployee.LastFirst + "] failed verification. Save cancelled."); e.Cancel = true; return; } } } } }
In the above code, if the IsOK property of any VerifierResult returned by the call to VerifierEngine.Execute() is false, the save is cancelled.
Regards,
Greg Dunn
IdeaBlade
|