KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
All I want to do is make sure that child classes of the class Item implement a static method and I want this to be checked at compile time to avoid runtime errors. abstract classes with static methods don't seem to work: ERROR: A static member cannot be marked as override, virtual, or abstract public abstract class Item { public static abstract Item GetHistoricalItem(int id, DateTime pastDateTime); } public class Customer : Item { public static override Customer GetHistoricalItem(int id, DateTime pastDateTime) { return new Customer(); } } public class Address : Item { public static override Address GetHistoricalItem(int id, DateTime pastDateTime) { return new Address(); } } and interfaces don't seem to work either: ERROR: Customer does not implement interface member GetHistoricalItem() public class Customer : Item, HistoricalItem { public static Customer GetHistoricalItem(int id, DateTime pastDateTime) { return new Customer(); } } public class Address : Item, HistoricalItem { public static Address GetHistoricalItem(int id, DateTime pastDateTime) { return new Address(); } } interface HistoricalItem { Item GetHistoricalItem(); } Is there some workaround for this to have the compiler check if inheriting classes implement a static method with a certain signature or not?
Tags (comma-separated)
Save Edits
Cancel