Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Propagate DefaultMemberAttribute to IndexerNameAttribute (#136)
* Propagate DefaultMemberAttribute to IndexerNameAttribute * Invert condition * Get, set test * Bit more fancy panty code
- Loading branch information
1 parent
987f9ce
commit 712b9ed
Showing
3 changed files
with
120 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
namespace PublicApiGenerator | ||
{ | ||
public static class AttributeNameBuilder | ||
{ | ||
public static string Get(string name) | ||
{ | ||
// ParamArrayAttribute cannot be augment with the attribute marker, it would trip up CodeDom | ||
return name == "System.ParamArrayAttribute" ? name : $"{name}{CodeNormalizer.AttributeMarker}"; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
using System.Runtime.CompilerServices; | ||
using PublicApiGeneratorTests.Examples; | ||
using Xunit; | ||
|
||
namespace PublicApiGeneratorTests | ||
{ | ||
public class Indexer_properties : ApiGeneratorTestsBase | ||
{ | ||
[Fact] | ||
public void Should_output_indexer() | ||
{ | ||
AssertPublicApi<ClassWithIndexer>( | ||
@"namespace PublicApiGeneratorTests.Examples | ||
{ | ||
public class ClassWithIndexer | ||
{ | ||
public ClassWithIndexer() { } | ||
public int this[int x] { get; } | ||
} | ||
}"); | ||
} | ||
|
||
[Fact] | ||
public void Should_output_named_indexer() | ||
{ | ||
AssertPublicApi<ClassWithNamedIndexer>( | ||
@"namespace PublicApiGeneratorTests.Examples | ||
{ | ||
public class ClassWithNamedIndexer | ||
{ | ||
public ClassWithNamedIndexer() { } | ||
[System.Runtime.CompilerServices.IndexerName(""Bar"")] | ||
public int this[int x] { get; } | ||
} | ||
}"); | ||
} | ||
|
||
[Fact] | ||
public void Should_output_named_indexer_with_getset() | ||
{ | ||
AssertPublicApi<ClassWithNamedIndexerGetSet>( | ||
@"namespace PublicApiGeneratorTests.Examples | ||
{ | ||
public class ClassWithNamedIndexerGetSet | ||
{ | ||
public ClassWithNamedIndexerGetSet() { } | ||
[System.Runtime.CompilerServices.IndexerName(""Bar"")] | ||
public int this[int x] { get; set; } | ||
} | ||
}"); | ||
} | ||
} | ||
|
||
|
||
// ReSharper disable ClassNeverInstantiated.Global | ||
// ReSharper disable UnusedMember.Global | ||
// ReSharper disable ValueParameterNotUsed | ||
namespace Examples | ||
{ | ||
public class ClassWithIndexer | ||
{ | ||
public int this[int x] => x; | ||
} | ||
|
||
public class ClassWithNamedIndexer | ||
{ | ||
[IndexerName("Bar")] | ||
public int this[int x] => x; | ||
} | ||
|
||
public class ClassWithNamedIndexerGetSet | ||
{ | ||
private int y; | ||
|
||
[IndexerName("Bar")] | ||
public int this[int x] | ||
{ | ||
get => y; | ||
set => y = value; | ||
} | ||
} | ||
} | ||
// ReSharper restore ValueParameterNotUsed | ||
// ReSharper restore UnusedMember.Global | ||
// ReSharper restore ClassNeverInstantiated.Global | ||
} |