Automatically generate C# wrapper class from dll in Visual Studio 2010 Express?

后端 未结 3 775
一生所求
一生所求 2021-02-02 10:10

I was told by a colleague of mine that Visual Studio allows one to point to a .dll and auto-magically generate a C# wrapper class. Is this really possible? And if s

3条回答
  •  -上瘾入骨i
    2021-02-02 11:00

    I know this question is fairly old and seems to have been answered sufficiently, but I just want to add one thought I think might be important. I could be totally wrong, so please take my answer with a grain of salt and correct me on this if I am.

    To be able to call members/fields in a DLL, the information needed to call them must be accessible in some form. That information should be all you need to write a wrapper. With that, you can determine all members/fields "form" aka method headers and so on.

    In C# it is possible to load DLLs via reflection and get that information. I dont know about different DLL-Types as described above, but as I said, to call the members/fields this information has to be there in some form. So using reflection to get that Information, you could generate a new class e.g. "prefixOriginalname" and have it have the same members/fields as your original class, calling the members/fields of your original class and adding your desired extra functionality.

    So

    1. Every DLL (or peripheral document) gives you the information need to use its types. Namely everything that is implemented as "public"
    2. You can access this needed information via reflection
    3. Given 1. and 2., you can create a program to extract the needed information from DLL and generate wrappers accordingly.

    As I said, I am not 100% sure on this one, because the other answers make it sound to me like that might be too difficult or even impossible for some reason.

提交回复
热议问题