Commands w/ body defined in abstract classes aren't registered in subclasses unless virtual & overriden
See original GitHub issueSummary
Commands declared in abstract classes extending BaseCommandModule
do not propagate into their subclasses unless they are implemented or overriden in the subclass. This is both a bug report and a feature request, since it seems to be an oversight.
Details
Expected behavior
Registering a command in an abstract class, the command is propagated into whatever modules inherit that class
Actual behavior
The registered command doesn’t appear in the subclass.
Steps to reproduce
public abstract class BaseTestModule : BaseCommandModule
{
// works: subclass is required to override the method, and the command is registered there
[Command("atest")]
public abstract Task Test1(CommandContext ctx);
// works only if the subclass registers an `override` method for it
[Command("atest2")]
public virtual Task Test2(CommandContext ctx)
{
Console.WriteLine("Super");
return Task.CompletedTask;
}
// doesn't work, method is not registered in the subclass
[Command("atest3")]
public Task Test3(CommandContext ctx)
{
Console.WriteLine("Super");
return Task.CompletedTask;
}
}
[Group("test")]
public class TestImplementation : BaseTestModule
{
// works, will print test1
public override Task Test1(CommandContext ctx)
{
Console.WriteLine("test1");
return Task.CompletedTask;
}
// works, will print test2
public override Task Test2(CommandContext ctx)
{
Console.WriteLine("test2");
return Task.CompletedTask;
}
// atest3 doesn't work, doesn't print anything
}
Issue Analytics
- State:
- Created 5 years ago
- Comments:6 (6 by maintainers)
Top Results From Across the Web
Problem creating abstract class with no virtual pure ...
I want to create a class that is a subclass of two classes that have a common virtual base class. Furthermore, I want...
Read more >What happens if the subclass does not override abstract ...
What happens if the subclass does not override abstract methods in java - A method which does not have body is known as...
Read more >Is inheriting from a non-abstract class bad OOP?
The problem is that inheriting from a class with no virtual methods, will cause you problems if you inherit from it and overwrite...
Read more >Class Abstraction - Manual
PHP has abstract classes and methods. Classes defined as abstract cannot be instantiated, and any class that contains at least one abstract method...
Read more >Pure Virtual Functions and Abstract Classes in C++
A Computer Science portal for geeks. It contains well written, well thought and well explained computer science and programming articles, ...
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
It’s still an issue, I just wrote the wrong steps to reproduce it.
This is intentional.