Is there a way to simulate a static function in an interface in C#?
I want to use it for a factory, in which every object inherits from ICreateAble with a static function ‘Create’ and in the factory class you can then call Factory.Create(Type t, string fromFile) which calls t.Create()
before “answering”, I want to state that you should unchain your problem from your solution when you ask questions, as you are likely to get an answer that solves your solution even if it is not the best way to solve your underlying issue.
If you have truly genericized the creation of objects, I would consider flipping this pattern a bit and using generics to solve the problem rather than searching for a means to mimic a static method on an interface. This will require rethinking the solution, of course.
Depending on the nature of the object (state or behavior) I would also consider separating creation from the implementation. This is especially true if the object is a state object.
I would have to see more of what you are doing, but I assume you have an abstract factory that calls Create() which serves as a concrete factory … inside a static method on the object that is being created. I am not sure, wihtout additional context, that this is a good pattern. And, I am leaning towards NOT.