是否有可能在不同的组件再present同一类两个部分类? [英] Is it possible to have two partial classes in different assemblies represent the same class?
问题描述
我有一个名为在一个名为MyProject.Data项目第级,它充当我的Web应用程序的数据层。
I have a class called 'Article' in a project called 'MyProject.Data', which acts as the data layer for my web application.
我有一个单独的项目叫做MyProject.Admin',这是用于查看/编辑数据的基于Web的管理系统,并使用ASP.NET动态数据被构建。
I have a separate project called 'MyProject.Admin', which is a web-based admin system for viewing/editing the data, and was build using ASP.NET Dynamic Data.
基本上我要扩展Article类,使用部分类,这样我就可以增强其与UIHint扩展,这将让我有一个FCKEDIT控制取代普通的多行文本框的属性之一。
Basically I want to extend the Article class, using a partial class, so that I can augment one of its properties with a "UIHint" extender, which will allow me to replace the normal multi-line textbox with an FCKEdit control.
我的部分类和扩展是这样的:
My partial class and extender would look like this:
[MetadataType(typeof(ProjectMetaData))]
public partial class Project
{
}
public class ProjectMetaData
{
[UIHint("FCKeditor")]
public object ItemDetails { get; set; }
}
现在如果局部类是在同一个项目的原始部分类所有这一切工作正常 - 即MyProject.Data项目
Now this all works fine if the partial class is in the same project as the original partial class - i.e. the MyProject.Data project.
不过,UI的行为不应该坐在数据层,而是在管理层。所以我想这个类移动到MyProject.Admin。
But UI behavior shouldn't sit in the Data layer, but rather, in the Admin layer. So I want to move this class to MyProject.Admin.
但是,如果我这样做,功能丧失。
However, if I do that, the functionality is lost.
我的基本问题是:我可以在不同的项目2个部分类,但都指的是同一类
My fundamental question is: can I have 2 partial classes in separate projects, but both referring to the same "class"?
如果没有,有没有办法来完成我想要做的,没有数据层逻辑与UI逻辑混?
If not, is there a way to accomplish what I'm trying to do, without mixing data-layer logic with UI logic?
推荐答案
没有,你不能指的是同一类两种不同的组件(项目)两个部分类。一旦该程序集编译,元数据出炉,而且可以使用类不再分。部分类可以让你在同一类的定义分为两个文件。
No, you cannot have two partial classes referring to the same class in two different assemblies (projects). Once the assembly is compiled, the meta-data is baked in, and your classes are no longer partial. Partial classes allows you to split the definition of the same class into two files.
这篇关于是否有可能在不同的组件再present同一类两个部分类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!