分离定义和实施 [英] Separating definition and implementation

查看:71
本文介绍了分离定义和实施的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

年前我在VS2008下使用了C#,我记得没有办法将类定义及其实现分离到不同的文件中(类似于我们以前的做法)在带有头文件和源文件的C和C ++中。



是否有人知道该语言的新版本是否允许这种完全合理的行为?不包括界面的创建,这是其他特定情况的工具。



谢谢



< b>我尝试过的事情:



我广泛分类但结果是我们所有人对搜索引擎玩笑的期望。谷歌和网络的其余部分都不能从 reich 公司的网络访问。

Hi all,
years ago I used C# under VS2008 and I remember there wasn't a way to separate class definitions and their implementations in different files (similarly to what we're used to do in C and C++ with header and source files).

Does anybody know if new versions of the language allow for this completely reasonable behaviour? Excluding the creation of interfaces, which are a tool for other very specific situations.

Thanks

What I have tried:

I Binged far and wide but the results are what we all expect from a joke of search engine. Google and the rest of the web aren't accessbile from the reich company's network.

推荐答案

我认为你指的是部分 类。



你可以在几个文件中传播代码,但仍然在同一个类中。
I think you're referring to "partial" classes.

You can spread code among several files and still be in the same class.


据我所知,与C中的方式不完全相同,但您可以使用抽象类和方法实现相同的行为。但是,您需要告诉派生类继承自哪个基类,所以它不是免费的。



您还可以使用存储在其中的部分类不同的文件,但每个部分类只为现有的定义带来新的功能...



根据你所追求的,也许MEF可能是你需要的?请查看托管扩展性框架(MEF) [ ^ ]
As far as I know, not completely the same way as in C but you could achieve same kind of behaviour with abstract classes and methods. However, you'd need to tell the derived class from which base class it's inherited from so it's not that free.

Also you could use partial classes which are stored in different files but then each partial class only brings new features to already existing definition...

Depending on what you're after, perhaps MEF could be what you need? Have a look at Managed Extensibility Framework (MEF)[^]


好吧,您可以使用部分类,它允许您在文件之间拆分 - Visual Studio设计器使用它来将设计代码与代码分开。

但是...... C#实际上没有一个与实现大相分离的定义,而不是C在使用之前需要在原型中声明所有函数的方式,并且没有全局变量的概念。 C#,所以(除了接口和抽象类)之外没有任何内容可以放入定义文件。

你可以将const和readonly项放在一个单独的文件中,但是TBH你可能最好使用区域折叠这些项目并将它们分开。


或者我距离你想做的事情还有几英里?
Well, you could use partial classes, which allow you to split a class between files - the Visual Studio designer uses this to separate the design code from your code.
But... C# doesn't really have an definition which is massively separate from the implementation, not in the way that C required all functions to be declared in prototype before they were used, and there is no concept of "global variables" in C#, so (with the exception of Interfaces and abstract classes) there isn't really anything to put into a "definition file".
You could put const and readonly items in a separate file, but TBH you are probably better off using regions to "collapse" such items and separate them that way.

Or am I completely miles away from what you are trying to do?


这篇关于分离定义和实施的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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