开发者

Force cast imported class in C#

I have an imported assembly in my project, and I want to pass an object that is defined within the imported assembly. I want to manually construct each member of this object, but its members are read-only and does not have a constructor, so I can't seem to instantiate a derived object.

The imported class is defined something like this

public class foo
{
    public int num { get; }
    public String name { get; }
}

I used FormatterServices.GetUninitializedObject, but I feel it's a start. Perhaps there's a way to programmatically serialize?

Is there any way of instantiating it and 开发者_StackOverflowpassing it safely?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜