<dynamic> interface not allowed in C # - workaround

I have a class that I'm trying to create that uses dynamicas a parameter of type:

public class Idea : IEnumerable<dynamic>, IQueryable<dynamic>
{
}

Compiler: unable to implement dynamic interface

So, I have this workaround, which I'm not too keen on:

public class Idea<T> : IEnumerable<T>, IQueryable<T>
{
}

public class Idea : Idea<dynamic>
{
}

Compiler: success!

I cannot think of any other way to get around this problem, and I'm not sure what I want to show to the user Idea<T>.

Questions:

  • I feel like there are smells of code here ... can you confirm?
  • Why the CLR does not allow to implement interfaces dynamic?
  • Are there any patterns that I could use to achieve this without exhibiting Idea<T>?
+4
1

: " CLR ?"

, . , .

, , dynamic, ..

, :

, , ,

, . :

public class C
{
    public void M(object x) { }
    public void M(dynamic x) { }
}

, , , , , CLR .

, , , CLI, . :

, CLI , , , , , , , . , .

: , , , , , , . , . , .

+5
source

All Articles