Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Interesting question! I can think of two work-arounds to this. So not proper solutions based on what you want but they might help to re-use your code. Cant you create a CustomAttribute abstract class called MyCustomAttribute (or something) that overrides IsValid in the following way:</p> <pre><code>public override bool IsValid(object value) { var model = (MyObject) value; //if this value is set, I don't want to do anything other checks if (model.Prop3) { return true; } CustomValidate(model); } </code></pre> <p><code>CustomValidate(MyObject model)</code> is your abstract method then, you can write multiple custom attribute classes that extend MyCustomAttribute and purely need to implement the validation logic for A particular scenario. </p> <p>So you can have two classes:</p> <pre><code>public class BlahCustomAttribute : MyCustomAttribute { public override Boolean CustomValidate(MyObject obj) { if (model.Prop1 == "blah" &amp;&amp; model.Prop2 == 1) { ErrorMessage = "you can't enter blah if prop 2 equals 1"; return false; } } } public class BlahBlahCustomAttribute : MyCustomAttribute { public override Boolean CustomValidate(MyObject obj) { if (model.Prop1 == "blah" &amp;&amp; model.Prop2 == 1) { ErrorMessage = "you can't enter blah blah if prop 2 equals 1"; return false; } } } </code></pre> <p>Hope this helps - not exactly what you wanted but will do the job and its clean as well.</p> <p>The other solution is to comma-separate the error messages in the ErrorMessage property and handle it in the front-end (but I would go with the first approach).</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload