How do I set acceptable single values for an Enum property in a Serializable class?

1

Given enum as an example:

public enum IcmsCst
{
    [XmlEnum("00")] Cst00,
    [XmlEnum("10")] Cst10,
    [XmlEnum("20")] Cst20,
    ...
}

Is there a way to annotate so that I could specify that a particular type of ICMS could only accept a certain type of% with% of that% with%?

As for example:

public class Imposto
{
    [XmlEnum(AcceptOnly = [IcmsCst.Cst00])] // como exemplo do que busco para a limitação
    public ICMS Icms00 { get; set; }
}

So,     

asked by anonymous 18.07.2018 / 22:07

1 answer

1

There is no specific mechanism ready. You can create a complete framework to handle this. Or do the simple and the time to import the information handle whether it is valid or not. Generic mechanisms are useful for reuse. So there are when it's something that everyone needs, or you should do yours if you need to use it often and this brings benefits.

Even if you do, you need to have a well thought out way of handling this, which may not be a universal form. Do not accept, so what? Neither this point is defined in the question, without the clear criterion has no good solution. However, it is very difficult to establish these criteria in code declaratively.

    
23.07.2018 / 06:37