VB.net程序外部的可编辑代码 [英] Editable code outside of VB.net program

查看:65
本文介绍了VB.net程序外部的可编辑代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只编程了一年左右,所以请多多包涵.到目前为止,我所做的所有事情都已经硬编码到了程序中,但是现在我面临这样一种情况,我希望能够使某些代码可编辑,而不必发布新的解决方案并在每次需要更改时重新安装被制造.一个确切的问题是我的代码中有一个select case参数,但是每年都需要将此代码添加到其中.我不需要完整的代码示例或任何内容,只需要指出正确的方向即可.可以在文本,ini,xml,数据库或其他文件中完成此操作,还是有某种标准?

I''ve only been programming for about a year, so bear with me. Everything I have done so far has been hard coded into my programs, but now I am faced with a situation where I would like to be able to make some of the code editable without having to publish a new solution and reinstall everytime a change needs to be made. One exact issue is I have a select case argument in my code, but every year this code needs to be added to. I don''t need a complete code example or anything, I just need to be pointed in the right direction. Would this be done in a text, ini, xml, database, or some other file, or is there some sort of standard? Thank you in advance for any help on this!

推荐答案

这个问题范围太广,无法完全回答.基本上,使用数据不仅仅是避免硬编码.这完全取决于您的要求和不同的体系结构选择.

当然,对数据进行硬编码非常非常糟糕.但是您如何看待数据?您的整个程序也可以由其他程序处理的数据形式表示.

基本思想是,除非您在程序中为整个计算机建模并让用户编写自己的计算机,否则您不能做一个绝对通用的应用程序.因此,解决方案应切合实际,并考虑功能需求以及在需求变化的情况下提供灵活性的可能性.通过这种方式,您可以立即了解可选的内容以及可以依赖于下一发行版的内容.在一般的体系结构中,应该着重于识别知识在哪里,在哪里表达知识的正确方法.源代码中表示了一些知识,这最终是不可避免的.这种基本的体系结构决策是工作中的困难部分之一.

您列出的选项还取决于要求. (但是,您可能会忘记过时的INI并避免使用纯文本,但这不是绝对严格的规则.)您应该将它们视为存储数据而非存储数据的纯粹媒介.要更好地了解我在说什么,请阅读有关数据合同的信息: http ://msdn.microsoft.com/en-us/library/ms733127.aspx [ ^ ].

顺便说一句,这是一种以最小的工作量和最大的灵活性同时保留不大量数据的最佳方法.请参阅我过去提倡使用此方法的解决方案:
如何在我的表单应用程序? [ ^ ],
创建属性文件... [反序列化json字符串数组 [创建使用可重载插件的WPF应用程序... [ ^ ],
AppDomain拒绝加载程序集 [使用CodeDom生成代码 [动态加载用户控件 [
This question is too broad to answer it in full. Basically, using data is much more than just avoiding hard-coding. It all depends on your requirements and different architectural option.

Of course, hard-coding of data is very, very bad. But what do you consider data? Your whole program can also be represented in the form of data handled by some other program.

The basic idea is that you cannot do an application which is absolutely universal, unless you model a whole computer in your program and let the users write their own. So, the solutions should be realistic and consider both functional requirements and the provision for flexibility in case of changing requirements. This way, you can understand what to make optional right away and what can rely on next release. In a general architecture, one should focus on identifying, where the knowledge is and where is the right method of expressing the knowledge. Some knowledge is represented in the source code, and this is ultimately unavoidable. This fundamental kind of architectural decisions is one of the difficult parts of work.

The options you''ve listed also depend on requirements. (However, you probably may forget obsolete INI and avoid plain text, but it should not be an absolutely strict rule.) You should consider them as a mere media for persisting data, not the data. To get better idea on what am I talking about, read about Data Contract: http://msdn.microsoft.com/en-us/library/ms733127.aspx[^].

By the way, this is a best way to persist not very big volumes of data with minimal effort and maximum flexibility at the same time. Please see my past solution advocating this approach:
How can I utilize XML File streamwriter and reader in my form application?[^],
Creating property files...[^],
deseralize a json string array[^].

In this approach, you do not persist any separate data items, you persist the whole object graph of any complexity representing some data model.

That was about just the data. Now, let''s come back on a more general level and talk about the knowledge.

You see, some knowledge is better to express in data, but some — in code.

Respectively, if you need non-monolithic architecture with more flexible possibilities for updates, you need to consider two ways: one is data persistence explain above, another one — pluggable architecture of the code with replaceable components usually called plug-ins. The plug-ins can even be reloadable.

I overview some of the approaches on my past solutions written in response to different questions. Please see:
Create WPF Application that uses Reloadable Plugins...[^],
AppDomain refuses to load an assembly[^],
code generating using CodeDom[^],
Dynamically Load User Controls[^].

I won''t be surprised that this is a bit over your head. I think that looking at the bigger picture is always useful. You can come back to it some day later.

—SA


希望您对SA的解决方案感到满意.虽然SA的解决方案为您提供了更大的前景,但暂时您可以以某种方式修改代码(选择大小写逻辑等),以便从配置文件,xml等中读取变化的数据,从而您不会无需一次又一次发布并重新安装.

试试这些CP文章和链接,
用于提供应用程序配置数据的配置设置文件 [ http://vbnetsample.blogspot.com/2007/07/application-configuration-file.html [^ ]
http://visualbasic.about.com/od/usingvbnet/a/xmlconfig.htm [ ^ ]
XML配置文件终于变得简单了…… [
Hope you are on a high with SA''s solution. While SA''s solution gives you a bigger picture, for time being you can modify your code (select case logic etc) in such a way so as to read the varying data from a config file, xml etc. so that you won''t need to publish and re-install again and again.

Try these CP articles and links,
Configuration Settings File for providing application configuration data[^]
http://vbnetsample.blogspot.com/2007/07/application-configuration-file.html[^]
http://visualbasic.about.com/od/usingvbnet/a/xmlconfig.htm[^]
XML configuration files made simple... at last![^]


这篇关于VB.net程序外部的可编辑代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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