Browse Source

Minor improvements to InternalsVisibleTo in the C# end.

pull/732/head
Dimitar Dobrev 9 years ago
parent
commit
f12597fc3f
  1. 30
      src/Generator/Generators/CSharp/CSharpSources.cs
  2. 10
      tests/NamespacesDerived/NamespacesDerived.cs

30
src/Generator/Generators/CSharp/CSharpSources.cs

@ -167,20 +167,7 @@ namespace CppSharp.Generators.CSharp @@ -167,20 +167,7 @@ namespace CppSharp.Generators.CSharp
var module = TranslationUnits.Count == 0 ?
Context.Options.SystemModule : TranslationUnit.Module;
var hasInternalsVisibleTo = false;
if (Context.Options.DoAllModulesHaveLibraries())
{
foreach (var library in from m in Options.Modules
where m.Dependencies.Contains(module)
select m.LibraryName)
{
WriteLine($"[assembly:InternalsVisibleTo(\"{library}\")]");
if (!hasInternalsVisibleTo)
hasInternalsVisibleTo = true;
}
}
if (hasInternalsVisibleTo)
NewLine();
AddInternalsVisibleTo(module);
if (!string.IsNullOrEmpty(module.OutputNamespace))
{
@ -201,6 +188,21 @@ namespace CppSharp.Generators.CSharp @@ -201,6 +188,21 @@ namespace CppSharp.Generators.CSharp
}
}
private void AddInternalsVisibleTo(Module module)
{
if (!Context.Options.DoAllModulesHaveLibraries())
return;
foreach (var library in from m in Options.Modules
where m.Dependencies.Contains(module)
select m.LibraryName)
{
WriteLine($"[assembly:InternalsVisibleTo(\"{library}\")]");
NeedNewLine();
}
NewLineIfNeeded();
}
public void GenerateHeader()
{
PushBlock(BlockKind.Header);

10
tests/NamespacesDerived/NamespacesDerived.cs

@ -1,4 +1,3 @@ @@ -1,4 +1,3 @@
using System;
using System.IO;
using CppSharp.AST;
using CppSharp.Generators;
@ -41,11 +40,10 @@ namespace CppSharp.Tests @@ -41,11 +40,10 @@ namespace CppSharp.Tests
driver.Generator.OnUnitGenerated += o =>
{
var firstBlock = o.Templates[0].RootBlock.Blocks[1];
firstBlock.Text.StringBuilder.Append($@"using System.Runtime.CompilerServices;{
Environment.NewLine}{
Environment.NewLine}[assembly:InternalsVisibleTo(""NamespacesDerived.CSharp"")]{
Environment.NewLine}");
Block firstBlock = o.Templates[0].RootBlock.Blocks[1];
firstBlock.WriteLine("using System.Runtime.CompilerServices;");
firstBlock.NewLine();
firstBlock.WriteLine("[assembly:InternalsVisibleTo(\"NamespacesDerived.CSharp\")]");
};
}
}

Loading…
Cancel
Save