© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•2y ago•
11 replies
Marius 🗡

Is there a way to block the calling of public method from abstract class inside a derived one?

It makes sense to just not call it, but is there a way to prevent it?

example:
public abstract class Abstract
{
    public void Launch() { } // calls some inner private methods belonging to the abstract class itself does work with its data.
}

public class Derived : Abstract
{
    private void SomeMethod()
    {
        Launch(); // <-- is it possible to block such call? 
    }
}

// i would use that launch method in other outer class that uses other specific derived classes and calls the launch method like this:

public class Foo()
{
    public void DoWork()
    {
        Launch<Derived>();
    }
 
    void Launch<T>() where T : Abstract
    {
        Abstract specificClass = (T)Activator.CreateInstance(typeof(T));
        specificClass.Launch();
    }
}
public abstract class Abstract
{
    public void Launch() { } // calls some inner private methods belonging to the abstract class itself does work with its data.
}

public class Derived : Abstract
{
    private void SomeMethod()
    {
        Launch(); // <-- is it possible to block such call? 
    }
}

// i would use that launch method in other outer class that uses other specific derived classes and calls the launch method like this:

public class Foo()
{
    public void DoWork()
    {
        Launch<Derived>();
    }
 
    void Launch<T>() where T : Abstract
    {
        Abstract specificClass = (T)Activator.CreateInstance(typeof(T));
        specificClass.Launch();
    }
}
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Is there a way to return or access a class object created inside a public partial class (form) from
C#CC# / help
3y ago
Is there a way to unload a class from the ram?
C#CC# / help
5mo ago
✅ Is there a way to run a commands method inside of another command? (DSharpPlus)
C#CC# / help
3y ago