'System.Collections.Generic.IList<object>' does not contain a definition for 'Add' when using 'dynamic' and 'ExpandoObject'

后端 未结 2 1155
攒了一身酷
攒了一身酷 2021-02-18 15:30

Say that I have a class, Foo, looking something like this:

public class Foo : IFoo
{
    public Foo()
    {
        Bars = new List();
    }
    p         


        
2条回答
  •  刺人心
    刺人心 (楼主)
    2021-02-18 16:23

    I'm not sure if this subverts your particular use case, but:

    Try explicitly casting Bars to System.Collections.IList.

    ((System.Collections.IList)foo.Bars).Add(a);
    

    Source: https://stackoverflow.com/a/9468123/364

    Alternatively, just redefine Bars as IList rather than IList in your interface + class.

提交回复
热议问题