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
var module = TranslationUnits.Count == 0 ? var module = TranslationUnits.Count == 0 ?
Context.Options.SystemModule : TranslationUnit.Module; Context.Options.SystemModule : TranslationUnit.Module;
var hasInternalsVisibleTo = false; AddInternalsVisibleTo(module);
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();
if (!string.IsNullOrEmpty(module.OutputNamespace)) if (!string.IsNullOrEmpty(module.OutputNamespace))
{ {
@ -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() public void GenerateHeader()
{ {
PushBlock(BlockKind.Header); PushBlock(BlockKind.Header);

10
tests/NamespacesDerived/NamespacesDerived.cs

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

Loading…
Cancel
Save