Skip to content

Commit

Permalink
Initial attempt at adding strong typing to RAIIFree for #389.
Browse files Browse the repository at this point in the history
Generated C# looks correct but ILSpy only shows typeof(Type).
  • Loading branch information
mikebattista committed Nov 21, 2022
1 parent 870bbb0 commit f0deee3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ public static void WriteToStream(Dictionary<string, string> methodNamesToNamespa

if (!string.IsNullOrEmpty(item.CloseApi))
{
writer.WriteLine($" [RAIIFree(\"{item.CloseApi}\")]");
methodNamesToNamespaces.TryGetValue(item.CloseApi, out var closeApiNamespace);
writer.WriteLine($" [RAIIFree(typeof({closeApiNamespace}.Apis), \"{item.CloseApi}\")]");
}

if (!string.IsNullOrEmpty(item.AlsoUsableFor))
Expand Down
8 changes: 6 additions & 2 deletions sources/Win32MetadataInterop/RAIIFreeAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,16 @@ namespace Windows.Win32.Interop
{
public class RAIIFreeAttribute : Attribute
{
public RAIIFreeAttribute(string name)
public RAIIFreeAttribute(Type type, string name)
{
this.Type = type;
this.Name = name;
}

/// <summary>Gets the name of the type that was used in the native signature.</summary>
/// <summary>Gets the containing class for the CloseApi.</summary>
public Type Type { get; }

/// <summary>Gets the name of the CloseApi.</summary>
public string Name { get; }
}
}

0 comments on commit f0deee3

Please sign in to comment.