I want to take a class I have and split it up into several little classes so it becomes easier to maintain and read. But this class that I try to split using partial
is a static class.
I saw in an example on Stackoverflow that this was possible to do but when I do it, it keeps telling me that I cannot derive from a static class as static classes must derive from object.
So I have this setup:
public static class Facade
{
// A few general methods that other partial facades will use
}
public static partial class MachineFacade : Facade
{
// Methods that are specifically for Machine Queries in our Database
}
Any pointers? I want the Facade
class to be static so that I don't have to initialize it before use.
You can not inherit a static class.
Keep naming and modifiers consistent across files:
C# doesn't support inheritance from a static class.
You have to choose between your classes being static:
...or whether you wish MachineFacade to derive from Facade:
The problem is not that the class is a
partial
class. The problem is that you try to derive astatic
class from another one. There is no point in deriving astatic
class because you could not make use Polymorphism and other reasons for inheritance.If you want to define a
partial
class, create the class with the same name and access modifier.you do not need to override anything, just give them the same name: