[C#]添加“部分"运行时解决方案的类 [英] [C#] Adding "partial" classes to the solution at runtime

查看:113
本文介绍了[C#]添加“部分"运行时解决方案的类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好

我会尽量保持简短,我的问题是我正在做某种游戏"(也许更多是引擎?),而我试图做的整个想法是我已经做好了一切准备其他人可以做的,换句话说,您可以制作自己的游戏,但是我已经准备好了一些基本的东西可以使用,也许就像我的世界一样,那里有一些基本的东西,但可以轻松地向其中添加mod.

我在想的是使某些班级变得偏僻,例如我有一个输入系统,我想在那里做一些基本的动作,但我想让"modders"能够通过使用部分类来添加自己的输入,并简单地"将每个mod加载到解决方案中,只需使用用户创建的局部类扩展输入系统即可.

现在这是一个问题,老实说,我不知道如何在运行时将该类添加到解决方案中,并且仍然使程序可以找到这些类并像使用它们一样将它们用作我的主输入类.

那么这有可能吗?简单的代码和源代码会很可爱.

还是有更好的方法呢?

还是如果不可能,是否还有其他方法可以使它完全相同?

感谢您的阅读,我感谢您的时间和帮助:)

-杰基



快速更新:我想到我也可以加载一个程序集,但是我觉得这可能要先进得多,而且还需要播放器/"modder"/东西将所有内容编译为dll或exe.真的只是想避免,因为我想对modder/player保持简单,以便他可以在记事本或其他内容中继续前进.

另一种也有所进步,因为这几乎需要制作一种全新的语言,而这是我真正想要避免的,我可以使用ini文件扫描仪,但请不要在这里更多:)



附言我为此游戏使用了单色开发,因此该解决方案应尽可能在多个平台上使用.

Hi every one

I''ll try to keep this short, my problem is i''m making some kind of a "game" (maybe more of an engine?) and the whole idea in what i try to make is that i have made everything ready for others to do, in other words you make your own game but i have made some basic things ready to use, maybe a little like minecraft, where you have some basic stuff but can add mods to it easily.

what i''m thinking is to make some class partial, e.g. i have a input system and i wanna have my own stuff there with some basic movement, but i wanna let the "modders" have the ability to add their own inputs by using a partial class and "simply" load every mod into the solution and just extend the input system with the user made partial class.

now here is the problem i honestly have no clue how i can add this class into the solution at runtime and still make it possible for the program to find these classes and use them as if they''re partial/extender to my main input class.

so is this possible and how? code simples and sources would be lovely.

or if there is a better way of doing this, how?

or if it isn''t possible, is there any other way i can make it work just the same?

Thanks for reading i appreciate you time and help :)

- Jackie



fast update: it just came to my mind i could also just load an assembly, however i feel this might be much more advance and it would also require the player/"modder"/stuff to compile every thing to a dll or exe which i really just wanna try to avoid since i wanna keep it simple for the modder/player so he can go right ahead in notepad or something.

an other one also go abit advance since this will require to almost make a whole new language which i REALLY wanna avoid, i can go in on a ini file scanner maybe but please no more here :)



Ps. im using mono development for this game so the solution should be multi platform usable if possible.

推荐答案

部分类的概念与运行时无关.这个问题没有道理.

若要了解部分声明的作用,请仔细阅读: http://msdn.microsoft.com/en-us/library/wa80x488.aspx [ ^ ].

您似乎不太了解项目构建的功能,应用程序的编译,加载和执行方式.

当您学习它时,您将能够提出有效的问题并学习您可能需要的高级问题.

基本上,您可能需要实现和使用一些可插入性功能.请查看我过去关于以下主题的答案:
创建使用可重载插件的WPF应用程序... [^ ],
AppDomain拒绝加载程序集 [使用CodeDom生成代码 [创建使用可重载插件的WPF应用程序... [ ^ ],
动态加载用户控件 [在现有实例上的C#反射InvokeMember [项目和DLL:如何使其可管理? [ ^ ].

您也可以考虑使用MEF.请参阅:
http://en.wikipedia.org/wiki/Managed_Extensibility_Framework [ http://mef.codeplex.com/ [ ^ ].

可能有一些更简单的技术可以适合您的应用程序目标,但随后您需要正确地解释它们.您将需要一些重要的技巧,以将功能需求与可能的技术解决方案隔离开来;可以帮助您避免因可能沉迷于错误的想法而失去选择正确解决方案的能力.

—SA
The concept of partial class has nothing to do with run time. The question makes no sense.

To understand what partial declaration does, read carefully: http://msdn.microsoft.com/en-us/library/wa80x488.aspx[^].

It looks like you do not really understand what a project build does, how the application is compiled, loaded and executed.

When you learn it, you will be able to pose the valid questions and learn the advanced matter that you may need.

Basically, you might need to implement and use some pluggability feature. Please see my past answers on the topic:
Create WPF Application that uses Reloadable Plugins...[^],
AppDomain refuses to load an assembly[^],
code generating using CodeDom[^],
Create WPF Application that uses Reloadable Plugins...[^],
Dynamically Load User Controls[^],
C# Reflection InvokeMember on existing instance[^],
Projects and DLL''s: How to keep them managable?[^].

You might also consider using MEF. Please see:
http://en.wikipedia.org/wiki/Managed_Extensibility_Framework[^],
http://mef.codeplex.com/[^].

It is possible that some simpler technique can suite your application goals, but then you would need to explain them properly. You would need some important skill of isolation of functional requirements from the possible technical solutions; that could help you to avoid loosing the ability to choose right solution due to wrong ideas you might be preoccupied with.

—SA


这篇关于[C#]添加“部分"运行时解决方案的类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆