Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Accessing an internal class from a different Dll file

I am confused by some code that shouldn't be working, but oddly enough, is working and I know I'm simply overlooking something obvious. I'm looking at the source code for the Accord.NET framework and I downloaded it and its compiling just fine, but I'm confused about something. In one of the assemblies, called Accord.Math is a file called Indices.cs. Here is the definition:

internal static class Indices
{
    // Lots of code
    // ...
    // ...
}

You can see this on line 35.

Over in another assembly, called Accord.Statistics, there is a file called Tools.cs. In that file, there is this line:

return Accord.Math.Indices.Random(k, n);

You can see this on line 329.

I am confused on how this line can reference the Accord.Math.Indices class since it is marked as internal. My understanding is that a class marked as internal can only be accessed by classes that reside in the same DLL file. Can someone explain how this is working?

like image 354
Icemanind Avatar asked Aug 05 '15 05:08

Icemanind


1 Answers

This is because in file AssemblyInfo.cs you have these attributes:

[assembly: InternalsVisibleTo("Accord.Tests.Math, PublicKey=...")] 
[assembly: InternalsVisibleTo("Accord.Tests.MachineLearning,...")] 
[assembly: InternalsVisibleTo("Accord.Tests.Statistics,...")] 
[assembly: InternalsVisibleTo("Accord.Statistics, ...")]

These attributes specify that types that are ordinarily visible only within the current assembly are visible to a specified assembly (in the case that you asked it is visible to Accord.Statistics).

You can read more about InternalsVisibleToAttribute on MSDN

like image 53
dotnetom Avatar answered Oct 08 '22 06:10

dotnetom