I’m using [Ardalis.SmartEnum](https://github.com/ardalis/SmartEnum) to model a base enum class and two derived enums:
public abstract class Templates : SmartEnum<Templates> { … }
public class TemplatesCiclo : Templates
{
public static readonly TemplatesCiclo IdentificadorPedido = new(1, nameof(IdentificadorPedido));
// … other members …
}
public class TemplatesNotaFiscal : Templates
{
public static readonly TemplatesNotaFiscal ValorNota = new(9, nameof(ValorNota));
// … other members …
}
When I iterate over TemplatesCiclo.List, I expected only the TemplatesCiclo instances, but I also get the TemplatesNotaFiscal values:
foreach (var tmpl in TemplatesCiclo.List)
{
Console.WriteLine(tmpl.Name);
// Prints both Ciclo members AND NotaFiscal members…
}
- What is causing the child class’s
List property to return every instance of the base class (including those from other subclasses)?
- How can I restrict the list so that it only contains the instances defined in
TemplatesCiclo?
Any insights into how SmartEnum registers and filters its static instances would be greatly appreciated!
I’m using [Ardalis.SmartEnum](https://github.com/ardalis/SmartEnum) to model a base enum class and two derived enums:
When I iterate over
TemplatesCiclo.List, I expected only theTemplatesCicloinstances, but I also get theTemplatesNotaFiscalvalues:Listproperty to return every instance of the base class (including those from other subclasses)?TemplatesCiclo?Any insights into how
SmartEnumregisters and filters its static instances would be greatly appreciated!