问题
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