diff --git a/src/Microsoft.Windows.CsWin32/Generator.cs b/src/Microsoft.Windows.CsWin32/Generator.cs index b498b1db..8ed3cb5b 100644 --- a/src/Microsoft.Windows.CsWin32/Generator.cs +++ b/src/Microsoft.Windows.CsWin32/Generator.cs @@ -147,6 +147,11 @@ public class Generator : IDisposable .WithCloseBracketToken(TokenWithLineFeed(SyntaxKind.CloseBracketToken)) .AddAttributes(Attribute(IdentifierName("DefaultDllImportSearchPaths")).AddArgumentListArguments(AttributeArgument(MemberAccessExpression(SyntaxKind.SimpleMemberAccessExpression, IdentifierName(nameof(DllImportSearchPath)), IdentifierName(nameof(DllImportSearchPath.System32)))))); + private static readonly AttributeSyntax GeneratedCodeAttribute = Attribute(IdentifierName("global::System.CodeDom.Compiler.GeneratedCode")) + .WithArgumentList(FixTrivia(AttributeArgumentList().AddArguments( + AttributeArgument(LiteralExpression(SyntaxKind.StringLiteralExpression, Literal(ThisAssembly.AssemblyName))), + AttributeArgument(LiteralExpression(SyntaxKind.StringLiteralExpression, Literal(ThisAssembly.AssemblyInformationalVersion)))))); + private static readonly HashSet ImplicitConversionTypeDefs = new HashSet(StringComparer.Ordinal) { "PWSTR", @@ -465,13 +470,36 @@ private IEnumerable NamespaceMembers { get { - IEnumerable result = - from entry in this.committedCode.MembersByModule - select ClassDeclaration(Identifier(this.options.ClassName)) - .AddModifiers(TokenWithSpace(this.Visibility), TokenWithSpace(SyntaxKind.StaticKeyword), TokenWithSpace(SyntaxKind.PartialKeyword)) - .AddMembers(entry.ToArray()) - .WithLeadingTrivia(ParseLeadingTrivia(string.Format(CultureInfo.InvariantCulture, PartialPInvokeContentComment, entry.Key))) - .WithAdditionalAnnotations(new SyntaxAnnotation(SimpleFileNameAnnotation, $"{this.options.ClassName}.{entry.Key}")); + IEnumerable> members = this.committedCode.MembersByModule; + IEnumerable result = Enumerable.Empty(); + for (int i = 0; i < members.Count(); i++) + { + IGrouping entry = members.ElementAt(i); + if (i == 0) + { + result = result.Concat(new MemberDeclarationSyntax[] + { + ClassDeclaration(Identifier(this.options.ClassName)) + .AddModifiers(TokenWithSpace(this.Visibility), TokenWithSpace(SyntaxKind.StaticKeyword), TokenWithSpace(SyntaxKind.PartialKeyword)) + .AddMembers(entry.ToArray()) + .AddAttributeLists(AttributeList().AddAttributes(GeneratedCodeAttribute)) + .WithLeadingTrivia(ParseLeadingTrivia(string.Format(CultureInfo.InvariantCulture, PartialPInvokeContentComment, entry.Key))) + .WithAdditionalAnnotations(new SyntaxAnnotation(SimpleFileNameAnnotation, $"{this.options.ClassName}.{entry.Key}")), + }); + } + else + { + result = result.Concat(new MemberDeclarationSyntax[] + { + ClassDeclaration(Identifier(this.options.ClassName)) + .AddModifiers(TokenWithSpace(this.Visibility), TokenWithSpace(SyntaxKind.StaticKeyword), TokenWithSpace(SyntaxKind.PartialKeyword)) + .AddMembers(entry.ToArray()) + .WithLeadingTrivia(ParseLeadingTrivia(string.Format(CultureInfo.InvariantCulture, PartialPInvokeContentComment, entry.Key))) + .WithAdditionalAnnotations(new SyntaxAnnotation(SimpleFileNameAnnotation, $"{this.options.ClassName}.{entry.Key}")), + }); + } + } + result = result.Concat(this.committedCode.GeneratedTypes); ClassDeclarationSyntax inlineArrayIndexerExtensionsClass = this.DeclareInlineArrayIndexerExtensionsClass(); @@ -1673,10 +1701,11 @@ internal void RequestConstant(FieldDefinitionHandle fieldDefHandle) .AddModifiers(TokenWithSpace(this.Visibility)) .WithBaseList(BaseList(SingletonSeparatedList(SimpleBaseType(SafeHandleTypeSyntax)))) .AddMembers(members.ToArray()) + .AddAttributeLists(AttributeList().AddAttributes(GeneratedCodeAttribute)) .WithLeadingTrivia(ParseLeadingTrivia($@" - /// - /// Represents a Win32 handle that can be closed with . - /// +/// +/// Represents a Win32 handle that can be closed with . +/// ")); this.volatileCode.AddSafeHandleType(safeHandleDeclaration); @@ -2861,6 +2890,15 @@ private bool HasObsoleteAttribute(CustomAttributeHandleCollection attributes) return null; } + // add generated code attribute. + if (typeDeclaration is not null) + { + typeDeclaration = typeDeclaration + .WithLeadingTrivia() + .AddAttributeLists(AttributeList().AddAttributes(GeneratedCodeAttribute)) + .WithLeadingTrivia(typeDeclaration.GetLeadingTrivia()); + } + return typeDeclaration; } catch (Exception ex) @@ -3142,14 +3180,16 @@ private ClassDeclarationSyntax DeclareInlineArrayIndexerExtensionsClass() { return ClassDeclaration(InlineArrayIndexerExtensionsClassName.Identifier) .AddMembers(this.committedCode.InlineArrayIndexerExtensions.ToArray()) - .WithModifiers(TokenList(TokenWithSpace(this.Visibility), TokenWithSpace(SyntaxKind.StaticKeyword), TokenWithSpace(SyntaxKind.PartialKeyword))); + .WithModifiers(TokenList(TokenWithSpace(this.Visibility), TokenWithSpace(SyntaxKind.StaticKeyword), TokenWithSpace(SyntaxKind.PartialKeyword))) + .AddAttributeLists(AttributeList().AddAttributes(GeneratedCodeAttribute)); } private ClassDeclarationSyntax DeclareComInterfaceFriendlyExtensionsClass() { return ClassDeclaration(ComInterfaceFriendlyExtensionsClassName.Identifier) .AddMembers(this.committedCode.ComInterfaceExtensions.ToArray()) - .WithModifiers(TokenList(TokenWithSpace(this.Visibility), TokenWithSpace(SyntaxKind.StaticKeyword), TokenWithSpace(SyntaxKind.PartialKeyword))); + .WithModifiers(TokenList(TokenWithSpace(this.Visibility), TokenWithSpace(SyntaxKind.StaticKeyword), TokenWithSpace(SyntaxKind.PartialKeyword))) + .AddAttributeLists(AttributeList().AddAttributes(GeneratedCodeAttribute)); } /// diff --git a/test/Microsoft.Windows.CsWin32.Tests/GeneratorTests.cs b/test/Microsoft.Windows.CsWin32.Tests/GeneratorTests.cs index 727ecb39..ab722885 100644 --- a/test/Microsoft.Windows.CsWin32.Tests/GeneratorTests.cs +++ b/test/Microsoft.Windows.CsWin32.Tests/GeneratorTests.cs @@ -613,6 +613,44 @@ public void HandleTypeDefsUseIntPtrAsFieldType(string handleType) Assert.Equal(nameof(IntPtr), Assert.IsType(field.Declaration.Type).Identifier.ValueText); } + [Fact] + public void HasGeneratedCodeAttribute() + { + this.generator = this.CreateGenerator(); + Assert.True(this.generator.TryGenerate("IDebugDocumentInfo", CancellationToken.None)); + Assert.True(this.generator.TryGenerate("HANDLE", CancellationToken.None)); + Assert.True(this.generator.TryGenerate("INPUT_RECORD", CancellationToken.None)); + Assert.True(this.generator.TryGenerate("GetTickCount", CancellationToken.None)); + Assert.True(this.generator.TryGenerate("ACTIVATE_KEYBOARD_LAYOUT_FLAGS", CancellationToken.None)); + Assert.True(this.generator.TryGenerate("PAINTSTRUCT", CancellationToken.None)); + this.CollectGeneratedCode(this.generator); + this.AssertNoDiagnostics(); + + InterfaceDeclarationSyntax interfaceDecl = Assert.IsType(this.FindGeneratedType("IDebugDocumentInfo").Single()); + Assert.Contains(interfaceDecl.AttributeLists, al => al.Attributes.Any(a => a.Name.ToString().Contains("GeneratedCode"))); + + StructDeclarationSyntax handle = Assert.IsType(this.FindGeneratedType("HANDLE").Single()); + Assert.Contains(handle.AttributeLists, al => al.Attributes.Any(a => a.Name.ToString().Contains("GeneratedCode"))); + + StructDeclarationSyntax structDecl = Assert.IsType(this.FindGeneratedType("INPUT_RECORD").Single()); + Assert.Contains(structDecl.AttributeLists, al => al.Attributes.Any(a => a.Name.ToString().Contains("GeneratedCode"))); + + IEnumerable pInvokeClass = this.FindGeneratedType("PInvoke").OfType(); + Assert.Contains(pInvokeClass, c => c.AttributeLists.Any(al => al.Attributes.Any(a => a.Name.ToString().Contains("GeneratedCode")))); + + EnumDeclarationSyntax enumDecl = Assert.IsType(this.FindGeneratedType("ACTIVATE_KEYBOARD_LAYOUT_FLAGS").Single()); + Assert.Contains(enumDecl.AttributeLists, al => al.Attributes.Any(a => a.Name.ToString().Contains("GeneratedCode"))); + + ClassDeclarationSyntax arrayExtensions = Assert.IsType(this.FindGeneratedType("InlineArrayIndexerExtensions").Single()); + Assert.Contains(arrayExtensions.AttributeLists, al => al.Attributes.Any(a => a.Name.ToString().Contains("GeneratedCode"))); + + ClassDeclarationSyntax overloadsExtensions = Assert.IsType(this.FindGeneratedType("FriendlyOverloadExtensions").Single()); + Assert.Contains(overloadsExtensions.AttributeLists, al => al.Attributes.Any(a => a.Name.ToString().Contains("GeneratedCode"))); + + ClassDeclarationSyntax sysFreeStringSafeHandleClass = Assert.IsType(this.FindGeneratedType("SysFreeStringSafeHandle").Single()); + Assert.Contains(overloadsExtensions.AttributeLists, al => al.Attributes.Any(a => a.Name.ToString().Contains("GeneratedCode"))); + } + [Fact] public void NamespaceHandleGetsNoSafeHandle() { @@ -1096,14 +1134,15 @@ public void NoFriendlyOverloadsWithSpanInNet35(bool allowMarshaling) [Fact] public void FixedLengthInlineCharArraysWorkInNet35() { - const string expected = @" /// Defines the attributes of a font. + const string expected = $@" /// Defines the attributes of a font. /// /// The following situations do not support ClearType antialiasing: /// This doc was truncated. /// Read more on docs.microsoft.com. /// + [global::System.CodeDom.Compiler.GeneratedCode(""Microsoft.Windows.CsWin32"", ""{ThisAssembly.AssemblyInformationalVersion}"")] internal partial struct LOGFONTW - { + {{ /// /// Type: LONG Specifies the height, in logical units, of the font's character cell or character. The character height value (also known as the em height) is the character cell height value minus the internal-leading value. The font mapper interprets the value specified in lfHeight in the following manner. /// This doc was truncated. @@ -1168,7 +1207,7 @@ internal partial struct LOGFONTW [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)] internal partial struct __char_32 - { + {{ internal char _0,_1,_2,_3,_4,_5,_6,_7,_8,_9,_10,_11,_12,_13,_14,_15,_16,_17,_18,_19,_20,_21,_22,_23,_24,_25,_26,_27,_28,_29,_30,_31; /// Always 32. @@ -1181,31 +1220,31 @@ internal partial struct __char_32 /// Thrown when is less than 0 or greater than . /// internal unsafe readonly string ToString(int length) - { + {{ if (length < 0 || length > Length)throw new ArgumentOutOfRangeException(nameof(length), length, ""Length must be between 0 and the fixed array length.""); fixed (char* p0 = &_0) return new string(p0, 0, length); - } + }} /// /// Copies the fixed array to a new string, stopping before the first null terminator character or at the end of the fixed array (whichever is shorter). /// public override readonly unsafe string ToString() - { + {{ int length; fixed (char* p = &_0) - { + {{ char* pLastExclusive = p + Length; char* pCh = p; for(; pCh < pLastExclusive && *pCh != '\0'; pCh++); length= checked((int)(pCh - p)); - } + }} return ToString(length); - } - } - } + }} + }} + }} "; const string expectedIndexer = @" @@ -1235,8 +1274,9 @@ internal static unsafe ref char ItemRef(this ref winmdroot.Graphics.Gdi.LOGFONTW [Fact] public void FixedLengthInlineArraysOfferExtensionIndexerWhereNoSpanPossible() { - const string expected = @" internal partial struct MainAVIHeader - { + const string expected = $@" [global::System.CodeDom.Compiler.GeneratedCode(""Microsoft.Windows.CsWin32"", ""{ThisAssembly.AssemblyInformationalVersion}"")] + internal partial struct MainAVIHeader + {{ internal uint dwMicroSecPerFrame; internal uint dwMaxBytesPerSec; internal uint dwPaddingGranularity; @@ -1250,33 +1290,33 @@ public void FixedLengthInlineArraysOfferExtensionIndexerWhereNoSpanPossible() internal __uint_4 dwReserved; internal partial struct __uint_4 - { + {{ internal uint _0,_1,_2,_3; /// Always 4. internal readonly int Length => 4; internal unsafe readonly void CopyTo(Span target, int length = 4) - { + {{ if (length > 4)throw new ArgumentOutOfRangeException(""length""); fixed (uint* p0 = &_0) for(int i = 0; i < length; i++) target[i]= p0[i]; - } + }} internal readonly uint[] ToArray(int length = 4) - { + {{ if (length > 4)throw new ArgumentOutOfRangeException(""length""); uint[] target = new uint[length]; CopyTo(target, length); return target; - } + }} internal unsafe readonly bool Equals(ReadOnlySpan value) - { + {{ fixed (uint* p0 = &_0) - { + {{ int commonLength = Math.Min(value.Length, 4); for(int i = 0; i < commonLength; @@ -1284,28 +1324,29 @@ internal unsafe readonly bool Equals(ReadOnlySpan value) for(int i = commonLength; i < 4; i++) if (p0[i] != default(uint)) return false; - } + }} return true; - } - } - } + }} + }} + }} "; - const string expectedIndexer = @" + const string expectedIndexer = $@" + [global::System.CodeDom.Compiler.GeneratedCode(""Microsoft.Windows.CsWin32"", ""{ThisAssembly.AssemblyInformationalVersion}"")] internal static partial class InlineArrayIndexerExtensions - { + {{ internal static unsafe ref readonly uint ReadOnlyItemRef(this in winmdroot.Media.DirectShow.MainAVIHeader.__uint_4 @this, int index) - { + {{ fixed (uint* p0 = &@this._0) return ref p0[index]; - } + }} internal static unsafe ref uint ItemRef(this ref winmdroot.Media.DirectShow.MainAVIHeader.__uint_4 @this, int index) - { + {{ fixed (uint* p0 = &@this._0) return ref p0[index]; - } - } + }} + }} "; this.AssertGeneratedType("MainAVIHeader", expected, expectedIndexer); @@ -1317,8 +1358,9 @@ internal static unsafe ref uint ItemRef(this ref winmdroot.Media.DirectShow.Main [Fact] public void FixedLengthInlineArraysGetSpanWherePossible() { - const string expected = @" internal partial struct MainAVIHeader - { + const string expected = $@" [global::System.CodeDom.Compiler.GeneratedCode(""Microsoft.Windows.CsWin32"", ""{ThisAssembly.AssemblyInformationalVersion}"")] + internal partial struct MainAVIHeader + {{ internal uint dwMicroSecPerFrame; internal uint dwMaxBytesPerSec; internal uint dwPaddingGranularity; @@ -1332,7 +1374,7 @@ public void FixedLengthInlineArraysGetSpanWherePossible() internal __uint_4 dwReserved; internal partial struct __uint_4 - { + {{ internal uint _0,_1,_2,_3; /// Always 4. @@ -1353,26 +1395,26 @@ internal partial struct __uint_4 internal Span AsSpan() => MemoryMarshal.CreateSpan(ref _0, 4); internal unsafe readonly void CopyTo(Span target, int length = 4) - { + {{ if (length > 4)throw new ArgumentOutOfRangeException(""length""); fixed (uint* p0 = &_0) for(int i = 0; i < length; i++) target[i]= p0[i]; - } + }} internal readonly uint[] ToArray(int length = 4) - { + {{ if (length > 4)throw new ArgumentOutOfRangeException(""length""); uint[] target = new uint[length]; CopyTo(target, length); return target; - } + }} internal unsafe readonly bool Equals(ReadOnlySpan value) - { + {{ fixed (uint* p0 = &_0) - { + {{ int commonLength = Math.Min(value.Length, 4); for(int i = 0; i < commonLength; @@ -1380,11 +1422,11 @@ internal unsafe readonly bool Equals(ReadOnlySpan value) for(int i = commonLength; i < 4; i++) if (p0[i] != default(uint)) return false; - } + }} return true; - } - } - } + }} + }} + }} "; const string expectedIndexer = @" @@ -1607,7 +1649,7 @@ public async Task TestSimpleStructure() }, GeneratedSources = { - (typeof(SourceGenerator), "Windows.Win32.BOOL.g.cs", @"// ------------------------------------------------------------------------------ + (typeof(SourceGenerator), "Windows.Win32.BOOL.g.cs", $@"// ------------------------------------------------------------------------------ // // This code was generated by a tool. // @@ -1618,7 +1660,7 @@ public async Task TestSimpleStructure() #pragma warning disable CS1591,CS1573,CS0465,CS0649,CS8019,CS1570,CS1584,CS1658,CS0436,CS8981 namespace Windows.Win32 -{ +{{ using global::System; using global::System.Diagnostics; using global::System.Runtime.CompilerServices; @@ -1626,11 +1668,12 @@ namespace Windows.Win32 using winmdroot = global::Windows.Win32; namespace Foundation - { - [DebuggerDisplay(""{Value}"")] + {{ + [DebuggerDisplay(""{{Value}}"")] + [global::System.CodeDom.Compiler.GeneratedCode(""Microsoft.Windows.CsWin32"", ""{ThisAssembly.AssemblyInformationalVersion}"")] internal readonly partial struct BOOL : IEquatable - { + {{ internal readonly int Value; internal BOOL(int value) => this.Value = value; public static implicit operator int(BOOL value) => value.Value; @@ -1646,9 +1689,9 @@ internal readonly partial struct BOOL internal BOOL(bool value) => this.Value = value ? 1 : 0; public static implicit operator bool(BOOL value) => value.Value != 0; public static implicit operator BOOL(bool value) => new BOOL(value); - } - } -} + }} + }} +}} ".Replace("\r\n", "\n")), (typeof(SourceGenerator), "Windows.Win32.CsWin32Stamp.g.cs", CsWin32StampContent), }, @@ -1675,7 +1718,7 @@ public async Task TestSimpleEnum() GeneratedSources = { (typeof(SourceGenerator), "Windows.Win32.CsWin32Stamp.g.cs", CsWin32StampContent), - (typeof(SourceGenerator), "Windows.Win32.DISPLAYCONFIG_SCANLINE_ORDERING.g.cs", @"// ------------------------------------------------------------------------------ + (typeof(SourceGenerator), "Windows.Win32.DISPLAYCONFIG_SCANLINE_ORDERING.g.cs", $@"// ------------------------------------------------------------------------------ // // This code was generated by a tool. // @@ -1686,7 +1729,7 @@ public async Task TestSimpleEnum() #pragma warning disable CS1591,CS1573,CS0465,CS0649,CS8019,CS1570,CS1584,CS1658,CS0436,CS8981 namespace Windows.Win32 -{ +{{ using global::System; using global::System.Diagnostics; using global::System.Runtime.CompilerServices; @@ -1694,13 +1737,14 @@ namespace Windows.Win32 using winmdroot = global::Windows.Win32; namespace Devices.Display - { + {{ /// The DISPLAYCONFIG_SCANLINE_ORDERING enumeration specifies the method that the display uses to create an image on a screen. /// /// Learn more about this API from docs.microsoft.com. /// + [global::System.CodeDom.Compiler.GeneratedCode(""Microsoft.Windows.CsWin32"", ""{ThisAssembly.AssemblyInformationalVersion}"")] internal enum DISPLAYCONFIG_SCANLINE_ORDERING - { + {{ /// Indicates that scan-line ordering of the output is unspecified. The caller can only set the scanLineOrdering member of the DISPLAYCONFIG_PATH_TARGET_INFO structure in a call to the SetDisplayConfig function to DISPLAYCONFIG_SCANLINE_ORDERING_UNSPECIFIED if the caller also set the refresh rate denominator and numerator of the refreshRate member both to zero. In this case, SetDisplayConfig uses the best refresh rate it can find. DISPLAYCONFIG_SCANLINE_ORDERING_UNSPECIFIED = 0, /// Indicates that the output is a progressive image. @@ -1713,9 +1757,9 @@ internal enum DISPLAYCONFIG_SCANLINE_ORDERING DISPLAYCONFIG_SCANLINE_ORDERING_INTERLACED_LOWERFIELDFIRST = 3, /// Forces this enumeration to compile to 32 bits in size. Without this value, some compilers would allow this enumeration to compile to a size other than 32 bits. You should not use this value. DISPLAYCONFIG_SCANLINE_ORDERING_FORCE_UINT32 = -1, - } - } -} + }} + }} +}} ".Replace("\r\n", "\n")), }, }, @@ -1741,7 +1785,7 @@ public async Task TestSimpleEnumWithoutDocs() GeneratedSources = { (typeof(SourceGenerator), "Windows.Win32.CsWin32Stamp.g.cs", CsWin32StampContent), - (typeof(SourceGenerator), "Windows.Win32.DISPLAYCONFIG_SCANLINE_ORDERING.g.cs", @"// ------------------------------------------------------------------------------ + (typeof(SourceGenerator), "Windows.Win32.DISPLAYCONFIG_SCANLINE_ORDERING.g.cs", $@"// ------------------------------------------------------------------------------ // // This code was generated by a tool. // @@ -1752,7 +1796,7 @@ public async Task TestSimpleEnumWithoutDocs() #pragma warning disable CS1591,CS1573,CS0465,CS0649,CS8019,CS1570,CS1584,CS1658,CS0436,CS8981 namespace Windows.Win32 -{ +{{ using global::System; using global::System.Diagnostics; using global::System.Runtime.CompilerServices; @@ -1760,18 +1804,19 @@ namespace Windows.Win32 using winmdroot = global::Windows.Win32; namespace Devices.Display - { + {{ + [global::System.CodeDom.Compiler.GeneratedCode(""Microsoft.Windows.CsWin32"", ""{ThisAssembly.AssemblyInformationalVersion}"")] internal enum DISPLAYCONFIG_SCANLINE_ORDERING - { + {{ DISPLAYCONFIG_SCANLINE_ORDERING_UNSPECIFIED = 0, DISPLAYCONFIG_SCANLINE_ORDERING_PROGRESSIVE = 1, DISPLAYCONFIG_SCANLINE_ORDERING_INTERLACED = 2, DISPLAYCONFIG_SCANLINE_ORDERING_INTERLACED_UPPERFIELDFIRST = 2, DISPLAYCONFIG_SCANLINE_ORDERING_INTERLACED_LOWERFIELDFIRST = 3, DISPLAYCONFIG_SCANLINE_ORDERING_FORCE_UINT32 = -1, - } - } -} + }} + }} +}} ".Replace("\r\n", "\n")), }, }, @@ -1797,7 +1842,7 @@ public async Task TestFlagsEnum() GeneratedSources = { (typeof(SourceGenerator), "Windows.Win32.CsWin32Stamp.g.cs", CsWin32StampContent), - (typeof(SourceGenerator), "Windows.Win32.FILE_ACCESS_FLAGS.g.cs", @"// ------------------------------------------------------------------------------ + (typeof(SourceGenerator), "Windows.Win32.FILE_ACCESS_FLAGS.g.cs", $@"// ------------------------------------------------------------------------------ // // This code was generated by a tool. // @@ -1808,7 +1853,7 @@ public async Task TestFlagsEnum() #pragma warning disable CS1591,CS1573,CS0465,CS0649,CS8019,CS1570,CS1584,CS1658,CS0436,CS8981 namespace Windows.Win32 -{ +{{ using global::System; using global::System.Diagnostics; using global::System.Runtime.CompilerServices; @@ -1816,10 +1861,11 @@ namespace Windows.Win32 using winmdroot = global::Windows.Win32; namespace Storage.FileSystem - { + {{ [Flags] + [global::System.CodeDom.Compiler.GeneratedCode(""Microsoft.Windows.CsWin32"", ""{ThisAssembly.AssemblyInformationalVersion}"")] internal enum FILE_ACCESS_FLAGS : uint - { + {{ FILE_READ_DATA = 0x00000001, FILE_LIST_DIRECTORY = 0x00000001, FILE_WRITE_DATA = 0x00000002, @@ -1846,9 +1892,9 @@ internal enum FILE_ACCESS_FLAGS : uint FILE_GENERIC_READ = 0x00120089, FILE_GENERIC_WRITE = 0x00120116, FILE_GENERIC_EXECUTE = 0x001200A0, - } - } -} + }} + }} +}} ".Replace("\r\n", "\n")), }, }, @@ -1873,7 +1919,7 @@ public async Task TestSimpleDelegate() }, GeneratedSources = { - (typeof(SourceGenerator), "Windows.Win32.BOOL.g.cs", @"// ------------------------------------------------------------------------------ + (typeof(SourceGenerator), "Windows.Win32.BOOL.g.cs", $@"// ------------------------------------------------------------------------------ // // This code was generated by a tool. // @@ -1884,7 +1930,7 @@ public async Task TestSimpleDelegate() #pragma warning disable CS1591,CS1573,CS0465,CS0649,CS8019,CS1570,CS1584,CS1658,CS0436,CS8981 namespace Windows.Win32 -{ +{{ using global::System; using global::System.Diagnostics; using global::System.Runtime.CompilerServices; @@ -1892,11 +1938,12 @@ namespace Windows.Win32 using winmdroot = global::Windows.Win32; namespace Foundation - { - [DebuggerDisplay(""{Value}"")] + {{ + [DebuggerDisplay(""{{Value}}"")] + [global::System.CodeDom.Compiler.GeneratedCode(""Microsoft.Windows.CsWin32"", ""{ThisAssembly.AssemblyInformationalVersion}"")] internal readonly partial struct BOOL : IEquatable - { + {{ internal readonly int Value; internal BOOL(int value) => this.Value = value; public static implicit operator int(BOOL value) => value.Value; @@ -1912,12 +1959,12 @@ internal readonly partial struct BOOL internal BOOL(bool value) => this.Value = value ? 1 : 0; public static implicit operator bool(BOOL value) => value.Value != 0; public static implicit operator BOOL(bool value) => new BOOL(value); - } - } -} + }} + }} +}} ".Replace("\r\n", "\n")), (typeof(SourceGenerator), "Windows.Win32.CsWin32Stamp.g.cs", CsWin32StampContent), - (typeof(SourceGenerator), "Windows.Win32.Delegates.g.cs", @"// ------------------------------------------------------------------------------ + (typeof(SourceGenerator), "Windows.Win32.Delegates.g.cs", $@"// ------------------------------------------------------------------------------ // // This code was generated by a tool. // @@ -1928,7 +1975,7 @@ internal readonly partial struct BOOL #pragma warning disable CS1591,CS1573,CS0465,CS0649,CS8019,CS1570,CS1584,CS1658,CS0436,CS8981 namespace Windows.Win32 -{ +{{ using global::System; using global::System.Diagnostics; using global::System.Runtime.CompilerServices; @@ -1936,13 +1983,13 @@ namespace Windows.Win32 using winmdroot = global::Windows.Win32; namespace UI.WindowsAndMessaging - { + {{ [UnmanagedFunctionPointerAttribute(CallingConvention.Winapi)] internal unsafe delegate winmdroot.Foundation.BOOL WNDENUMPROC(winmdroot.Foundation.HWND param0, winmdroot.Foundation.LPARAM param1); - } -} + }} +}} ".Replace("\r\n", "\n")), - (typeof(SourceGenerator), "Windows.Win32.HWND.g.cs", @"// ------------------------------------------------------------------------------ + (typeof(SourceGenerator), "Windows.Win32.HWND.g.cs", $@"// ------------------------------------------------------------------------------ // // This code was generated by a tool. // @@ -1953,7 +2000,7 @@ namespace UI.WindowsAndMessaging #pragma warning disable CS1591,CS1573,CS0465,CS0649,CS8019,CS1570,CS1584,CS1658,CS0436,CS8981 namespace Windows.Win32 -{ +{{ using global::System; using global::System.Diagnostics; using global::System.Runtime.CompilerServices; @@ -1961,11 +2008,12 @@ namespace Windows.Win32 using winmdroot = global::Windows.Win32; namespace Foundation - { - [DebuggerDisplay(""{Value}"")] + {{ + [DebuggerDisplay(""{{Value}}"")] + [global::System.CodeDom.Compiler.GeneratedCode(""Microsoft.Windows.CsWin32"", ""{ThisAssembly.AssemblyInformationalVersion}"")] internal readonly partial struct HWND : IEquatable - { + {{ internal readonly IntPtr Value; internal HWND(IntPtr value) => this.Value = value; @@ -1982,11 +2030,11 @@ internal readonly partial struct HWND public override bool Equals(object obj) => obj is HWND other && this.Equals(other); public override int GetHashCode() => this.Value.GetHashCode(); - } - } -} + }} + }} +}} ".Replace("\r\n", "\n")), - (typeof(SourceGenerator), "Windows.Win32.LPARAM.g.cs", @"// ------------------------------------------------------------------------------ + (typeof(SourceGenerator), "Windows.Win32.LPARAM.g.cs", $@"// ------------------------------------------------------------------------------ // // This code was generated by a tool. // @@ -1997,7 +2045,7 @@ internal readonly partial struct HWND #pragma warning disable CS1591,CS1573,CS0465,CS0649,CS8019,CS1570,CS1584,CS1658,CS0436,CS8981 namespace Windows.Win32 -{ +{{ using global::System; using global::System.Diagnostics; using global::System.Runtime.CompilerServices; @@ -2005,11 +2053,12 @@ namespace Windows.Win32 using winmdroot = global::Windows.Win32; namespace Foundation - { - [DebuggerDisplay(""{Value}"")] + {{ + [DebuggerDisplay(""{{Value}}"")] + [global::System.CodeDom.Compiler.GeneratedCode(""Microsoft.Windows.CsWin32"", ""{ThisAssembly.AssemblyInformationalVersion}"")] internal readonly partial struct LPARAM : IEquatable - { + {{ internal readonly nint Value; internal LPARAM(nint value) => this.Value = value; public static implicit operator nint(LPARAM value) => value.Value; @@ -2022,9 +2071,9 @@ internal readonly partial struct LPARAM public override bool Equals(object obj) => obj is LPARAM other && this.Equals(other); public override int GetHashCode() => this.Value.GetHashCode(); - } - } -} + }} + }} +}} ".Replace("\r\n", "\n")), }, }, @@ -2050,7 +2099,7 @@ public async Task TestSimpleMethod() GeneratedSources = { (typeof(SourceGenerator), "Windows.Win32.CsWin32Stamp.g.cs", CsWin32StampContent), - (typeof(SourceGenerator), "Windows.Win32.HDC.g.cs", @"// ------------------------------------------------------------------------------ + (typeof(SourceGenerator), "Windows.Win32.HDC.g.cs", $@"// ------------------------------------------------------------------------------ // // This code was generated by a tool. // @@ -2061,7 +2110,7 @@ public async Task TestSimpleMethod() #pragma warning disable CS1591,CS1573,CS0465,CS0649,CS8019,CS1570,CS1584,CS1658,CS0436,CS8981 namespace Windows.Win32 -{ +{{ using global::System; using global::System.Diagnostics; using global::System.Runtime.CompilerServices; @@ -2069,11 +2118,12 @@ namespace Windows.Win32 using winmdroot = global::Windows.Win32; namespace Graphics.Gdi - { - [DebuggerDisplay(""{Value}"")] + {{ + [DebuggerDisplay(""{{Value}}"")] + [global::System.CodeDom.Compiler.GeneratedCode(""Microsoft.Windows.CsWin32"", ""{ThisAssembly.AssemblyInformationalVersion}"")] internal readonly partial struct HDC : IEquatable - { + {{ internal readonly IntPtr Value; internal HDC(IntPtr value) => this.Value = value; @@ -2090,11 +2140,11 @@ internal readonly partial struct HDC public override bool Equals(object obj) => obj is HDC other && this.Equals(other); public override int GetHashCode() => this.Value.GetHashCode(); - } - } -} + }} + }} +}} ".Replace("\r\n", "\n")), - (typeof(SourceGenerator), "Windows.Win32.HWND.g.cs", @"// ------------------------------------------------------------------------------ + (typeof(SourceGenerator), "Windows.Win32.HWND.g.cs", $@"// ------------------------------------------------------------------------------ // // This code was generated by a tool. // @@ -2105,7 +2155,7 @@ internal readonly partial struct HDC #pragma warning disable CS1591,CS1573,CS0465,CS0649,CS8019,CS1570,CS1584,CS1658,CS0436,CS8981 namespace Windows.Win32 -{ +{{ using global::System; using global::System.Diagnostics; using global::System.Runtime.CompilerServices; @@ -2113,11 +2163,12 @@ namespace Windows.Win32 using winmdroot = global::Windows.Win32; namespace Foundation - { - [DebuggerDisplay(""{Value}"")] + {{ + [DebuggerDisplay(""{{Value}}"")] + [global::System.CodeDom.Compiler.GeneratedCode(""Microsoft.Windows.CsWin32"", ""{ThisAssembly.AssemblyInformationalVersion}"")] internal readonly partial struct HWND : IEquatable - { + {{ internal readonly IntPtr Value; internal HWND(IntPtr value) => this.Value = value; @@ -2134,11 +2185,11 @@ internal readonly partial struct HWND public override bool Equals(object obj) => obj is HWND other && this.Equals(other); public override int GetHashCode() => this.Value.GetHashCode(); - } - } -} + }} + }} +}} ".Replace("\r\n", "\n")), - (typeof(SourceGenerator), "Windows.Win32.PInvoke.User32.g.cs", @"// ------------------------------------------------------------------------------ + (typeof(SourceGenerator), "Windows.Win32.PInvoke.User32.g.cs", $@"// ------------------------------------------------------------------------------ // // This code was generated by a tool. // @@ -2149,7 +2200,7 @@ internal readonly partial struct HWND #pragma warning disable CS1591,CS1573,CS0465,CS0649,CS8019,CS1570,CS1584,CS1658,CS0436,CS8981 namespace Windows.Win32 -{ +{{ using global::System; using global::System.Diagnostics; using global::System.Runtime.CompilerServices; @@ -2160,8 +2211,9 @@ namespace Windows.Win32 /// /// Contains extern methods from ""User32.dll"". /// + [global::System.CodeDom.Compiler.GeneratedCode(""Microsoft.Windows.CsWin32"", ""{ThisAssembly.AssemblyInformationalVersion}"")] internal static partial class PInvoke - { + {{ /// The ReleaseDC function releases a device context (DC), freeing it for use by other applications. The effect of the ReleaseDC function depends on the type of DC. It frees only common and window DCs. It has no effect on class or private DCs. /// A handle to the window whose DC is to be released. /// A handle to the DC to be released. @@ -2174,8 +2226,8 @@ internal static partial class PInvoke [DllImport(""User32"", ExactSpelling = true)] [DefaultDllImportSearchPaths(DllImportSearchPath.System32)] internal static extern int ReleaseDC(winmdroot.Foundation.HWND hWnd, winmdroot.Graphics.Gdi.HDC hDC); - } -} + }} +}} ".Replace("\r\n", "\n")), }, }, @@ -2200,7 +2252,7 @@ public async Task TestMethodWithOverloads() }, GeneratedSources = { - (typeof(SourceGenerator), "Windows.Win32.BOOL.g.cs", @"// ------------------------------------------------------------------------------ + (typeof(SourceGenerator), "Windows.Win32.BOOL.g.cs", $@"// ------------------------------------------------------------------------------ // // This code was generated by a tool. // @@ -2211,7 +2263,7 @@ public async Task TestMethodWithOverloads() #pragma warning disable CS1591,CS1573,CS0465,CS0649,CS8019,CS1570,CS1584,CS1658,CS0436,CS8981 namespace Windows.Win32 -{ +{{ using global::System; using global::System.Diagnostics; using global::System.Runtime.CompilerServices; @@ -2219,11 +2271,12 @@ namespace Windows.Win32 using winmdroot = global::Windows.Win32; namespace Foundation - { - [DebuggerDisplay(""{Value}"")] + {{ + [DebuggerDisplay(""{{Value}}"")] + [global::System.CodeDom.Compiler.GeneratedCode(""Microsoft.Windows.CsWin32"", ""{ThisAssembly.AssemblyInformationalVersion}"")] internal readonly partial struct BOOL : IEquatable - { + {{ internal readonly int Value; internal BOOL(int value) => this.Value = value; public static implicit operator int(BOOL value) => value.Value; @@ -2239,12 +2292,12 @@ internal readonly partial struct BOOL internal BOOL(bool value) => this.Value = value ? 1 : 0; public static implicit operator bool(BOOL value) => value.Value != 0; public static implicit operator BOOL(bool value) => new BOOL(value); - } - } -} + }} + }} +}} ".Replace("\r\n", "\n")), (typeof(SourceGenerator), "Windows.Win32.CsWin32Stamp.g.cs", CsWin32StampContent), - (typeof(SourceGenerator), "Windows.Win32.FILE_ACCESS_FLAGS.g.cs", @"// ------------------------------------------------------------------------------ + (typeof(SourceGenerator), "Windows.Win32.FILE_ACCESS_FLAGS.g.cs", $@"// ------------------------------------------------------------------------------ // // This code was generated by a tool. // @@ -2255,7 +2308,7 @@ internal readonly partial struct BOOL #pragma warning disable CS1591,CS1573,CS0465,CS0649,CS8019,CS1570,CS1584,CS1658,CS0436,CS8981 namespace Windows.Win32 -{ +{{ using global::System; using global::System.Diagnostics; using global::System.Runtime.CompilerServices; @@ -2263,10 +2316,11 @@ namespace Windows.Win32 using winmdroot = global::Windows.Win32; namespace Storage.FileSystem - { + {{ [Flags] + [global::System.CodeDom.Compiler.GeneratedCode(""Microsoft.Windows.CsWin32"", ""{ThisAssembly.AssemblyInformationalVersion}"")] internal enum FILE_ACCESS_FLAGS : uint - { + {{ FILE_READ_DATA = 0x00000001, FILE_LIST_DIRECTORY = 0x00000001, FILE_WRITE_DATA = 0x00000002, @@ -2293,11 +2347,11 @@ internal enum FILE_ACCESS_FLAGS : uint FILE_GENERIC_READ = 0x00120089, FILE_GENERIC_WRITE = 0x00120116, FILE_GENERIC_EXECUTE = 0x001200A0, - } - } -} + }} + }} +}} ".Replace("\r\n", "\n")), - (typeof(SourceGenerator), "Windows.Win32.FILE_CREATION_DISPOSITION.g.cs", @"// ------------------------------------------------------------------------------ + (typeof(SourceGenerator), "Windows.Win32.FILE_CREATION_DISPOSITION.g.cs", $@"// ------------------------------------------------------------------------------ // // This code was generated by a tool. // @@ -2308,7 +2362,7 @@ internal enum FILE_ACCESS_FLAGS : uint #pragma warning disable CS1591,CS1573,CS0465,CS0649,CS8019,CS1570,CS1584,CS1658,CS0436,CS8981 namespace Windows.Win32 -{ +{{ using global::System; using global::System.Diagnostics; using global::System.Runtime.CompilerServices; @@ -2316,19 +2370,20 @@ namespace Windows.Win32 using winmdroot = global::Windows.Win32; namespace Storage.FileSystem - { + {{ + [global::System.CodeDom.Compiler.GeneratedCode(""Microsoft.Windows.CsWin32"", ""{ThisAssembly.AssemblyInformationalVersion}"")] internal enum FILE_CREATION_DISPOSITION : uint - { + {{ CREATE_NEW = 1U, CREATE_ALWAYS = 2U, OPEN_EXISTING = 3U, OPEN_ALWAYS = 4U, TRUNCATE_EXISTING = 5U, - } - } -} + }} + }} +}} ".Replace("\r\n", "\n")), - (typeof(SourceGenerator), "Windows.Win32.FILE_FLAGS_AND_ATTRIBUTES.g.cs", @"// ------------------------------------------------------------------------------ + (typeof(SourceGenerator), "Windows.Win32.FILE_FLAGS_AND_ATTRIBUTES.g.cs", $@"// ------------------------------------------------------------------------------ // // This code was generated by a tool. // @@ -2339,7 +2394,7 @@ internal enum FILE_CREATION_DISPOSITION : uint #pragma warning disable CS1591,CS1573,CS0465,CS0649,CS8019,CS1570,CS1584,CS1658,CS0436,CS8981 namespace Windows.Win32 -{ +{{ using global::System; using global::System.Diagnostics; using global::System.Runtime.CompilerServices; @@ -2347,10 +2402,11 @@ namespace Windows.Win32 using winmdroot = global::Windows.Win32; namespace Storage.FileSystem - { + {{ [Flags] + [global::System.CodeDom.Compiler.GeneratedCode(""Microsoft.Windows.CsWin32"", ""{ThisAssembly.AssemblyInformationalVersion}"")] internal enum FILE_FLAGS_AND_ATTRIBUTES : uint - { + {{ FILE_ATTRIBUTE_READONLY = 0x00000001, FILE_ATTRIBUTE_HIDDEN = 0x00000002, FILE_ATTRIBUTE_SYSTEM = 0x00000004, @@ -2396,11 +2452,11 @@ internal enum FILE_FLAGS_AND_ATTRIBUTES : uint SECURITY_EFFECTIVE_ONLY = 0x00080000, SECURITY_SQOS_PRESENT = 0x00100000, SECURITY_VALID_SQOS_FLAGS = 0x001F0000, - } - } -} + }} + }} +}} ".Replace("\r\n", "\n")), - (typeof(SourceGenerator), "Windows.Win32.FILE_SHARE_MODE.g.cs", @"// ------------------------------------------------------------------------------ + (typeof(SourceGenerator), "Windows.Win32.FILE_SHARE_MODE.g.cs", $@"// ------------------------------------------------------------------------------ // // This code was generated by a tool. // @@ -2411,7 +2467,7 @@ internal enum FILE_FLAGS_AND_ATTRIBUTES : uint #pragma warning disable CS1591,CS1573,CS0465,CS0649,CS8019,CS1570,CS1584,CS1658,CS0436,CS8981 namespace Windows.Win32 -{ +{{ using global::System; using global::System.Diagnostics; using global::System.Runtime.CompilerServices; @@ -2419,19 +2475,20 @@ namespace Windows.Win32 using winmdroot = global::Windows.Win32; namespace Storage.FileSystem - { + {{ [Flags] + [global::System.CodeDom.Compiler.GeneratedCode(""Microsoft.Windows.CsWin32"", ""{ThisAssembly.AssemblyInformationalVersion}"")] internal enum FILE_SHARE_MODE : uint - { + {{ FILE_SHARE_NONE = 0x00000000, FILE_SHARE_DELETE = 0x00000004, FILE_SHARE_READ = 0x00000001, FILE_SHARE_WRITE = 0x00000002, - } - } -} + }} + }} +}} ".Replace("\r\n", "\n")), - (typeof(SourceGenerator), "Windows.Win32.HANDLE.g.cs", @"// ------------------------------------------------------------------------------ + (typeof(SourceGenerator), "Windows.Win32.HANDLE.g.cs", $@"// ------------------------------------------------------------------------------ // // This code was generated by a tool. // @@ -2442,7 +2499,7 @@ internal enum FILE_SHARE_MODE : uint #pragma warning disable CS1591,CS1573,CS0465,CS0649,CS8019,CS1570,CS1584,CS1658,CS0436,CS8981 namespace Windows.Win32 -{ +{{ using global::System; using global::System.Diagnostics; using global::System.Runtime.CompilerServices; @@ -2450,11 +2507,12 @@ namespace Windows.Win32 using winmdroot = global::Windows.Win32; namespace Foundation - { - [DebuggerDisplay(""{Value}"")] + {{ + [DebuggerDisplay(""{{Value}}"")] + [global::System.CodeDom.Compiler.GeneratedCode(""Microsoft.Windows.CsWin32"", ""{ThisAssembly.AssemblyInformationalVersion}"")] internal readonly partial struct HANDLE : IEquatable - { + {{ internal readonly IntPtr Value; internal HANDLE(IntPtr value) => this.Value = value; @@ -2471,11 +2529,11 @@ internal readonly partial struct HANDLE public override bool Equals(object obj) => obj is HANDLE other && this.Equals(other); public override int GetHashCode() => this.Value.GetHashCode(); - } - } -} + }} + }} +}} ".Replace("\r\n", "\n")), - (typeof(SourceGenerator), "Windows.Win32.PCWSTR.g.cs", @"// ------------------------------------------------------------------------------ + (typeof(SourceGenerator), "Windows.Win32.PCWSTR.g.cs", $@"// ------------------------------------------------------------------------------ // // This code was generated by a tool. // @@ -2486,7 +2544,7 @@ internal readonly partial struct HANDLE #pragma warning disable CS1591,CS1573,CS0465,CS0649,CS8019,CS1570,CS1584,CS1658,CS0436,CS8981 namespace Windows.Win32 -{ +{{ using global::System; using global::System.Diagnostics; using global::System.Runtime.CompilerServices; @@ -2494,14 +2552,14 @@ namespace Windows.Win32 using winmdroot = global::Windows.Win32; namespace Foundation - { - /// - /// A pointer to a constant character string. - /// - [DebuggerDisplay(""{"" + nameof(DebuggerDisplay) + ""}"")] + {{ + /// + /// A pointer to a constant character string. + /// + [DebuggerDisplay(""{{"" + nameof(DebuggerDisplay) + ""}}"")] internal unsafe readonly partial struct PCWSTR : IEquatable - { + {{ /// /// A pointer to the first character in the string. The content should be considered readonly, as it was typed as constant in the SDK. /// @@ -2522,17 +2580,17 @@ internal unsafe readonly partial struct PCWSTR /// Gets the number of characters up to the first null character (exclusive). /// internal int Length - { + {{ get - { + {{ char* p = this.Value; if (p is null) return 0; while (*p != '\0') p++; return checked((int)(p - this.Value)); - } - } + }} + }} /// @@ -2548,11 +2606,11 @@ internal int Length /// Returns a span of the characters in this string. /// internal ReadOnlySpan AsSpan() => this.Value is null ? default(ReadOnlySpan) : new ReadOnlySpan(this.Value, this.Length); - } - } -} + }} + }} +}} ".Replace("\r\n", "\n")), - (typeof(SourceGenerator), "Windows.Win32.PInvoke.Kernel32.g.cs", @"// ------------------------------------------------------------------------------ + (typeof(SourceGenerator), "Windows.Win32.PInvoke.Kernel32.g.cs", $@"// ------------------------------------------------------------------------------ // // This code was generated by a tool. // @@ -2563,7 +2621,7 @@ internal int Length #pragma warning disable CS1591,CS1573,CS0465,CS0649,CS8019,CS1570,CS1584,CS1658,CS0436,CS8981 namespace Windows.Win32 -{ +{{ using global::System; using global::System.Diagnostics; using global::System.Runtime.CompilerServices; @@ -2571,11 +2629,12 @@ namespace Windows.Win32 using winmdroot = global::Windows.Win32; - /// - /// Contains extern methods from ""Kernel32.dll"". - /// + /// + /// Contains extern methods from ""Kernel32.dll"". + /// + [global::System.CodeDom.Compiler.GeneratedCode(""Microsoft.Windows.CsWin32"", ""{ThisAssembly.AssemblyInformationalVersion}"")] internal static partial class PInvoke - { + {{ /// Closes an open object handle. /// A valid handle to an open object. /// @@ -2590,31 +2649,31 @@ internal static partial class PInvoke /// internal static unsafe Microsoft.Win32.SafeHandles.SafeFileHandle CreateFile(string lpFileName, winmdroot.Storage.FileSystem.FILE_ACCESS_FLAGS dwDesiredAccess, winmdroot.Storage.FileSystem.FILE_SHARE_MODE dwShareMode, winmdroot.Security.SECURITY_ATTRIBUTES? lpSecurityAttributes, winmdroot.Storage.FileSystem.FILE_CREATION_DISPOSITION dwCreationDisposition, winmdroot.Storage.FileSystem.FILE_FLAGS_AND_ATTRIBUTES dwFlagsAndAttributes, SafeHandle hTemplateFile) - { + {{ bool hTemplateFileAddRef = false; try - { + {{ fixed (char* lpFileNameLocal = lpFileName) - { + {{ winmdroot.Security.SECURITY_ATTRIBUTES lpSecurityAttributesLocal = lpSecurityAttributes.HasValue ? lpSecurityAttributes.Value : default(winmdroot.Security.SECURITY_ATTRIBUTES); winmdroot.Foundation.HANDLE hTemplateFileLocal; if (hTemplateFile is object) - { + {{ hTemplateFile.DangerousAddRef(ref hTemplateFileAddRef); hTemplateFileLocal = (winmdroot.Foundation.HANDLE)hTemplateFile.DangerousGetHandle(); - } + }} else hTemplateFileLocal = default(winmdroot.Foundation.HANDLE); winmdroot.Foundation.HANDLE __result = PInvoke.CreateFile(lpFileNameLocal, dwDesiredAccess, dwShareMode, lpSecurityAttributes.HasValue ? &lpSecurityAttributesLocal : null, dwCreationDisposition, dwFlagsAndAttributes, hTemplateFileLocal); return new Microsoft.Win32.SafeHandles.SafeFileHandle(__result, ownsHandle: true); - } - } + }} + }} finally - { + {{ if (hTemplateFileAddRef) hTemplateFile.DangerousRelease(); - } - } + }} + }} /// Creates or opens a file or I/O device. The most commonly used I/O devices are as follows:\_file, file stream, directory, physical disk, volume, console buffer, tape drive, communications resource, mailslot, and pipe. /// @@ -2655,10 +2714,10 @@ internal static unsafe Microsoft.Win32.SafeHandles.SafeFileHandle CreateFile(str [DllImport(""Kernel32"", ExactSpelling = true, EntryPoint = ""CreateFileW"", SetLastError = true)] [DefaultDllImportSearchPaths(DllImportSearchPath.System32)] internal static extern unsafe winmdroot.Foundation.HANDLE CreateFile(winmdroot.Foundation.PCWSTR lpFileName, winmdroot.Storage.FileSystem.FILE_ACCESS_FLAGS dwDesiredAccess, winmdroot.Storage.FileSystem.FILE_SHARE_MODE dwShareMode, [Optional] winmdroot.Security.SECURITY_ATTRIBUTES* lpSecurityAttributes, winmdroot.Storage.FileSystem.FILE_CREATION_DISPOSITION dwCreationDisposition, winmdroot.Storage.FileSystem.FILE_FLAGS_AND_ATTRIBUTES dwFlagsAndAttributes, winmdroot.Foundation.HANDLE hTemplateFile); - } -} + }} +}} ".Replace("\r\n", "\n")), - (typeof(SourceGenerator), "Windows.Win32.PWSTR.g.cs", @"// ------------------------------------------------------------------------------ + (typeof(SourceGenerator), "Windows.Win32.PWSTR.g.cs", $@"// ------------------------------------------------------------------------------ // // This code was generated by a tool. // @@ -2669,7 +2728,7 @@ internal static unsafe Microsoft.Win32.SafeHandles.SafeFileHandle CreateFile(str #pragma warning disable CS1591,CS1573,CS0465,CS0649,CS8019,CS1570,CS1584,CS1658,CS0436,CS8981 namespace Windows.Win32 -{ +{{ using global::System; using global::System.Diagnostics; using global::System.Runtime.CompilerServices; @@ -2677,11 +2736,12 @@ namespace Windows.Win32 using winmdroot = global::Windows.Win32; namespace Foundation - { - [DebuggerDisplay(""{Value}"")] + {{ + [DebuggerDisplay(""{{Value}}"")] + [global::System.CodeDom.Compiler.GeneratedCode(""Microsoft.Windows.CsWin32"", ""{ThisAssembly.AssemblyInformationalVersion}"")] internal unsafe readonly partial struct PWSTR : IEquatable - { + {{ internal readonly char* Value; internal PWSTR(char* value) => this.Value = value; public static implicit operator char*(PWSTR value) => value.Value; @@ -2696,17 +2756,17 @@ internal unsafe readonly partial struct PWSTR public override int GetHashCode() => checked((int)this.Value); internal int Length - { + {{ get - { + {{ char* p = this.Value; if (p is null) return 0; while (*p != '\0') p++; return checked((int)(p - this.Value)); - } - } + }} + }} public override string ToString() => this.Value is null ? null : new string(this.Value); @@ -2714,11 +2774,11 @@ internal int Length /// Returns a span of the characters in this string. /// internal Span AsSpan() => this.Value is null ? default(Span) : new Span(this.Value, this.Length); - } - } -} + }} + }} +}} ".Replace("\r\n", "\n")), - (typeof(SourceGenerator), "Windows.Win32.SECURITY_ATTRIBUTES.g.cs", @"// ------------------------------------------------------------------------------ + (typeof(SourceGenerator), "Windows.Win32.SECURITY_ATTRIBUTES.g.cs", $@"// ------------------------------------------------------------------------------ // // This code was generated by a tool. // @@ -2729,7 +2789,7 @@ internal int Length #pragma warning disable CS1591,CS1573,CS0465,CS0649,CS8019,CS1570,CS1584,CS1658,CS0436,CS8981 namespace Windows.Win32 -{ +{{ using global::System; using global::System.Diagnostics; using global::System.Runtime.CompilerServices; @@ -2737,13 +2797,14 @@ namespace Windows.Win32 using winmdroot = global::Windows.Win32; namespace Security - { + {{ /// The SECURITY_ATTRIBUTES structure contains the security descriptor for an object and specifies whether the handle retrieved by specifying this structure is inheritable. /// /// Read more on docs.microsoft.com. /// + [global::System.CodeDom.Compiler.GeneratedCode(""Microsoft.Windows.CsWin32"", ""{ThisAssembly.AssemblyInformationalVersion}"")] internal partial struct SECURITY_ATTRIBUTES - { + {{ /// The size, in bytes, of this structure. Set this value to the size of the **SECURITY\_ATTRIBUTES** structure. internal uint nLength; /// @@ -2753,9 +2814,9 @@ internal partial struct SECURITY_ATTRIBUTES internal unsafe void* lpSecurityDescriptor; /// A Boolean value that specifies whether the returned handle is inherited when a new process is created. If this member is **TRUE**, the new process inherits the handle. internal winmdroot.Foundation.BOOL bInheritHandle; - } - } -} + }} + }} +}} ".Replace("\r\n", "\n")), }, },