C# ‘dynamic’ cannot access properties from anonymous types declared in another assembly

后端 未结 8 2504
无人共我
无人共我 2020-11-27 16:22

Code below is working well as long as I have class ClassSameAssembly in same assembly as class Program. But when I move class ClassSameAssemb

8条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-11-27 17:10

    If you're already using Newtonsoft.Json in your project (or you're willing to add it for this purpose), you could implement that horrible extension method Jon Skeet is referring to in his answer like this:

    public static class ObjectExtensions
    {
        public static ExpandoObject ToExpando(this object obj)
            => JsonConvert.DeserializeObject(JsonConvert.SerializeObject(obj));
    }
    

提交回复
热议问题