Skip to content

Commit

Permalink
Merge pull request #776 from microsoft/fix774
Browse files Browse the repository at this point in the history
Add IPicture test and fix the failure
  • Loading branch information
AArnott authored Nov 15, 2022
2 parents 8b9fa8b + 14505fb commit f3eef4e
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
23 changes: 21 additions & 2 deletions src/Microsoft.Windows.CsWin32/Generator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4021,14 +4021,23 @@ private ISet<string> GetDeclarableProperties(IEnumerable<MethodDefinition> metho
badProperty |= !allowNonConsecutiveAccessors && priorPropertyData.Index != rowIndex - 1;
if (badProperty)
{
badProperties.Add(propertyName.Identifier.ValueText);
goodProperties.Remove(propertyName.Identifier.ValueText);
ReportBadProperty();
continue;
}
}

goodProperties[propertyName.Identifier.ValueText] = (propertyType, rowIndex);
}
else if (propertyName is not null)
{
ReportBadProperty();
}

void ReportBadProperty()
{
badProperties.Add(propertyName.Identifier.ValueText);
goodProperties.Remove(propertyName.Identifier.ValueText);
}
}

return goodProperties.Count == 0 ? ImmutableHashSet<string>.Empty : new HashSet<string>(goodProperties.Keys, StringComparer.Ordinal);
Expand All @@ -4039,8 +4048,18 @@ private bool TryGetPropertyAccessorInfo(MethodDefinition methodDefinition, [NotN
propertyName = null;
accessorKind = null;
propertyType = null;

if ((methodDefinition.Attributes & MethodAttributes.SpecialName) != MethodAttributes.SpecialName)
{
// Sometimes another method actually *does* qualify as a property accessor, which would have this method as another accessor if it qualified.
// But since this doesn't qualify, produce the property name that should be disqualified as a whole since C# doesn't like seeing property X and method set_X as seperate declarations.
string disqualifiedMethodName = this.Reader.GetString(methodDefinition.Name);
int index = disqualifiedMethodName.IndexOf('_');
if (index > 0)
{
propertyName = IdentifierName(disqualifiedMethodName.Substring(index + 1));
}

return false;
}

Expand Down
13 changes: 13 additions & 0 deletions test/Microsoft.Windows.CsWin32.Tests/GeneratorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -632,6 +632,19 @@ public void COMPropertiesAreGeneratedAsStructProperties_NonConsecutiveAccessors(
Assert.NotEmpty(structSyntax.Members.OfType<MethodDeclarationSyntax>().Where(m => m.Identifier.ValueText == "put_ClassName"));
}

/// <summary>
/// Verifies that IPicture can be generated.
/// It is a special case because of <see href="https://github.com/microsoft/win32metadata/issues/1367">this metadata bug</see>.
/// </summary>
[Fact]
public void COMPropertiesAreGeneratedAsStructProperties_NonConsecutiveAccessors_IPicture()
{
this.generator = this.CreateGenerator(DefaultTestGeneratorOptions with { AllowMarshaling = false });
Assert.True(this.generator.TryGenerate("IPicture", CancellationToken.None));
this.CollectGeneratedCode(this.generator);
this.AssertNoDiagnostics();
}

[Theory, PairwiseData]
public void COMPropertiesAreGeneratedAsMethodsWhenTheirReturnTypesDiffer([CombinatorialValues(0, 1, 2)] int marshaling)
{
Expand Down

0 comments on commit f3eef4e

Please sign in to comment.