Is there a wildcard-sort of functionality for making the internals visible to assemblies that share common assembly’s major(My english-fu is failing me) name?
For example, The.Empire is the major name of all assemblies. I tried The.Empire.*, but to no avail.
Assembly A
[assembly: System.Runtime.CompilerServices.InternalsVisibleTo("The.Empire.*")]
namespace The.Empire
{
internal static class Constants
{
internal readonly static string CommonId = "Luke";
}
}
Assembly B
namespace The.Empire.Strikes
{
public class Mate
{
public void AccessSomething()
{
Console.WriteLine("{0}", Constants.CommonId); // inaccessible
}
}
}
Assembly C
namespace The.Empire.Back
{
public class Mate
{
public void AccessSomething()
{
Console.WriteLine("{0}", Constants.CommonId); // inaccessible
}
}
}
Is this possible? On OOP inheritance analogy, something analogous to protected, only the deriver has access to protected
It’s not a loose coupling if I put the specific assembly name on InternalsVisibleTo. Other implementors of Assembly A can’t be catered unless I recompile AssemblyA
[assembly: System.Runtime.CompilerServices.InternalsVisibleTo("The.Empire.Strikes")]
[assembly: System.Runtime.CompilerServices.InternalsVisibleTo("The.Empire.Back")]
The documentation suggests that the only ways to specify multiple assemblies is either with multiple attributes or with multiple names in a single attribute:
That is:
or:
I don’t think what you want is possible, and likely intentionally so. Making your internals visible to another assembly is something that should be used sparingly, since it allows more coupling than might otherwise be desirable. Thus it should difficult to show your internals unless you absolutely meant them to be shown to a given assembly. Wildcards actively works against that.
Your best option (if you don’t want to use multiple attributes) is to either a) merge the assemblies so that they can just naturally share
internals or b) make certain keyinternalmemberspublic(orprotected) and make those the integration points for the other assemblies.