1

I have a FormDialog that has LUIS entities bound to the state.

public abstract class AbstractFormDialog
{
    [Optional]
    public string Entity1;

    [Optional]
   public string Entity2;

    [Optional]
    public string Entity3;

    [Optional]
    public string Entity4;

    [Optional]
    public string Entity5;
}

In a subclass of AbstractFormDialog, I want to be able to say that some of these entities are required, so that "no preference" is not an option. Something like

public abstract class FormDialog1 : AbstractFormDialog
{
    [Required]
    public string Entity1;

    [Required]
   public string Entity2;
}

Does anyone know if this is possible? Of course I could make all attributes required in the base class, and then in every class which extends it, list which entities are actually optional. This design is bad though, because if a new Entity were to be added every subclass would need to be updated.

Daniel A. White
  • 187,200
  • 47
  • 362
  • 445
Kah
  • 627
  • 2
  • 11
  • 28
  • Depends on how the attributes are read from reflection. If it uses the actual `AbstractFormDialog` type to read the data, then there's probably nothing you can do. If it gets the attributes based on the instance, then you could make your fields properties instead and override it. Other than that, you could see if whatever checks the attributes also checks the `TypeDescriptor` http://stackoverflow.com/questions/12143650/how-to-add-property-level-attribute-to-the-typedescriptor-at-runtime – TyCobb Jun 20 '16 at 18:39

1 Answers1

1

You can also control this by utilizing the Field APIs at runtime when you build your form, i.e. new FormBuilder() .Field(new FieldReflector(nameof(FormDialog1.Entity1)) .SetOptional(false)) .Build(); This would make the Entity1 field for this instance "Required".

Chris McConnell
  • 108
  • 1
  • 5