How to configure all subtypes of a base class
See original GitHub issueShould inheritance be observed in the ConfigurationContainer
?
Say I have the following setup:
public abstract class CommandListDTO
{
...
public abstract List<Type> AllowableCommandTypes { get; }
}
public class CommandList1: CommandListDTO
{
public override List<Type> AllowableCommandTypes { get; } = new List<Type>
{
typeof(Command1),
typeof(Command2),
};
}
Is there a way to configure all subclasses to i.e. ignore AllowableCommandTypes
?
I tried
.Type<CommandListDTO>().Member(x => x.AllowableCommandTypes).Ignore()
But it seems I have to type this out for all child classes to get it to work:
.Type<CommandList1>().Member(x => x.AllowableCommandTypes).Ignore()
.Type<CommandList2>().Member(x => x.AllowableCommandTypes).Ignore()
.Type<CommandList3>().Member(x => x.AllowableCommandTypes).Ignore()
Issue Analytics
- State:
- Created 3 years ago
- Comments:8 (5 by maintainers)
Top Results From Across the Web
C# - Create instance of all sub classes of a generic base ...
Get all derivative class of BaseClass<T> var allSubTypes = AppDomain.CurrentDomain.GetAssemblies() .SelectMany(a=>a.GetTypes()) .
Read more >Base class should have no knowledge of its subtypes?
If a class knows about its subtypes, that implies you can't just add one (extend the class) without modifying the base type (which...
Read more >Inheritance - Learning the Java Language
A subclass inherits all the members (fields, methods, and nested classes) from its superclass. Constructors are not members, so they are not inherited...
Read more >Inheritance
Inheritance - derive types to create more specialized behavior · In this article · Abstract and virtual methods · Abstract base classes ·...
Read more >Class modifiers
The base class constructor is called whenever an instance of a subtype of the class is created. All implemented private members exist in...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@Mike-E-wins thanks for the quick response! Just tested your fix and it works for me.
Ahhh good point @gmkado that’s a different extension so it has its own set of rules/implementations. I am not sure about quick/easy but I will find out. 😁 Captured in #411. Please be sure to let me know of any others you find as well.