Aug 30, 2015

Access Internal class or member on another Assemblies in C#

Sometime we would like to access Internal Class or Member on Unit Test case Assembly.

I just happen same situation in my one of the project. So I have googling and spend some time on it and finding solution.

Writing this blog for them who having facing same situation. so that would be help for them.

C# having call Internal Assembly like in Visual Basic(VB) having call Friend Assembly.

Interal class InternalClass
{
    public void Test()
    {
        Console.WriteLine("Sample Class");
    }
}

If would like to access InternalClass on another assemblies then need to define each assemblies name on AssemblyInfo.cs with following line.

[assembly: InternalsVisibleTo("name of assembly here")]
i.e. If you want access InternalClass on assembly ABC then you will need to mention on AssemblyInfo.cs file for same.

[assembly: InternalsVisibleTo("ABC")]
Hope that is help to you!!

For more detail please click here

No comments:

Post a Comment