Skip to content

Commit a6261f8

Browse files
authored
Remove link attribute and use a comment instead (#248)
1 parent 312f5f0 commit a6261f8

File tree

94 files changed

+320
-312
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

94 files changed

+320
-312
lines changed

contributing.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ using Link = System.ComponentModel.DescriptionAttribute;
160160
/// The specification for module initializers in the .NET runtime can be found here:
161161
/// https://github.com/dotnet/runtime/blob/master/docs/design/specs/Ecma-335-Augments.md#module-initializer
162162
/// </remarks>
163-
[Link("https://learn.microsoft.com/en-us/dotnet/api/system.runtime.compilerservices.moduleinitializerattribute")]
163+
//Link: https://learn.microsoft.com/en-us/dotnet/api/system.runtime.compilerservices.moduleinitializerattribute
164164
[ExcludeFromCodeCoverage]
165165
[DebuggerNonUserCode]
166166
[AttributeUsage(
@@ -216,7 +216,7 @@ static partial class Polyfill
216216
/// <returns>A <see cref="Task"/> that represents the asynchronous flush operation.</returns>
217217
/// <exception cref="ObjectDisposedException">The text writer is disposed.</exception>
218218
/// <exception cref="InvalidOperationException">The writer is currently in use by a previous write operation.</exception>
219-
[Link("https://learn.microsoft.com/en-us/dotnet/api/system.io.textwriter.flushasync#system-io-textwriter-flushasync(system-threading-cancellationtoken)")]
219+
//Link: https://learn.microsoft.com/en-us/dotnet/api/system.io.textwriter.flushasync#system-io-textwriter-flushasync(system-threading-cancellationtoken)
220220
public static Task FlushAsync(this TextWriter target, CancellationToken cancellationToken)
221221
{
222222
if (cancellationToken.IsCancellationRequested)
@@ -236,7 +236,7 @@ static partial class Polyfill
236236
/// StringBuilder.GetChunks() method to avoid creating the intermediate string
237237
/// </summary>
238238
/// <param name="value">The string (as a StringBuilder) to write to the stream</param>
239-
[Link("https://learn.microsoft.com/en-us/dotnet/api/system.io.textwriter.write#system-io-textwriter-write(system-text-stringbuilder)")]
239+
//Link: https://learn.microsoft.com/en-us/dotnet/api/system.io.textwriter.write#system-io-textwriter-write(system-text-stringbuilder)
240240
public static void Write(this TextWriter target, StringBuilder? value)
241241
{
242242
if (value == null)
@@ -260,7 +260,7 @@ static partial class Polyfill
260260
/// </summary>
261261
/// <param name="value">The string (as a StringBuilder) to write to the stream</param>
262262
/// <param name="cancellationToken">The token to monitor for cancellation requests.</param>
263-
[Link("https://learn.microsoft.com/en-us/dotnet/api/system.io.textwriter.writeasync#system-io-textwriter-writeasync(system-readonlymemory((system-char))-system-threading-cancellationtoken)")]
263+
//Link: https://learn.microsoft.com/en-us/dotnet/api/system.io.textwriter.writeasync#system-io-textwriter-writeasync(system-readonlymemory((system-char))-system-threading-cancellationtoken)
264264
public static Task WriteAsync(this TextWriter target, StringBuilder? value, CancellationToken cancellationToken = default)
265265
{
266266
if (cancellationToken.IsCancellationRequested)
@@ -302,7 +302,7 @@ static partial class Polyfill
302302
/// The default value is <see cref="CancellationToken.None"/>.
303303
/// </param>
304304
/// <returns>A task that represents the asynchronous write operation.</returns>
305-
[Link("https://learn.microsoft.com/en-us/dotnet/api/system.io.textwriter.writeasync#system-io-textwriter-writeasync(system-readonlymemory((system-char))-system-threading-cancellationtoken)")]
305+
//Link: https://learn.microsoft.com/en-us/dotnet/api/system.io.textwriter.writeasync#system-io-textwriter-writeasync(system-readonlymemory((system-char))-system-threading-cancellationtoken)
306306
public static ValueTask WriteAsync(
307307
this TextWriter target,
308308
ReadOnlyMemory<char> buffer,
@@ -330,7 +330,7 @@ static partial class Polyfill
330330
/// The default value is <see cref="CancellationToken.None"/>.
331331
/// </param>
332332
/// <returns>A task that represents the asynchronous write operation.</returns>
333-
[Link("https://learn.microsoft.com/en-us/dotnet/api/system.io.textwriter.writelineasync#system-io-textwriter-writelineasync(system-readonlymemory((system-char))-system-threading-cancellationtoken)")]
333+
//Link: https://learn.microsoft.com/en-us/dotnet/api/system.io.textwriter.writelineasync#system-io-textwriter-writelineasync(system-readonlymemory((system-char))-system-threading-cancellationtoken)
334334
public static ValueTask WriteLineAsync(
335335
this TextWriter target,
336336
ReadOnlyMemory<char> buffer,
@@ -355,7 +355,7 @@ static partial class Polyfill
355355
/// Writes a character span to the text stream.
356356
/// </summary>
357357
/// <param name="buffer">The character span to write.</param>
358-
[Link("https://learn.microsoft.com/en-us/dotnet/api/system.io.textwriter.write#system-io-textwriter-write(system-readonlyspan((system-char)))")]
358+
//Link: https://learn.microsoft.com/en-us/dotnet/api/system.io.textwriter.write#system-io-textwriter-write(system-readonlyspan((system-char)))
359359
public static void Write(
360360
this TextWriter target,
361361
ReadOnlySpan<char> buffer)
@@ -378,7 +378,7 @@ static partial class Polyfill
378378
/// Writes the text representation of a character span to the text stream, followed by a line terminator.
379379
/// </summary>
380380
/// <param name="buffer">The char span value to write to the text stream.</param>
381-
[Link("https://learn.microsoft.com/en-us/dotnet/api/system.io.textwriter.writeline#system-io-textwriter-writeline(system-readonlyspan((system-char)))")]
381+
//Link: https://learn.microsoft.com/en-us/dotnet/api/system.io.textwriter.writeline#system-io-textwriter-writeline(system-readonlyspan((system-char)))
382382
public static void WriteLine(
383383
this TextWriter target,
384384
ReadOnlySpan<char> buffer)

readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -478,7 +478,7 @@ The class `Polyfill` includes the following extension methods:
478478

479479
#### ConcurrentBag<T>
480480

481-
* `void Clear<T>(ConcurrentBag<T>)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.collections.concurrent.concurrentbag-1.clear)
481+
* `void Clear<T>()` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.collections.concurrent.concurrentbag-1.clear)
482482

483483

484484
#### ConcurrentDictionary<TKey, TValue>

src/ApiBuilderTests/BuildApiTest.cs

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
using Microsoft.CodeAnalysis;
2+
13
[TestFixture]
24
class BuildApiTest
35
{
@@ -204,16 +206,22 @@ static string BuildParameters(MethodDeclarationSyntax method)
204206

205207
static bool TryGetReference(MethodDeclarationSyntax method, [NotNullWhen(true)] out string? reference)
206208
{
207-
var descriptionAttribute = method.Attributes()
208-
.SingleOrDefault(_ => _.Name.ToString() == "Link");
209-
if (descriptionAttribute == null)
209+
var syntaxTrivia = method.GetLeadingTrivia();
210+
foreach (var trivia in syntaxTrivia)
210211
{
211-
reference = null;
212-
return false;
212+
if (trivia.IsKind(SyntaxKind.SingleLineCommentTrivia))
213+
{
214+
var comment = trivia.ToString();
215+
if (comment.StartsWith("//Link: "))
216+
{
217+
reference = comment.Replace("//Link: ", string.Empty);
218+
return true;
219+
}
220+
}
213221
}
214222

215-
reference = descriptionAttribute.ArgumentList!.Arguments.Single().Value().Trim('"');
216-
return true;
223+
reference = null;
224+
return false;
217225
}
218226

219227

src/Polyfill/CallerArgumentExpressionAttribute.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ namespace System.Runtime.CompilerServices;
1515
[ExcludeFromCodeCoverage]
1616
[DebuggerNonUserCode]
1717
[AttributeUsage(AttributeTargets.Parameter)]
18-
[Link("https://learn.microsoft.com/en-us/dotnet/api/system.runtime.compilerservices.callerargumentexpressionattribute")]
18+
//Link: https://learn.microsoft.com/en-us/dotnet/api/system.runtime.compilerservices.callerargumentexpressionattribute
1919
#if PolyPublic
2020
public
2121
#endif

src/Polyfill/CollectionBuilderAttribute.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ namespace System.Runtime.CompilerServices;
1212
[ExcludeFromCodeCoverage]
1313
[DebuggerNonUserCode]
1414
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Interface, Inherited = false)]
15-
[Link("https://learn.microsoft.com/en-us/dotnet/api/system.runtime.compilerservices.collectionbuilderattribute")]
15+
//Link: https://learn.microsoft.com/en-us/dotnet/api/system.runtime.compilerservices.collectionbuilderattribute
1616
#if PolyPublic
1717
public
1818
#endif

src/Polyfill/CompilerFeatureRequiredAttribute.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ namespace System.Runtime.CompilerServices;
1818
validOn: AttributeTargets.All,
1919
AllowMultiple = true,
2020
Inherited = false)]
21-
[Link("https://learn.microsoft.com/en-us/dotnet/api/system.runtime.compilerservices.compilerfeaturerequiredattribute")]
21+
//Link: https://learn.microsoft.com/en-us/dotnet/api/system.runtime.compilerservices.compilerfeaturerequiredattribute
2222
#if PolyPublic
2323
public
2424
#endif

src/Polyfill/ConstantExpectedAttribute.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ namespace System.Diagnostics.CodeAnalysis;
1818
[ExcludeFromCodeCoverage]
1919
[DebuggerNonUserCode]
2020
[AttributeUsage(AttributeTargets.Parameter, Inherited = false)]
21-
[Link("https://learn.microsoft.com/en-us/dotnet/api/system.diagnostics.codeanalysis.constantexpectedattribute")]
21+
//Link: https://learn.microsoft.com/en-us/dotnet/api/system.diagnostics.codeanalysis.constantexpectedattribute
2222
#if PolyPublic
2323
public
2424
#endif

src/Polyfill/DateTimeOffsetPolyfill.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ static class DateTimeOffsetPolyfill
2121
/// <summary>
2222
/// Tries to parse a string into a value.
2323
/// </summary>
24-
[Link("https://learn.microsoft.com/en-us/dotnet/api/system.datetimeoffset.tryparse#system-datetimeoffset-tryparse(system-string-system-iformatprovider-system-datetimeoffset@)")]
24+
//Link: https://learn.microsoft.com/en-us/dotnet/api/system.datetimeoffset.tryparse#system-datetimeoffset-tryparse(system-string-system-iformatprovider-system-datetimeoffset@)
2525
public static bool TryParse(string? target, IFormatProvider? provider, out DateTimeOffset result) =>
2626
#if NET7_0_OR_GREATER
2727
DateTimeOffset.TryParse(target, provider, out result);
@@ -34,7 +34,7 @@ public static bool TryParse(string? target, IFormatProvider? provider, out DateT
3434
/// <summary>
3535
/// Tries to parse a span of characters into a value.
3636
/// </summary>
37-
[Link("https://learn.microsoft.com/en-us/dotnet/api/system.datetimeoffset.tryparse#system-datetimeoffset-tryparse(system-readonlyspan((system-char))-system-iformatprovider-system-datetimeoffset@)")]
37+
//Link: https://learn.microsoft.com/en-us/dotnet/api/system.datetimeoffset.tryparse#system-datetimeoffset-tryparse(system-readonlyspan((system-char))-system-iformatprovider-system-datetimeoffset@)
3838
public static bool TryParse(ReadOnlySpan<char> target, IFormatProvider? provider, out DateTimeOffset result) =>
3939
#if NET8_0_OR_GREATER
4040
DateTimeOffset.TryParse(target, provider, out result);
@@ -45,7 +45,7 @@ public static bool TryParse(ReadOnlySpan<char> target, IFormatProvider? provider
4545
/// <summary>
4646
/// Tries to parse a span of characters into a value.
4747
/// </summary>
48-
[Link("https://learn.microsoft.com/en-us/dotnet/api/system.datetimeoffset.tryparse#system-datetimeoffset-tryparse(system-readonlyspan((system-char))-system-datetimeoffset@)")]
48+
//Link: https://learn.microsoft.com/en-us/dotnet/api/system.datetimeoffset.tryparse#system-datetimeoffset-tryparse(system-readonlyspan((system-char))-system-datetimeoffset@)
4949
public static bool TryParse(ReadOnlySpan<char> target, out DateTimeOffset result) =>
5050
#if NETSTANDARD2_1 || NETSTANDARD2_1_OR_GREATER || NET5_0_OR_GREATER
5151
DateTimeOffset.TryParse(target, out result);
@@ -56,7 +56,7 @@ public static bool TryParse(ReadOnlySpan<char> target, out DateTimeOffset result
5656
/// <summary>
5757
/// Tries to parse a span of characters into a value.
5858
/// </summary>
59-
[Link("https://learn.microsoft.com/en-us/dotnet/api/system.datetimeoffset.tryparse#system-datetimeoffset-tryparse(system-readonlyspan((system-char))-system-iformatprovider-system-globalization-datetimestyles-system-datetimeoffset@)")]
59+
//Link: https://learn.microsoft.com/en-us/dotnet/api/system.datetimeoffset.tryparse#system-datetimeoffset-tryparse(system-readonlyspan((system-char))-system-iformatprovider-system-globalization-datetimestyles-system-datetimeoffset@)
6060
public static bool TryParse(ReadOnlySpan<char> target, IFormatProvider? provider, DateTimeStyles styles, out DateTimeOffset result) =>
6161
#if NETSTANDARD2_1 || NETSTANDARD2_1_OR_GREATER || NET5_0_OR_GREATER
6262
DateTimeOffset.TryParse(target, provider, styles, out result);
@@ -67,7 +67,7 @@ public static bool TryParse(ReadOnlySpan<char> target, IFormatProvider? provider
6767
/// <summary>
6868
/// Tries to parse a span of characters into a value.
6969
/// </summary>
70-
[Link("https://learn.microsoft.com/en-us/dotnet/api/system.datetimeoffset.tryparseexact#system-datetimeoffset-tryparseexact(system-readonlyspan((system-char))-system-readonlyspan((system-char))-system-iformatprovider-system-globalization-datetimestyles-system-datetimeoffset@)")]
70+
//Link: https://learn.microsoft.com/en-us/dotnet/api/system.datetimeoffset.tryparseexact#system-datetimeoffset-tryparseexact(system-readonlyspan((system-char))-system-readonlyspan((system-char))-system-iformatprovider-system-globalization-datetimestyles-system-datetimeoffset@)
7171
public static bool TryParseExact(ReadOnlySpan<char> target, string format, IFormatProvider? provider, DateTimeStyles styles, out DateTimeOffset result) =>
7272
#if NETSTANDARD2_1 || NETSTANDARD2_1_OR_GREATER || NET5_0_OR_GREATER
7373
DateTimeOffset.TryParseExact(target, format, provider, styles, out result);
@@ -78,7 +78,7 @@ public static bool TryParseExact(ReadOnlySpan<char> target, string format, IForm
7878
/// <summary>
7979
/// Tries to parse a span of characters into a value.
8080
/// </summary>
81-
[Link("https://learn.microsoft.com/en-us/dotnet/api/system.datetimeoffset.tryparseexact#system-datetimeoffset-tryparseexact(system-readonlyspan((system-char))-system-readonlyspan((system-char))-system-iformatprovider-system-globalization-datetimestyles-system-datetimeoffset@)")]
81+
//Link: https://learn.microsoft.com/en-us/dotnet/api/system.datetimeoffset.tryparseexact#system-datetimeoffset-tryparseexact(system-readonlyspan((system-char))-system-readonlyspan((system-char))-system-iformatprovider-system-globalization-datetimestyles-system-datetimeoffset@)
8282
public static bool TryParseExact(ReadOnlySpan<char> target, ReadOnlySpan<char> format, IFormatProvider? provider, DateTimeStyles styles, out DateTimeOffset result) =>
8383
#if NETFRAMEWORK || NETSTANDARD2_0 || NETCOREAPP2_0
8484
DateTimeOffset.TryParseExact(target.ToString(), format.ToString(), provider, styles, out result);

src/Polyfill/DateTimePolyfill.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ static class DateTimePolyfill
1919
/// <summary>
2020
/// Tries to parse a string into a value.
2121
/// </summary>
22-
[Link("https://learn.microsoft.com/en-us/dotnet/api/system.datetime.tryparse#system-datetime-tryparse(system-string-system-iformatprovider-system-datetime@)")]
22+
//Link: https://learn.microsoft.com/en-us/dotnet/api/system.datetime.tryparse#system-datetime-tryparse(system-string-system-iformatprovider-system-datetime@)
2323
public static bool TryParse(string? target, IFormatProvider? provider, out DateTime result) =>
2424
#if NET7_0_OR_GREATER
2525
DateTime.TryParse(target, provider, out result);
@@ -32,7 +32,7 @@ public static bool TryParse(string? target, IFormatProvider? provider, out DateT
3232
/// <summary>
3333
/// Tries to parse a span of characters into a value.
3434
/// </summary>
35-
[Link("https://learn.microsoft.com/en-us/dotnet/api/system.datetime.tryparse#system-datetime-tryparse(system-readonlyspan((system-char))-system-iformatprovider-system-datetime@)")]
35+
//Link: https://learn.microsoft.com/en-us/dotnet/api/system.datetime.tryparse#system-datetime-tryparse(system-readonlyspan((system-char))-system-iformatprovider-system-datetime@)
3636
public static bool TryParse(ReadOnlySpan<char> target, IFormatProvider? provider, out DateTime result) =>
3737
#if NET8_0_OR_GREATER
3838
DateTime.TryParse(target, provider, out result);
@@ -43,7 +43,7 @@ public static bool TryParse(ReadOnlySpan<char> target, IFormatProvider? provider
4343
/// <summary>
4444
/// Tries to parse a span of characters into a value.
4545
/// </summary>
46-
[Link("https://learn.microsoft.com/en-us/dotnet/api/system.datetime.tryparse#system-datetime-tryparse(system-readonlyspan((system-char))-system-datetime@)")]
46+
//Link: https://learn.microsoft.com/en-us/dotnet/api/system.datetime.tryparse#system-datetime-tryparse(system-readonlyspan((system-char))-system-datetime@)
4747
public static bool TryParse(ReadOnlySpan<char> target, out DateTime result) =>
4848
#if NETSTANDARD2_1 || NETSTANDARD2_1_OR_GREATER || NET5_0_OR_GREATER
4949
DateTime.TryParse(target, out result);
@@ -54,7 +54,7 @@ public static bool TryParse(ReadOnlySpan<char> target, out DateTime result) =>
5454
/// <summary>
5555
/// Tries to parse a span of characters into a value.
5656
/// </summary>
57-
[Link("https://learn.microsoft.com/en-us/dotnet/api/system.datetime.tryparse#system-datetime-tryparse(system-readonlyspan((system-char))-system-iformatprovider-system-globalization-datetimestyles-system-datetime@)")]
57+
//Link: https://learn.microsoft.com/en-us/dotnet/api/system.datetime.tryparse#system-datetime-tryparse(system-readonlyspan((system-char))-system-iformatprovider-system-globalization-datetimestyles-system-datetime@)
5858
public static bool TryParse(ReadOnlySpan<char> target, IFormatProvider? provider, DateTimeStyles styles, out DateTime result) =>
5959
#if NETSTANDARD2_1 || NETSTANDARD2_1_OR_GREATER || NET5_0_OR_GREATER
6060
DateTime.TryParse(target, provider, styles, out result);
@@ -65,7 +65,7 @@ public static bool TryParse(ReadOnlySpan<char> target, IFormatProvider? provider
6565
/// <summary>
6666
/// Tries to parse a span of characters into a value.
6767
/// </summary>
68-
[Link("https://learn.microsoft.com/en-us/dotnet/api/system.datetime.tryparseexact#system-datetime-tryparseexact(system-readonlyspan((system-char))-system-readonlyspan((system-char))-system-iformatprovider-system-globalization-datetimestyles-system-datetime@)")]
68+
//Link: https://learn.microsoft.com/en-us/dotnet/api/system.datetime.tryparseexact#system-datetime-tryparseexact(system-readonlyspan((system-char))-system-readonlyspan((system-char))-system-iformatprovider-system-globalization-datetimestyles-system-datetime@)
6969
public static bool TryParseExact(ReadOnlySpan<char> target, string format, IFormatProvider? provider, DateTimeStyles style, out DateTime result) =>
7070
#if NETSTANDARD2_1 || NETSTANDARD2_1_OR_GREATER || NET5_0_OR_GREATER
7171
DateTime.TryParseExact(target, format, provider, style, out result);
@@ -76,7 +76,7 @@ public static bool TryParseExact(ReadOnlySpan<char> target, string format, IForm
7676
/// <summary>
7777
/// Tries to parse a span of characters into a value.
7878
/// </summary>
79-
[Link("https://learn.microsoft.com/en-us/dotnet/api/system.datetime.tryparseexact#system-datetime-tryparseexact(system-readonlyspan((system-char))-system-readonlyspan((system-char))-system-iformatprovider-system-globalization-datetimestyles-system-datetime@)")]
79+
//Link: https://learn.microsoft.com/en-us/dotnet/api/system.datetime.tryparseexact#system-datetime-tryparseexact(system-readonlyspan((system-char))-system-readonlyspan((system-char))-system-iformatprovider-system-globalization-datetimestyles-system-datetime@)
8080
public static bool TryParseExact(ReadOnlySpan<char> target, ReadOnlySpan<char> format, IFormatProvider? provider, DateTimeStyles styles, out DateTime result) =>
8181
#if NETFRAMEWORK || NETSTANDARD2_0 || NETCOREAPP2_0
8282
DateTime.TryParseExact(target.ToString(), format.ToString(), provider, styles, out result);

src/Polyfill/DisableRuntimeMarshallingAttribute.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ namespace System.Runtime.CompilerServices;
2929
[ExcludeFromCodeCoverage]
3030
[DebuggerNonUserCode]
3131
[AttributeUsage(AttributeTargets.Assembly)]
32-
[Link("https://learn.microsoft.com/en-us/dotnet/api/system.runtime.compilerservices.disableruntimemarshallingattribute")]
32+
//Link: https://learn.microsoft.com/en-us/dotnet/api/system.runtime.compilerservices.disableruntimemarshallingattribute
3333
#if PolyPublic
3434
public
3535
#endif

0 commit comments

Comments
 (0)