C# - Load a text file as a class

后端 未结 3 1446
北恋
北恋 2021-01-05 18:34

Is there any way to load a .txt file as a class, which my main program can then call functions from? I\'m basically trying to add mod support to my simple app, where the us

3条回答
  •  情歌与酒
    2021-01-05 19:07

    Use a Framework that Handles Plugins

    The Managed Extensibility Framework is just what you're looking for

    http://mef.codeplex.com/

    The Managed Extensibility Framework (MEF) is a composition layer for .NET that improves the flexibility, maintainability and testability of large applications. MEF can be used for third-party plugin extensibility, or it can bring the benefits of a loosely-coupled plugin-like architecture to regular applications.

    The MEF provides a well-defined architecture to support plugins in your application.

    DLL vs. Text (Source Code)

    The plugin developer is expected to provide a DLL containing the plugin code. However, if needed, you can compile source code into a DLL for them using Roslyn. Keep in mind that if you want to support receiving the plugin source code, you will also have to provide support for helping the user deal with compiler errors and debugging the plugin within your framework. It may be wiser to require them to provide a DLL.

提交回复
热议问题