Skip to content

Instantly share code, notes, and snippets.

@MirzaMerdovic
Last active March 15, 2018 21:27
Show Gist options
  • Save MirzaMerdovic/bf9e37bc59595522959af3eeb8fddc24 to your computer and use it in GitHub Desktop.
Save MirzaMerdovic/bf9e37bc59595522959af3eeb8fddc24 to your computer and use it in GitHub Desktop.
# 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