Guest User

Untitled

a guest
Mar 24th, 2018
292
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  1. # Project 1:
  2.  
  3. Base class:
  4. public abstract class BaseRepository
  5. {
  6. private protected Task<string> GetEmail(int id)
  7. {
  8. return Task.FromResult("username@mail.com");
  9. }
  10. }
  11.  
  12. Inheritance works!
  13. public class AccountRepository : BaseRepository
  14. {
  15. public async Task UpdateEmail(int id, string newEmail)
  16. {
  17. var currentEmail = await GetEmail(id);
  18. }
  19. }
  20.  
  21. # Project 2:
  22. Inheritance fails with error: "BaseRepository.GetEmail(int) is inaccessible due to its protection level"
  23. public class CustomerRepository : BaseRepository
  24. {
  25. public async Task UpdateCustomer(int id, string newEmail)
  26. {
  27. var currentEmail = await GetEmail(id);
  28. }
  29. }
  30.  
  31. #Note:
  32. Using [assembly: InternalsVisibleTo("Project2") in AssemblyInfo.cs of "Project1" will of course make the method visible.
Add Comment
Please, Sign In to add comment