Is it possible to have two partial classes in different assemblies represent the same class?

前端 未结 9 1427
栀梦
栀梦 2020-11-27 03:56

I have a class called \'Article\' in a project called \'MyProject.Data\', which acts as the data layer for my web application.

I have a separate project called \'MyP

相关标签:
9条回答
  • 2020-11-27 04:37

    I've had similar issues with this. I kept my partial classes in my Data project so in your case the 'MyProject.Data'. MetaDataClasses shouldn't go in your Admin project as you will create a circular references other wise.

    I added a new Class Lib project for my MetaDataClasses e.g. 'MyProject.MetaData' and then referenced this from my Data project

    0 讨论(0)
  • 2020-11-27 04:38

    As noted, partial classes is a compile-time phenomenon, not runtime. Classes in assemblies are by definition complete.

    In MVC terms, you want to keep view code separate from model code, yet enable certain kinds of UI based on model properties. Check out Martin Fowler's excellent overview of the different flavours of MVC, MVP and whatnot: you'll find design ideas aplenty. I suppose you could also use Dependency Injection to tell the UI what kind of controls are viable for individual entities and attributes.

    Your aim of separating concerns is great; but partial classes were intended to address entirely different issues (primarily with code generation and design-time modelling languages).

    0 讨论(0)
  • 2020-11-27 04:45

    Add the base file as a linked file into your projects. It's still partial but as allows you to share it between both projects, keep them synchronized and at the same time have version/framework specific code in the partial classes.

    0 讨论(0)
提交回复
热议问题