Accessing an internal class from a different Dll file

1.7k views Asked by At

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?

1

There are 1 answers

2
dotnetom On BEST ANSWER

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