Last active
March 15, 2018 21:27
-
-
Save MirzaMerdovic/bf9e37bc59595522959af3eeb8fddc24 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Project 1: | |
Base class: | |
public abstract class BaseRepository | |
{ | |
private protected Task<string> GetEmail(int id) | |
{ | |
return Task.FromResult("username@mail.com"); | |
} | |
} | |
Inheritance works! | |
public class AccountRepository : BaseRepository | |
{ | |
public async Task UpdateEmail(int id, string newEmail) | |
{ | |
var currentEmail = await GetEmail(id); | |
} | |
} | |
# Project 2: | |
Inheritance fails with error: "BaseRepository.GetEmail(int) is inaccessible due to its protection level" | |
public class CustomerRepository : BaseRepository | |
{ | |
public async Task UpdateCustomer(int id, string newEmail) | |
{ | |
var currentEmail = await GetEmail(id); | |
} | |
} | |
#Note: | |
Using [assembly: InternalsVisibleTo("Project2") in AssemblyInfo.cs of "Project1" will of course make the method visible. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment