I suggest you ...

Allow for straightforward interface combination and instantiation

A) Why not support straightforward interface instantiation, like this:

interface IA { int X { get; set; }; }
var a = new IA { X = 1 }

You have gone so far to support anonymous type instantion, why not support this useful feature?!

B) Also, defining an interface that combines other interfaces is already supported but cumbersome:

interface IA { ... }, interface IB { ... },
interface IC : IA, IB { ... }, class C : IC { ... }, var c = new C();

Why not support something like this (type-wise):

interface IA { ... }, interface IB { ... },
var c = new (IA + IB) { ... }

The implicitly combined interface instance would implement common conflicting members explicitly!

This opens a lot of doors. To name a few:

1) Ponder an MVVM scenario for creating a wrapper viewmodel object that has to combine 2 or more model objects and add notification responsibility.

2) Null Object Pattern!

11 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…)
    Kaveh RazaviKaveh Razavi shared this idea  ·   ·  Flag idea as inappropriate…  ·  Admin →

    1 comment

    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...
      • LMKLMK commented  ·   ·  Flag as inappropriate

        I think allowing anonymous classes to implement an interface would be hugely useful, and cut down on a lot of typing.

        One situation I have had recently is wanting to return an interface instance from a function. I want to use a LINQ select to create an object with fields that match the interface, rather than defining yet another class, instantiating the class etc etc. All wasted typing cluttering up my code.

        A possible .vb syntax:

        dim anObj = new ISomeInterface with {.IntProp = 42, .SomeFn = sub() msgbox("Hi Mum")}

        Surely that wouldn't be hard to add to the vb and c# compilers??

      Feedback and Knowledge Base