Friday, October 12, 2012

C# : Access internal methods/classes of an Assembly


Microsoft introduced the new attribute InternalsVisibleTo which you can define inside your AssemblyInfo.cs file. It works like a friend class in C++, so after doing this you can access your internal methods.

Assembly without strong name:

[assembly: InternalsVisibleTo("AssemblyName")]

Strong named assembly then define it with the key.

[assembly: InternalsVisibleTo("AssemblyName, PublicKey=xxxxxxx")]

We used this to access internal methods/classes for writing unit test cases.

No comments:

Post a Comment