Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update usage of COM interop to ComWrappers when targeting .NET 9 #563

Merged
merged 3 commits into from
Jun 27, 2024
Merged
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
6 changes: 4 additions & 2 deletions eng/Versions.props
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,17 @@
<Project>
<PropertyGroup>
<!-- This repo version -->
<VersionPrefix>1.7.0</VersionPrefix>
<VersionPrefix>2.0.0</VersionPrefix>
<PreReleaseVersionLabel>beta</PreReleaseVersionLabel>
<SemanticVersioningV1>true</SemanticVersioningV1>
<!-- Opt-in/out repo features -->
<UsingToolPdbConverter>false</UsingToolPdbConverter>
<UsingToolNetFrameworkReferenceAssemblies>true</UsingToolNetFrameworkReferenceAssemblies>
<UsingToolNuGetRepack>true</UsingToolNuGetRepack>
<!-- symreader -->
<MicrosoftDiaSymReaderVersion>1.4.0-beta2-21525-04</MicrosoftDiaSymReaderVersion>
<MicrosoftDiaSymReaderVersion>2.2.0-beta.24327.1

</MicrosoftDiaSymReaderVersion>
<MicrosoftDiaSymReaderNativeVersion>17.0.0-beta1.21524.1</MicrosoftDiaSymReaderNativeVersion>
<!-- CoreFX -->
<SystemCollectionsImmutableVersion>5.0.0</SystemCollectionsImmutableVersion>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,20 @@
using System.Reflection.Metadata.Ecma335;
using System.Reflection.PortableExecutable;
using System.Runtime.InteropServices;
#if NET9_0_OR_GREATER
using System.Runtime.InteropServices.Marshalling;
#endif
using System.Text;

namespace Microsoft.DiaSymReader.PortablePdb.UnitTests
{
/// <summary>
/// Used to test <see cref="IMetadataImport"/>.
/// </summary>
internal sealed class TestIMetadataImport : IMetadataImport, IDisposable
#if NET9_0_OR_GREATER
[GeneratedComClass]
#endif
internal sealed partial class TestIMetadataImport : IMetadataImport, IDisposable
{
private readonly PEReader _peReader;
public readonly MetadataReader MetadataReader;
Expand Down Expand Up @@ -45,27 +51,27 @@ public unsafe int GetSigFromToken(int tkSignature, out byte* ppvSig, out int pcb

public void GetTypeDefProps(
int typeDefinition,
[MarshalAs(UnmanagedType.LPWStr), Out]StringBuilder qualifiedName,
[MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 2)] char[] qualifiedName,
int qualifiedNameBufferLength,
out int qualifiedNameLength,
[MarshalAs(UnmanagedType.U4)]out TypeAttributes attributes,
out TypeAttributes attributes,
out int baseType)
{
var handle = (TypeDefinitionHandle)MetadataTokens.Handle(typeDefinition);
var typeDef = MetadataReader.GetTypeDefinition(handle);

if (qualifiedName != null)
{
qualifiedName.Clear();

StringBuilder builder = new();
if (!typeDef.Namespace.IsNil)
{
qualifiedName.Append(MetadataReader.GetString(typeDef.Namespace));
qualifiedName.Append('.');
builder.Append(MetadataReader.GetString(typeDef.Namespace));
builder.Append('.');
}

qualifiedName.Append(MetadataReader.GetString(typeDef.Name));
qualifiedName.Length = qualifiedNameLength = Math.Min(qualifiedName.Length, Math.Max(0, qualifiedNameBufferLength - 1));
builder.Append(MetadataReader.GetString(typeDef.Name));
qualifiedNameLength = Math.Min(builder.Length, Math.Max(0, qualifiedNameBufferLength - 1));
builder.CopyTo(0, qualifiedName, 0, qualifiedNameLength);
}
else
{
Expand All @@ -81,7 +87,7 @@ public void GetTypeDefProps(
public void GetTypeRefProps(
int typeReference,
out int resolutionScope,
[MarshalAs(UnmanagedType.LPWStr), Out]StringBuilder qualifiedName,
[MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 3)] char[] qualifiedName,
int qualifiedNameBufferLength,
out int qualifiedNameLength)
{
Expand All @@ -90,16 +96,16 @@ public void GetTypeRefProps(

if (qualifiedName != null)
{
qualifiedName.Clear();

StringBuilder builder = new();
if (!typeRef.Namespace.IsNil)
{
qualifiedName.Append(MetadataReader.GetString(typeRef.Namespace));
qualifiedName.Append('.');
builder.Append(MetadataReader.GetString(typeRef.Namespace));
builder.Append('.');
}

qualifiedName.Append(MetadataReader.GetString(typeRef.Name));
qualifiedName.Length = qualifiedNameLength = Math.Min(qualifiedName.Length, Math.Max(0, qualifiedNameBufferLength - 1));
builder.Append(MetadataReader.GetString(typeRef.Name));
qualifiedNameLength = Math.Min(builder.Length, Math.Max(0, qualifiedNameBufferLength - 1));
builder.CopyTo(0, qualifiedName, 0, qualifiedNameLength);
}
else
{
Expand Down Expand Up @@ -278,7 +284,7 @@ public unsafe uint GetCustomAttributeProps(uint cv, out uint ptkObj, out uint pt
throw new NotImplementedException();
}

public uint GetEventProps(uint ev, out uint pointerClass, StringBuilder stringEvent, uint cchEvent, out uint pchEvent, out uint pdwEventFlags, out uint ptkEventType, out uint pmdAddOn, out uint pmdRemoveOn, out uint pmdFire, [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 11)]uint[] rmdOtherMethod, uint countMax)
public uint GetEventProps(uint ev, out uint pointerClass, [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 3)] char[] stringEvent, uint cchEvent, out uint pchEvent, out uint pdwEventFlags, out uint ptkEventType, out uint pmdAddOn, out uint pmdRemoveOn, out uint pmdFire, [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 11)]uint[] rmdOtherMethod, uint countMax)
{
throw new NotImplementedException();
}
Expand All @@ -288,7 +294,7 @@ public unsafe uint GetFieldMarshal(uint tk, out byte* ppvNativeType)
throw new NotImplementedException();
}

public unsafe uint GetFieldProps(uint mb, out uint pointerClass, StringBuilder stringField, uint cchField, out uint pchField, out uint pdwAttr, out byte* ppvSigBlob, out uint pcbSigBlob, out uint pdwCPlusTypeFlag, out void* ppValue)
public unsafe uint GetFieldProps(uint mb, out uint pointerClass, [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 3)] char[] stringField, uint cchField, out uint pchField, out uint pdwAttr, out byte* ppvSigBlob, out uint pcbSigBlob, out uint pdwCPlusTypeFlag, out void* ppValue)
{
throw new NotImplementedException();
}
Expand All @@ -298,12 +304,12 @@ public uint GetInterfaceImplProps(uint impl, out uint pointerClass)
throw new NotImplementedException();
}

public unsafe uint GetMemberProps(uint mb, out uint pointerClass, StringBuilder stringMember, uint cchMember, out uint pchMember, out uint pdwAttr, out byte* ppvSigBlob, out uint pcbSigBlob, out uint pulCodeRVA, out uint pdwImplFlags, out uint pdwCPlusTypeFlag, out void* ppValue)
public unsafe uint GetMemberProps(uint mb, out uint pointerClass, [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 3)] char[] stringMember, uint cchMember, out uint pchMember, out uint pdwAttr, out byte* ppvSigBlob, out uint pcbSigBlob, out uint pulCodeRVA, out uint pdwImplFlags, out uint pdwCPlusTypeFlag, out void* ppValue)
{
throw new NotImplementedException();
}

public unsafe uint GetMemberRefProps(uint mr, ref uint ptk, StringBuilder stringMember, uint cchMember, out uint pchMember, out byte* ppvSigBlob)
public unsafe uint GetMemberRefProps(uint mr, ref uint ptk, [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 3)] char[] stringMember, uint cchMember, out uint pchMember, out byte* ppvSigBlob)
{
throw new NotImplementedException();
}
Expand All @@ -323,7 +329,7 @@ public uint GetModuleFromScope()
throw new NotImplementedException();
}

public uint GetModuleRefProps(uint mur, StringBuilder stringName, uint cchName)
public uint GetModuleRefProps(uint mur, [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 2)] char[] stringName, uint cchName)
{
throw new NotImplementedException();
}
Expand All @@ -348,7 +354,7 @@ public int GetParamForMethodIndex(uint md, uint ulongParamSeq, out uint pointerP
throw new NotImplementedException();
}

public unsafe uint GetParamProps(uint tk, out uint pmd, out uint pulSequence, StringBuilder stringName, uint cchName, out uint pchName, out uint pdwAttr, out uint pdwCPlusTypeFlag, out void* ppValue)
public unsafe uint GetParamProps(uint tk, out uint pmd, out uint pulSequence, [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 4)] char[] stringName, uint cchName, out uint pchName, out uint pdwAttr, out uint pdwCPlusTypeFlag, out void* ppValue)
{
throw new NotImplementedException();
}
Expand All @@ -358,12 +364,12 @@ public unsafe uint GetPermissionSetProps(uint pm, out uint pdwAction, out void*
throw new NotImplementedException();
}

public uint GetPinvokeMap(uint tk, out uint pdwMappingFlags, StringBuilder stringImportName, uint cchImportName, out uint pchImportName)
public uint GetPinvokeMap(uint tk, out uint pdwMappingFlags, [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 3)] char[] stringImportName, uint cchImportName, out uint pchImportName)
{
throw new NotImplementedException();
}

public unsafe uint GetPropertyProps(uint prop, out uint pointerClass, StringBuilder stringProperty, uint cchProperty, out uint pchProperty, out uint pdwPropFlags, out byte* ppvSig, out uint bytePointerSig, out uint pdwCPlusTypeFlag, out void* ppDefaultValue, out uint pcchDefaultValue, out uint pmdSetter, out uint pmdGetter, [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 14)]uint[] rmdOtherMethod, uint countMax)
public unsafe uint GetPropertyProps(uint prop, out uint pointerClass, [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 3)] char[] stringProperty, uint cchProperty, out uint pchProperty, out uint pdwPropFlags, out byte* ppvSig, out uint bytePointerSig, out uint pdwCPlusTypeFlag, out void* ppDefaultValue, out uint pcchDefaultValue, out uint pmdSetter, out uint pmdGetter, [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 14)]uint[] rmdOtherMethod, uint countMax)
{
throw new NotImplementedException();
}
Expand All @@ -373,7 +379,7 @@ public uint GetRVA(uint tk, out uint pulCodeRVA)
throw new NotImplementedException();
}

public Guid GetScopeProps(StringBuilder stringName, uint cchName, out uint pchName)
public Guid GetScopeProps([MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] char[] stringName, uint cchName, out uint pchName)
{
throw new NotImplementedException();
}
Expand All @@ -383,7 +389,7 @@ public unsafe uint GetTypeSpecFromToken(uint typespec, out byte* ppvSig)
throw new NotImplementedException();
}

public uint GetUserString(uint stk, StringBuilder stringString, uint cchString)
public uint GetUserString(uint stk, [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 2)] char[] stringString, uint cchString)
{
throw new NotImplementedException();
}
Expand All @@ -404,7 +410,7 @@ public void ResetEnum(uint handleEnum, uint ulongPos)
throw new NotImplementedException();
}

public uint ResolveTypeRef(uint tr, [In]ref Guid riid, [MarshalAs(UnmanagedType.Interface)]out object ppIScope)
public uint ResolveTypeRef(uint tr, in Guid riid, [MarshalAs(UnmanagedType.Interface)]out object ppIScope)
{
throw new NotImplementedException();
}
Expand Down
2 changes: 1 addition & 1 deletion src/Microsoft.DiaSymReader.PortablePdb/DocumentId.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public DocumentId(int id)

public bool Equals(DocumentId other) => Value == other.Value;
public override int GetHashCode() => Value.GetHashCode();
public override bool Equals(object obj) => obj is DocumentId id && Equals(id);
public override bool Equals(object? obj) => obj is DocumentId id && Equals(id);

private object GetDebuggerDisplay() => Value;
}
Expand Down
Loading