Skip to content

Commit f12597f

Browse files
committed
Minor improvements to InternalsVisibleTo in the C# end.
1 parent 21233a6 commit f12597f

File tree

2 files changed

+20
-20
lines changed

2 files changed

+20
-20
lines changed

src/Generator/Generators/CSharp/CSharpSources.cs

+16-14
Original file line numberDiff line numberDiff line change
@@ -167,20 +167,7 @@ public override void Process()
167167

168168
var module = TranslationUnits.Count == 0 ?
169169
Context.Options.SystemModule : TranslationUnit.Module;
170-
var hasInternalsVisibleTo = false;
171-
if (Context.Options.DoAllModulesHaveLibraries())
172-
{
173-
foreach (var library in from m in Options.Modules
174-
where m.Dependencies.Contains(module)
175-
select m.LibraryName)
176-
{
177-
WriteLine($"[assembly:InternalsVisibleTo(\"{library}\")]");
178-
if (!hasInternalsVisibleTo)
179-
hasInternalsVisibleTo = true;
180-
}
181-
}
182-
if (hasInternalsVisibleTo)
183-
NewLine();
170+
AddInternalsVisibleTo(module);
184171

185172
if (!string.IsNullOrEmpty(module.OutputNamespace))
186173
{
@@ -201,6 +188,21 @@ where m.Dependencies.Contains(module)
201188
}
202189
}
203190

191+
private void AddInternalsVisibleTo(Module module)
192+
{
193+
if (!Context.Options.DoAllModulesHaveLibraries())
194+
return;
195+
196+
foreach (var library in from m in Options.Modules
197+
where m.Dependencies.Contains(module)
198+
select m.LibraryName)
199+
{
200+
WriteLine($"[assembly:InternalsVisibleTo(\"{library}\")]");
201+
NeedNewLine();
202+
}
203+
NewLineIfNeeded();
204+
}
205+
204206
public void GenerateHeader()
205207
{
206208
PushBlock(BlockKind.Header);

tests/NamespacesDerived/NamespacesDerived.cs

+4-6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
using System;
21
using System.IO;
32
using CppSharp.AST;
43
using CppSharp.Generators;
@@ -41,11 +40,10 @@ public override void Postprocess(Driver driver, ASTContext ctx)
4140

4241
driver.Generator.OnUnitGenerated += o =>
4342
{
44-
var firstBlock = o.Templates[0].RootBlock.Blocks[1];
45-
firstBlock.Text.StringBuilder.Append($@"using System.Runtime.CompilerServices;{
46-
Environment.NewLine}{
47-
Environment.NewLine}[assembly:InternalsVisibleTo(""NamespacesDerived.CSharp"")]{
48-
Environment.NewLine}");
43+
Block firstBlock = o.Templates[0].RootBlock.Blocks[1];
44+
firstBlock.WriteLine("using System.Runtime.CompilerServices;");
45+
firstBlock.NewLine();
46+
firstBlock.WriteLine("[assembly:InternalsVisibleTo(\"NamespacesDerived.CSharp\")]");
4947
};
5048
}
5149
}

0 commit comments

Comments
 (0)