I suggest you ...

Static Interfaces

I've been thinking about static interfaces, and I think they would be really useful for software which uses reflection to identify and assemble components. Currently I find myself having to design around this limitation with unnecessary factories or by enforcing conditions at runtime (like checking for methods and throwing exceptions if they aren't present).
It would be great if the following was possible:

foreach (var type in Assembly.GetExecutingAssembly().GetTypes().Where(t => t is IStaticInterfaceType))
(type as IStaticInterfaceType).StaticMethod();
This could be used for singleton patterns, initialization methods, registration methods, constructor contracts, or any number of other things.

I don't know how much overhead this would introduce, but perhaps this would be possible by making every class have its own corresponding Type. This type would be derived from Type and would implement the static interfaces for the type.

This would allow for much safer use of reflection (which is a brilliant tool for keeping things modular and for reducing code bulk).

24 votes
Vote
Sign in
Check!
(thinking…)
Reset
or sign in with
  • facebook
  • google
    Password icon
    I agree to the terms of service
    Signed in as (Sign out)
    You have left! (?) (thinking…)
    Johannes MoerschJohannes Moersch shared this idea  ·   ·  Flag idea as inappropriate…  ·  Admin →

    2 comments

    Sign in
    Check!
    (thinking…)
    Reset
    or sign in with
    • facebook
    • google
      Password icon
      I agree to the terms of service
      Signed in as (Sign out)
      Submitting...

      Feedback and Knowledge Base