question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to configure all subtypes of a base class

See original GitHub issue

Should 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:closed
  • Created 3 years ago
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
gmkadocommented, Jun 7, 2020

@Mike-E-wins thanks for the quick response! Just tested your fix and it works for me.

0reactions
Mike-E-angelocommented, Jul 6, 2020

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found