About c# partial class accesibility

丶灬走出姿态 提交于 2020-01-05 13:53:26

问题


I have a question about partial classes in c#

In This picture, I have a domain model. I am have added reference this(DomainModelLib) to Client application and repoistory application.

Repository application is using this domain model classes as "DbSet" and getting data from database. Realtions are created in model partial classes as you can see.

I referenced Model to Client application. I wanna first partial(first red frame) of Product class can access in Client application but second part(bottom red frame) of class can not access.

But two parts should be accesible in repository. Is this possible?

(NHibernate XML mapping is keeping relations from users, I wana keep somethings from users this way in Entity Framework)


回答1:


Accessibility isn't in any way defined by which source file contributes to a partial class.

The only way I can see of doing this exactly as stated is to make the members declared in the bottom red frame internal, and use [InternalsVisibleTo] to allow the EFRepository project access to internal members in DomainModelLib.

You might want to consider alternatives though... it's hard to suggest good alternatives without knowing exactly what you're trying to achieve, but giving two different "external" libraries different accessibility is fundamentally tricky.




回答2:


A new library could be created (say X). Move the bottom red frame into that. Reference X from both domain and repo.



来源:https://stackoverflow.com/questions/16940036/about-c-sharp-partial-class-accesibility

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!