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?
精彩评论