简体   繁体   English

C#:如何将类传递给单独dll中的函数

[英]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. 您需要将objectclass没有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.

相关问题 如何将 function 传递给 C# class dll,这是我从另一个 C# 应用程序调用的? function 在调用 dll 的应用程序中定义 - How can I pass a function to a C# class dll, that I am calling from another C# app? The function is defined in the app where the dll is called 如何将指针从C#传递给非托管DLL? - How can I pass a pointer from C# to an unmanaged DLL? 我如何编写使用C#键盘类的dll函数 - How can i write a dll function that uses the C# Keyboard Class C#如何将类实例传递给c#dll方法? - C# how to pass a class instance to c# dll method? 如何将C#委托函数传递给Managed C ++ .Dll? - How would I pass a C# delegate function to a Managed C++ .Dll? 如何将函数指针从C#传递给C ++ Dll? - How to pass function pointer from C# to a C++ Dll? 如何将结构从C#托管结构传递到C ++非托管DLL并得到结果结构? - How can I pass struct from C# managed to C++ unmanaged DLL and get struct in result? 如何在C#服务和单独的VB 6应用程序之间来回传递结构(或类)消息? - How do I pass a struct (or class) message back and forth between a C# service and a separate VB 6 application? 如何将指针从C#传递到DLL中的本机函数? - How to pass a pointer from C# to native function in DLL? 我如何将我的imageButton值传递给C#函数 - How can i pass my imagebutton values to c# function
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM