[英]C#: How can I pass a class to a function in separate dll
I tried to code my own serialization dll. 我尝试编写自己的序列化dll。 The code itself works as expected.
代码本身按预期工作。 Now I want to put the entire code into a dll file.
现在,我想将整个代码放入一个dll文件中。
My problem is the following: how do I tell the dll WHICH class it should serialize? 我的问题如下:如何告诉DLL WHICH类应该序列化?
Example: 例:
public class serialize
{
public static void doSerialization(class serializableClass, string path, string fileName)
{
do code here...
}
}
Ok. 好。 I used
class serializableClass
, you know? 我使用了
class serializableClass
,您知道吗? Type + Name. 类型+名称。 Sure It won't work like this.
当然不能这样工作。 I was afraid it wouldn't.
我怕不会。 But how do I do it, though?
但是,我该怎么做呢? I want the dll to serialize the class
settings.cs
which is in my main program... I hope the question is clear. 我希望dll序列化主程序中的类
settings.cs
。我希望问题清楚。 Otherwise just ask ;) 否则,只问;)
Thanks for Your help. 谢谢你的帮助。 Best Regards.
最好的祝福。
You need to pass object
of class
not class
it self. 您需要将
object
的class
没有class
它的自我。 Assuming serializableClass
is a class. 假设
serializableClass
是一个类。 Although the library (dll) does not know your class serializableClass. 虽然库(dll)不知道您的类serializableClass。 You can make library of common classes and add reference of that library in
main
program and library for serialization. 您可以创建通用类的库 ,并在
main
和库中添加该库的引用以进行序列化。
public class serialize
{
public static void doSerialization(serializableClass objSerializableClass , string path, string fileName)
{
do code here...
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.