Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/Microsoft.Windows.CsWin32/Generator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ internal Generator MainGenerator

private bool WideCharOnly => this.options.WideCharOnly;

private string Namespace => this.MetadataIndex.CommonNamespace;
private string Namespace => this.options.Namespace ?? this.MetadataIndex.CommonNamespace;

private SyntaxKind Visibility => this.options.Public ? SyntaxKind.PublicKeyword : SyntaxKind.InternalKeyword;

Expand Down Expand Up @@ -817,7 +817,7 @@ nsContents.Key is object
usingDirectives.Add(UsingDirective(ParseName(GlobalNamespacePrefix + "System.Runtime.Versioning")));
}

usingDirectives.Add(UsingDirective(NameEquals(GlobalWinmdRootNamespaceAlias), ParseName(GlobalNamespacePrefix + this.MetadataIndex.CommonNamespace)));
usingDirectives.Add(UsingDirective(NameEquals(GlobalWinmdRootNamespaceAlias), ParseName(GlobalNamespacePrefix + this.Namespace)));

var normalizedResults = new Dictionary<string, CompilationUnitSyntax>(StringComparer.OrdinalIgnoreCase);
results.AsParallel().WithCancellation(cancellationToken).ForAll(kv =>
Expand Down
8 changes: 8 additions & 0 deletions src/Microsoft.Windows.CsWin32/GeneratorOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@ public record GeneratorOptions
/// <value>The default value is "PInvoke".</value>
public string ClassName { get; init; } = "PInvoke";

/// <summary>
/// Gets the root namespace to use for the generated code. This is used to determine the namespace of the generated types.
/// </summary>
/// <value>
/// The default namespace is the namespace of the metadata assembly that the generator generates interop code for, e.g. "Windows.Win32".
/// </value>
public string? Namespace { get; init; }

/// <summary>
/// Gets a value indicating whether to emit a single source file as opposed to types spread across many files.
/// </summary>
Expand Down
6 changes: 6 additions & 0 deletions src/Microsoft.Windows.CsWin32/settings.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,12 @@
"description": "A value indicating whether to expose the generated APIs publicly (as opposed to internally).",
"type": "boolean",
"default": false
},
"namespace": {
"description": "The namespace under which all p/invoke methods and constants are generated.",
"type": "string",
"default": null,
"pattern": "^\\w+(?:\\.\\w+)*$"
}
}
}