How to apply an Extension Method on the object having the type of ExpandoObject?

后端 未结 2 387
遥遥无期
遥遥无期 2021-01-21 16:31

Here is my code:

public static class DynamicExtensions

    public static void Add(this ExpandoObject obj, string path){
        dynamic _obj = obj;
        if (         


        
2条回答
  •  面向向阳花
    2021-01-21 17:10

    Dynamic explicitly excludes extension methods. This is because the method is resolved at run time, not compile time. To resolve the method call correctly, the DLR would need information about the call that includes which using directives are in force; there's no mechanism to do that. See this answer by Eric Lippert for more detail: https://stackoverflow.com/a/5313149/385844

    You can, of course, call the method using the static method call syntax:

    DynamicExtensions.Add(obj, "p1");
    

提交回复
热议问题