Search code examples
c#internal

Inherit internal base class from another internal child class


I have an internal class in MyProject. I have another internal class in my UnitTestProject. I want to inherit MyProject.internalClass from UnitTestProject.internalClass. But I can't inherit. Here is my code.

namespace MyProject.Data
{
    internal class BaseClass
    {

    }
}


namespace MyUnitTests.Data
{
    internal class TestClass: BaseClass
    {

    }
}

I add reference MyProject.dll in UnitTests project. But I still can't inherit. I am not sure the way I'm doing is right or wrong. Please give me any suggestion?


Solution

  • See InternalsVisibleToAttribute. You should put this attribute into AssemblyInfo.cs for the MyProject assembly:

    [assembly:InternalsVisibleTo("MyUnitTests")]