开发者

Force cast imported class in C#

开发者 https://www.devze.com 2023-03-17 00:11 出处:网络
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-

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

精彩评论

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