cast anonymous type to an interface?

前端 未结 3 870
梦如初夏
梦如初夏 2020-12-09 09:09

This doesn\'t seem to be possible? So what is the best work-around? Expando / dynamic?

public interface ICoOrd {
    int x { get; set; }
    int y { get; s         


        
3条回答
  •  萌比男神i
    2020-12-09 09:45

    No, anonymous types never implement interfaces. dynamic wouldn't let you cast to the interface either, but would let you just access the two properties. Note that anonymous types are internal, so if you want to use them across assemblies using dynamic, you'll need to use InternalsVisibleTo.

提交回复
热议问题