Skip to content
This repository was archived by the owner on Apr 8, 2019. It is now read-only.

Commit 24a4170

Browse files
authored
Merge pull request #25 from sharwell/fix-type-forwarded-properties
Only add getters and setters for type-forwarded properties to public API
2 parents dc2a045 + 44a80ba commit 24a4170

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

PublicApiAnalyzer/PublicApiAnalyzer.Test/ApiDesign/DeclarePublicAPIAnalyzerTests.cs

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -509,7 +509,7 @@ private void Method() { }
509509
}
510510

511511
[Fact]
512-
public async Task TypeForwardsAreProcessedAsync()
512+
public async Task TypeForwardsAreProcessed1Async()
513513
{
514514
var source = @"
515515
[assembly: System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.StringComparison))]
@@ -529,6 +529,34 @@ public async Task TypeForwardsAreProcessedAsync()
529529
await this.VerifyCSharpDiagnosticAsync(source, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
530530
}
531531

532+
[Fact]
533+
public async Task TypeForwardsAreProcessed2Async()
534+
{
535+
var source = @"
536+
[assembly: System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.StringComparer))]
537+
";
538+
this.shippedText = $@"
539+
System.StringComparer (forwarded, contained in mscorlib)
540+
static System.StringComparer.InvariantCulture.get -> System.StringComparer (forwarded, contained in mscorlib)
541+
static System.StringComparer.InvariantCultureIgnoreCase.get -> System.StringComparer (forwarded, contained in mscorlib)
542+
static System.StringComparer.CurrentCulture.get -> System.StringComparer (forwarded, contained in mscorlib)
543+
static System.StringComparer.CurrentCultureIgnoreCase.get -> System.StringComparer (forwarded, contained in mscorlib)
544+
static System.StringComparer.Ordinal.get -> System.StringComparer (forwarded, contained in mscorlib)
545+
static System.StringComparer.OrdinalIgnoreCase.get -> System.StringComparer (forwarded, contained in mscorlib)
546+
static System.StringComparer.Create(System.Globalization.CultureInfo culture, bool ignoreCase) -> System.StringComparer (forwarded, contained in mscorlib)
547+
System.StringComparer.Compare(object x, object y) -> int (forwarded, contained in mscorlib)
548+
System.StringComparer.Equals(object x, object y) -> bool (forwarded, contained in mscorlib)
549+
System.StringComparer.GetHashCode(object obj) -> int (forwarded, contained in mscorlib)
550+
abstract System.StringComparer.Compare(string x, string y) -> int (forwarded, contained in mscorlib)
551+
abstract System.StringComparer.Equals(string x, string y) -> bool (forwarded, contained in mscorlib)
552+
abstract System.StringComparer.GetHashCode(string obj) -> int (forwarded, contained in mscorlib)
553+
System.StringComparer.StringComparer() -> void (forwarded, contained in mscorlib)
554+
";
555+
this.unshippedText = $@"";
556+
557+
await this.VerifyCSharpDiagnosticAsync(source, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
558+
}
559+
532560
[Fact]
533561
public async Task TestAvoidMultipleOverloadsWithOptionalParametersAsync()
534562
{

PublicApiAnalyzer/PublicApiAnalyzer/ApiDesign/DeclarePublicAPIAnalyzer.Impl.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -519,6 +519,13 @@ private bool IsPublicAPI(ISymbol symbol)
519519
return false;
520520
}
521521

522+
// We don't consider properties to be public APIs. Instead, property getters and setters
523+
// (which are IMethodSymbols) are considered as public APIs.
524+
if (symbol is IPropertySymbol)
525+
{
526+
return false;
527+
}
528+
522529
return this.IsPublicApiCore(symbol);
523530
}
524531

0 commit comments

Comments
 (0)