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.
Static classes have several limitations compared to non-static ones: A static class cannot be inherited from another class. A static class cannot be a base class for another static or non-static class. Static classes do not support virtual methods.
All parts of a partial class should be in the same namespace. Each part of a partial class should be in the same assembly or DLL, in other words you can't create a partial class in source files of a different class library project. Each part of a partial class has the same accessibility.
Static Classes and Partial Classes in C# If you have a class with only class variables and class methods (only static members), you may chose to mark the class as static. A partial class will be aggregated by contributions from several source files.
Keep naming and modifiers consistent across files:
public static partial class Facade
{
// A few general methods that other partial facades will use
}
public static partial class Facade
{
// Methods that are specifically for Machine Queries in our Database
}
The problem is not that the class is a partial
class. The problem is that you try to derive a static
class from another one. There is no point in deriving a static
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With