diff --git a/api_list.include.md b/api_list.include.md index f078101c..0582421f 100644 --- a/api_list.include.md +++ b/api_list.include.md @@ -1,19 +1,21 @@ -### Boolean +### Extension methods + +#### Boolean * `Boolean TryFormat(Span, Int32&)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.boolean.tryformat) -### Byte +#### Byte * `Boolean TryFormat(Span, Int32&, ReadOnlySpan, IFormatProvider)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.byte.tryformat) -### Dictionary +#### Dictionary * `Boolean Remove(TKey, TValue&)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.collections.generic.dictionary-2.remove) -### IEnumerable +#### IEnumerable * `IEnumerable Chunk(Int32)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.linq.enumerable.chunk) * `IEnumerable Except(TSource)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.linq.enumerable.except?view=net-8.0#system-linq-enumerable-except-1(system-collections-generic-ienumerable((-0))-system-collections-generic-ienumerable((-0)))) @@ -28,18 +30,18 @@ * `HashSet ToHashSet(IEqualityComparer)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.linq.enumerable.tohashset#system-linq-enumerable-tohashset-1(system-collections-generic-ienumerable((-0))-system-collections-generic-iequalitycomparer((-0)))) -### IReadOnlyDictionary +#### IReadOnlyDictionary * `TValue GetValueOrDefault(TKey)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.collections.generic.collectionextensions.getvalueordefault) * `TValue GetValueOrDefault(TKey, TValue)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.collections.generic.collectionextensions.getvalueordefault#system-collections-generic-collectionextensions-getvalueordefault-2(system-collections-generic-ireadonlydictionary((-0-1))-0-1)) -### KeyValuePair +#### KeyValuePair * `Void Deconstruct(TKey&, TValue&)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.collections.generic.keyvaluepair-2.deconstruct) -### DateTime +#### DateTime * `DateTime AddMicroseconds(Double)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.datetime.addmicroseconds) * `Int32 Microsecond()` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.datetime.microsecond) @@ -47,7 +49,7 @@ * `Boolean TryFormat(Span, Int32&, ReadOnlySpan, IFormatProvider)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.datetime.tryformat) -### DateTimeOffset +#### DateTimeOffset * `DateTimeOffset AddMicroseconds(Double)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.datetimeoffset.addmicroseconds) * `Int32 Microsecond()` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.datetimeoffset.microsecond) @@ -55,56 +57,56 @@ * `Boolean TryFormat(Span, Int32&, ReadOnlySpan, IFormatProvider)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.datetimeoffset.tryformat) -### Decimal +#### Decimal * `Boolean TryFormat(Span, Int32&, ReadOnlySpan, IFormatProvider)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.decimal.tryformat) -### Process +#### Process * `Task WaitForExitAsync(CancellationToken)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.diagnostics.process.waitforexitasync) -### Double +#### Double * `Boolean TryFormat(Span, Int32&, ReadOnlySpan, IFormatProvider)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.double.tryformat) -### Guid +#### Guid * `Boolean TryFormat(Span, Int32&, ReadOnlySpan)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.guid.tryformat#system-guid-tryformat(system-span((system-char))-system-int32@-system-readonlyspan((system-char)))) -### Int16 +#### Int16 * `Boolean TryFormat(Span, Int32&, ReadOnlySpan, IFormatProvider)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.int16.tryformat) -### Int32 +#### Int32 * `Boolean TryFormat(Span, Int32&, ReadOnlySpan, IFormatProvider)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.int32.tryformat) -### Int64 +#### Int64 * `Boolean TryFormat(Span, Int32&, ReadOnlySpan, IFormatProvider)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.int64.tryformat) -### Stream +#### Stream * `Task CopyToAsync(Stream, CancellationToken)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.io.stream.copytoasync#system-io-stream-copytoasync(system-io-stream-system-threading-cancellationtoken)) * `ValueTask ReadAsync(Memory, CancellationToken)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.io.stream.readasync#system-io-stream-readasync(system-memory((system-byte))-system-threading-cancellationtoken)) * `ValueTask WriteAsync(ReadOnlyMemory, CancellationToken)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.io.stream.writeasync#system-io-stream-writeasync(system-readonlymemory((system-byte))-system-threading-cancellationtoken)) -### TextReader +#### TextReader * `ValueTask ReadAsync(Memory, CancellationToken)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.io.textreader.readasync#system-io-textreader-readasync(system-memory((system-char))-system-threading-cancellationtoken)) * `Task ReadLineAsync(CancellationToken)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.io.textreader.readtoendasync#system-io-textreader-readlineasync(system-threading-cancellationtoken)) * `Task ReadToEndAsync(CancellationToken)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.io.textreader.readtoendasync#system-io-textreader-readtoendasync(system-threading-cancellationtoken)) -### TextWriter +#### TextWriter * `Void Write(ReadOnlySpan)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.io.textwriter.write#system-io-textwriter-write(system-readonlyspan((system-char)))) * `ValueTask WriteAsync(ReadOnlyMemory, CancellationToken)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.io.textwriter.writeasync#system-io-textwriter-writeasync(system-readonlymemory((system-char))-system-threading-cancellationtoken)) @@ -112,7 +114,7 @@ * `ValueTask WriteLineAsync(ReadOnlyMemory, CancellationToken)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.io.textwriter.writelineasync#system-io-textwriter-writelineasync(system-readonlymemory((system-char))-system-threading-cancellationtoken)) -### HttpClient +#### HttpClient * `Task GetByteArrayAsync(String, CancellationToken)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.net.http.httpclient.getbytearrayasync#system-net-http-httpclient-getbytearrayasync(system-string-system-threading-cancellationtoken)) * `Task GetByteArrayAsync(Uri, CancellationToken)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.net.http.httpclient.getbytearrayasync#system-net-http-httpclient-getbytearrayasync(system-uri-system-threading-cancellationtoken)) @@ -122,40 +124,40 @@ * `Task GetStringAsync(Uri, CancellationToken)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.net.http.httpclient.getstringasync#system-net-http-httpclient-getstringasync(system-uri-system-threading-cancellationtoken)) -### HttpContent +#### HttpContent * `Task ReadAsByteArrayAsync(CancellationToken)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.net.http.httpcontent.readasbytearrayasync#system-net-http-httpcontent-readasbytearrayasync(system-threading-cancellationtoken)) * `Task ReadAsStreamAsync(CancellationToken)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.net.http.httpcontent.readasstreamasync#system-net-http-httpcontent-readasstreamasync(system-threading-cancellationtoken)) * `Task ReadAsStringAsync(CancellationToken)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.net.http.httpcontent.readasstringasync#system-net-http-httpcontent-readasstringasync(system-threading-cancellationtoken)) -### ReadOnlySpan +#### ReadOnlySpan * `Boolean EndsWith(String, StringComparison)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.endswith#system-memoryextensions-endswith-1(system-readonlyspan((-0))-system-readonlyspan((-0)))) * `Boolean SequenceEqual(String)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.sequenceequal#system-memoryextensions-sequenceequal-1(system-readonlyspan((-0))-system-readonlyspan((-0)))) * `Boolean StartsWith(String, StringComparison)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.startswith#system-memoryextensions-startswith-1(system-readonlyspan((-0))-system-readonlyspan((-0)))) -### ReadOnlySpan +#### ReadOnlySpan * `Boolean Contains(T)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.contains#system-memoryextensions-contains-1(system-readonlyspan((-0))-0)) -### Reflection.EventInfo +#### Reflection.EventInfo * `Reflection.NullabilityState GetNullability()` * `Reflection.NullabilityInfo GetNullabilityInfo()` * `Boolean IsNullable()` -### Reflection.FieldInfo +#### Reflection.FieldInfo * `Reflection.NullabilityState GetNullability()` * `Reflection.NullabilityInfo GetNullabilityInfo()` * `Boolean IsNullable()` -### Reflection.MemberInfo +#### Reflection.MemberInfo * `Reflection.NullabilityState GetNullability()` * `Reflection.NullabilityInfo GetNullabilityInfo()` @@ -163,43 +165,43 @@ * `Boolean IsNullable()` -### Reflection.ParameterInfo +#### Reflection.ParameterInfo * `Reflection.NullabilityState GetNullability()` * `Reflection.NullabilityInfo GetNullabilityInfo()` * `Boolean IsNullable()` -### Reflection.PropertyInfo +#### Reflection.PropertyInfo * `Reflection.NullabilityState GetNullability()` * `Reflection.NullabilityInfo GetNullabilityInfo()` * `Boolean IsNullable()` -### SByte +#### SByte * `Boolean TryFormat(Span, Int32&, ReadOnlySpan, IFormatProvider)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.sbyte.tryformat) -### Single +#### Single * `Boolean TryFormat(Span, Int32&, ReadOnlySpan, IFormatProvider)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.single.tryformat) -### Span +#### Span * `Boolean EndsWith(String)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.endswith#system-memoryextensions-endswith-1(system-span((-0))-system-readonlyspan((-0)))) * `Boolean SequenceEqual(String)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.sequenceequal#system-memoryextensions-sequenceequal-1(system-span((-0))-system-readonlyspan((-0)))) * `Boolean StartsWith(String)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.startswith#system-memoryextensions-startswith-1(system-span((-0))-system-readonlyspan((-0)))) -### Span +#### Span * `Boolean Contains(T)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.contains#system-memoryextensions-contains-1(system-span((-0))-0)) -### String +#### String * `Boolean Contains(String, StringComparison)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.string.contains#system-string-contains(system-string-system-stringcomparison)) * `Boolean Contains(Char)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.string.contains#system-string-contains(system-char)) @@ -212,13 +214,13 @@ * `Boolean TryCopyTo(Span)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.string.trycopyto) -### RegularExpressions.Regex +#### RegularExpressions.Regex * `Boolean IsMatch(ReadOnlySpan, Int32)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.text.regularexpressions.regex.ismatch#system-text-regularexpressions-regex-ismatch(system-readonlyspan((system-char))-system-int32)) * `Boolean IsMatch(ReadOnlySpan)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.text.regularexpressions.regex.ismatch#system-text-regularexpressions-regex-ismatch(system-readonlyspan((system-char)))) -### StringBuilder +#### StringBuilder * `StringBuilder Append(ReadOnlySpan)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.text.stringbuilder.append#system-text-stringbuilder-append(system-readonlyspan((system-char)))) * `StringBuilder Append(AppendInterpolatedStringHandler&)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.text.stringbuilder.append#system-text-stringbuilder-append(system-text-stringbuilder-appendinterpolatedstringhandler@)) @@ -235,56 +237,71 @@ * `Boolean Equals(ReadOnlySpan)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.text.stringbuilder.equals#system-text-stringbuilder-equals(system-readonlyspan((system-char)))) -### CancellationToken +#### CancellationToken * `CancellationTokenRegistration Register(Action, Object)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.threading.cancellationtoken.register#system-threading-cancellationtoken-register(system-action((system-object-system-threading-cancellationtoken))-system-object)) * `CancellationTokenRegistration UnsafeRegister(Action, Object)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.threading.cancellationtoken.unsaferegister#system-threading-cancellationtoken-unsaferegister(system-action((system-object))-system-object)) * `CancellationTokenRegistration UnsafeRegister(Action, Object)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.threading.cancellationtoken.unsaferegister#system-threading-cancellationtoken-unsaferegister(system-action((system-object-system-threading-cancellationtoken))-system-object)) -### CancellationTokenSource +#### CancellationTokenSource * `Task CancelAsync()` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.threading.cancellationtokensource.cancelasync) -### Task +#### Task * `Task WaitAsync(CancellationToken)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.threading.tasks.task.waitasync#system-threading-tasks-task-waitasync(system-threading-cancellationtoken)) * `Task WaitAsync(TimeSpan)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.threading.tasks.task.waitasync#system-threading-tasks-task-waitasync(system-timespan)) * `Task WaitAsync(TimeSpan, CancellationToken)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.threading.tasks.task.waitasync#system-threading-tasks-task-waitasync(system-timespan-system-threading-cancellationtoken)) -### Task +#### Task * `Task WaitAsync(CancellationToken)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.threading.tasks.task.waitasync#system-threading-tasks-task-waitasync(system-threading-cancellationtoken)) * `Task WaitAsync(TimeSpan)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.threading.tasks.task-1.waitasync#system-threading-tasks-task-1-waitasync(system-timespan)) * `Task WaitAsync(TimeSpan, CancellationToken)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.threading.tasks.task-1.waitasync#system-threading-tasks-task-1-waitasync(system-timespan-system-threading-cancellationtoken)) -### TimeSpan +#### TimeSpan * `Int32 Microseconds()` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.timespan.microseconds) * `Int32 Nanoseconds()` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.timespan.nanoseconds) * `Boolean TryFormat(Span, Int32&, ReadOnlySpan, IFormatProvider)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.timespan.tryformat#system-timespan-tryformat(system-span((system-byte))-system-int32@-system-readonlyspan((system-char))-system-iformatprovider)) -### Type +#### Type * `Boolean IsGenericMethodParameter()` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.type.isgenericmethodparameter) -### UInt16 +#### UInt16 * `Boolean TryFormat(Span, Int32&, ReadOnlySpan, IFormatProvider)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.uint16.tryformat) -### UInt32 +#### UInt32 * `Boolean TryFormat(Span, Int32&, ReadOnlySpan, IFormatProvider)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.uint32.tryformat) -### UInt64 +#### UInt64 * `Boolean TryFormat(Span, Int32&, ReadOnlySpan, IFormatProvider)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.uint64.tryformat) +### Static helpers + +#### EnumPolyfill + + * `String[] GetNames()` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.enum.getnames) + * `TEnum[] GetValues()` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.enum.getvalues) + + +#### RegexPolyfill + + * `Boolean IsMatch(String, RegularExpressions.RegexOptions, TimeSpan)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.text.regularexpressions.regex.ismatch#system-text-regularexpressions-regex-ismatch(system-readonlyspan((system-char))-system-string-system-text-regularexpressions-regexoptions-system-timespan)) + * `Boolean IsMatch(String, RegularExpressions.RegexOptions)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.text.regularexpressions.regex.ismatch#system-text-regularexpressions-regex-ismatch(system-readonlyspan((system-char))-system-string-system-text-regularexpressions-regexoptions)) + * `Boolean IsMatch(String)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.text.regularexpressions.regex.ismatch#system-text-regularexpressions-regex-ismatch(system-readonlyspan((system-char))-system-string)) + + diff --git a/readme.md b/readme.md index c80e2342..31528d5a 100644 --- a/readme.md +++ b/readme.md @@ -354,22 +354,24 @@ The class `Polyfill` includes the following extension methods: > The methods using `AppendInterpolatedStringHandler` parameter are not extensions because the compiler prefers to use the overload with `string` parameter instead. -### Boolean +### Extension methods + +#### Boolean * `Boolean TryFormat(Span, Int32&)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.boolean.tryformat) -### Byte +#### Byte * `Boolean TryFormat(Span, Int32&, ReadOnlySpan, IFormatProvider)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.byte.tryformat) -### Dictionary +#### Dictionary * `Boolean Remove(TKey, TValue&)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.collections.generic.dictionary-2.remove) -### IEnumerable +#### IEnumerable * `IEnumerable Chunk(Int32)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.linq.enumerable.chunk) * `IEnumerable Except(TSource)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.linq.enumerable.except?view=net-8.0#system-linq-enumerable-except-1(system-collections-generic-ienumerable((-0))-system-collections-generic-ienumerable((-0)))) @@ -384,18 +386,18 @@ The class `Polyfill` includes the following extension methods: * `HashSet ToHashSet(IEqualityComparer)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.linq.enumerable.tohashset#system-linq-enumerable-tohashset-1(system-collections-generic-ienumerable((-0))-system-collections-generic-iequalitycomparer((-0)))) -### IReadOnlyDictionary +#### IReadOnlyDictionary * `TValue GetValueOrDefault(TKey)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.collections.generic.collectionextensions.getvalueordefault) * `TValue GetValueOrDefault(TKey, TValue)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.collections.generic.collectionextensions.getvalueordefault#system-collections-generic-collectionextensions-getvalueordefault-2(system-collections-generic-ireadonlydictionary((-0-1))-0-1)) -### KeyValuePair +#### KeyValuePair * `Void Deconstruct(TKey&, TValue&)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.collections.generic.keyvaluepair-2.deconstruct) -### DateTime +#### DateTime * `DateTime AddMicroseconds(Double)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.datetime.addmicroseconds) * `Int32 Microsecond()` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.datetime.microsecond) @@ -403,7 +405,7 @@ The class `Polyfill` includes the following extension methods: * `Boolean TryFormat(Span, Int32&, ReadOnlySpan, IFormatProvider)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.datetime.tryformat) -### DateTimeOffset +#### DateTimeOffset * `DateTimeOffset AddMicroseconds(Double)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.datetimeoffset.addmicroseconds) * `Int32 Microsecond()` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.datetimeoffset.microsecond) @@ -411,56 +413,56 @@ The class `Polyfill` includes the following extension methods: * `Boolean TryFormat(Span, Int32&, ReadOnlySpan, IFormatProvider)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.datetimeoffset.tryformat) -### Decimal +#### Decimal * `Boolean TryFormat(Span, Int32&, ReadOnlySpan, IFormatProvider)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.decimal.tryformat) -### Process +#### Process * `Task WaitForExitAsync(CancellationToken)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.diagnostics.process.waitforexitasync) -### Double +#### Double * `Boolean TryFormat(Span, Int32&, ReadOnlySpan, IFormatProvider)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.double.tryformat) -### Guid +#### Guid * `Boolean TryFormat(Span, Int32&, ReadOnlySpan)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.guid.tryformat#system-guid-tryformat(system-span((system-char))-system-int32@-system-readonlyspan((system-char)))) -### Int16 +#### Int16 * `Boolean TryFormat(Span, Int32&, ReadOnlySpan, IFormatProvider)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.int16.tryformat) -### Int32 +#### Int32 * `Boolean TryFormat(Span, Int32&, ReadOnlySpan, IFormatProvider)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.int32.tryformat) -### Int64 +#### Int64 * `Boolean TryFormat(Span, Int32&, ReadOnlySpan, IFormatProvider)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.int64.tryformat) -### Stream +#### Stream * `Task CopyToAsync(Stream, CancellationToken)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.io.stream.copytoasync#system-io-stream-copytoasync(system-io-stream-system-threading-cancellationtoken)) * `ValueTask ReadAsync(Memory, CancellationToken)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.io.stream.readasync#system-io-stream-readasync(system-memory((system-byte))-system-threading-cancellationtoken)) * `ValueTask WriteAsync(ReadOnlyMemory, CancellationToken)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.io.stream.writeasync#system-io-stream-writeasync(system-readonlymemory((system-byte))-system-threading-cancellationtoken)) -### TextReader +#### TextReader * `ValueTask ReadAsync(Memory, CancellationToken)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.io.textreader.readasync#system-io-textreader-readasync(system-memory((system-char))-system-threading-cancellationtoken)) * `Task ReadLineAsync(CancellationToken)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.io.textreader.readtoendasync#system-io-textreader-readlineasync(system-threading-cancellationtoken)) * `Task ReadToEndAsync(CancellationToken)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.io.textreader.readtoendasync#system-io-textreader-readtoendasync(system-threading-cancellationtoken)) -### TextWriter +#### TextWriter * `Void Write(ReadOnlySpan)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.io.textwriter.write#system-io-textwriter-write(system-readonlyspan((system-char)))) * `ValueTask WriteAsync(ReadOnlyMemory, CancellationToken)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.io.textwriter.writeasync#system-io-textwriter-writeasync(system-readonlymemory((system-char))-system-threading-cancellationtoken)) @@ -468,7 +470,7 @@ The class `Polyfill` includes the following extension methods: * `ValueTask WriteLineAsync(ReadOnlyMemory, CancellationToken)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.io.textwriter.writelineasync#system-io-textwriter-writelineasync(system-readonlymemory((system-char))-system-threading-cancellationtoken)) -### HttpClient +#### HttpClient * `Task GetByteArrayAsync(String, CancellationToken)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.net.http.httpclient.getbytearrayasync#system-net-http-httpclient-getbytearrayasync(system-string-system-threading-cancellationtoken)) * `Task GetByteArrayAsync(Uri, CancellationToken)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.net.http.httpclient.getbytearrayasync#system-net-http-httpclient-getbytearrayasync(system-uri-system-threading-cancellationtoken)) @@ -478,40 +480,40 @@ The class `Polyfill` includes the following extension methods: * `Task GetStringAsync(Uri, CancellationToken)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.net.http.httpclient.getstringasync#system-net-http-httpclient-getstringasync(system-uri-system-threading-cancellationtoken)) -### HttpContent +#### HttpContent * `Task ReadAsByteArrayAsync(CancellationToken)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.net.http.httpcontent.readasbytearrayasync#system-net-http-httpcontent-readasbytearrayasync(system-threading-cancellationtoken)) * `Task ReadAsStreamAsync(CancellationToken)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.net.http.httpcontent.readasstreamasync#system-net-http-httpcontent-readasstreamasync(system-threading-cancellationtoken)) * `Task ReadAsStringAsync(CancellationToken)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.net.http.httpcontent.readasstringasync#system-net-http-httpcontent-readasstringasync(system-threading-cancellationtoken)) -### ReadOnlySpan +#### ReadOnlySpan * `Boolean EndsWith(String, StringComparison)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.endswith#system-memoryextensions-endswith-1(system-readonlyspan((-0))-system-readonlyspan((-0)))) * `Boolean SequenceEqual(String)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.sequenceequal#system-memoryextensions-sequenceequal-1(system-readonlyspan((-0))-system-readonlyspan((-0)))) * `Boolean StartsWith(String, StringComparison)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.startswith#system-memoryextensions-startswith-1(system-readonlyspan((-0))-system-readonlyspan((-0)))) -### ReadOnlySpan +#### ReadOnlySpan * `Boolean Contains(T)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.contains#system-memoryextensions-contains-1(system-readonlyspan((-0))-0)) -### Reflection.EventInfo +#### Reflection.EventInfo * `Reflection.NullabilityState GetNullability()` * `Reflection.NullabilityInfo GetNullabilityInfo()` * `Boolean IsNullable()` -### Reflection.FieldInfo +#### Reflection.FieldInfo * `Reflection.NullabilityState GetNullability()` * `Reflection.NullabilityInfo GetNullabilityInfo()` * `Boolean IsNullable()` -### Reflection.MemberInfo +#### Reflection.MemberInfo * `Reflection.NullabilityState GetNullability()` * `Reflection.NullabilityInfo GetNullabilityInfo()` @@ -519,43 +521,43 @@ The class `Polyfill` includes the following extension methods: * `Boolean IsNullable()` -### Reflection.ParameterInfo +#### Reflection.ParameterInfo * `Reflection.NullabilityState GetNullability()` * `Reflection.NullabilityInfo GetNullabilityInfo()` * `Boolean IsNullable()` -### Reflection.PropertyInfo +#### Reflection.PropertyInfo * `Reflection.NullabilityState GetNullability()` * `Reflection.NullabilityInfo GetNullabilityInfo()` * `Boolean IsNullable()` -### SByte +#### SByte * `Boolean TryFormat(Span, Int32&, ReadOnlySpan, IFormatProvider)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.sbyte.tryformat) -### Single +#### Single * `Boolean TryFormat(Span, Int32&, ReadOnlySpan, IFormatProvider)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.single.tryformat) -### Span +#### Span * `Boolean EndsWith(String)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.endswith#system-memoryextensions-endswith-1(system-span((-0))-system-readonlyspan((-0)))) * `Boolean SequenceEqual(String)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.sequenceequal#system-memoryextensions-sequenceequal-1(system-span((-0))-system-readonlyspan((-0)))) * `Boolean StartsWith(String)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.startswith#system-memoryextensions-startswith-1(system-span((-0))-system-readonlyspan((-0)))) -### Span +#### Span * `Boolean Contains(T)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.contains#system-memoryextensions-contains-1(system-span((-0))-0)) -### String +#### String * `Boolean Contains(String, StringComparison)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.string.contains#system-string-contains(system-string-system-stringcomparison)) * `Boolean Contains(Char)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.string.contains#system-string-contains(system-char)) @@ -568,7 +570,13 @@ The class `Polyfill` includes the following extension methods: * `Boolean TryCopyTo(Span)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.string.trycopyto) -### StringBuilder +#### RegularExpressions.Regex + + * `Boolean IsMatch(ReadOnlySpan, Int32)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.text.regularexpressions.regex.ismatch#system-text-regularexpressions-regex-ismatch(system-readonlyspan((system-char))-system-int32)) + * `Boolean IsMatch(ReadOnlySpan)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.text.regularexpressions.regex.ismatch#system-text-regularexpressions-regex-ismatch(system-readonlyspan((system-char)))) + + +#### StringBuilder * `StringBuilder Append(ReadOnlySpan)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.text.stringbuilder.append#system-text-stringbuilder-append(system-readonlyspan((system-char)))) * `StringBuilder Append(AppendInterpolatedStringHandler&)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.text.stringbuilder.append#system-text-stringbuilder-append(system-text-stringbuilder-appendinterpolatedstringhandler@)) @@ -585,58 +593,73 @@ The class `Polyfill` includes the following extension methods: * `Boolean Equals(ReadOnlySpan)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.text.stringbuilder.equals#system-text-stringbuilder-equals(system-readonlyspan((system-char)))) -### CancellationToken +#### CancellationToken * `CancellationTokenRegistration Register(Action, Object)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.threading.cancellationtoken.register#system-threading-cancellationtoken-register(system-action((system-object-system-threading-cancellationtoken))-system-object)) * `CancellationTokenRegistration UnsafeRegister(Action, Object)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.threading.cancellationtoken.unsaferegister#system-threading-cancellationtoken-unsaferegister(system-action((system-object))-system-object)) * `CancellationTokenRegistration UnsafeRegister(Action, Object)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.threading.cancellationtoken.unsaferegister#system-threading-cancellationtoken-unsaferegister(system-action((system-object-system-threading-cancellationtoken))-system-object)) -### CancellationTokenSource +#### CancellationTokenSource * `Task CancelAsync()` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.threading.cancellationtokensource.cancelasync) -### Task +#### Task * `Task WaitAsync(CancellationToken)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.threading.tasks.task.waitasync#system-threading-tasks-task-waitasync(system-threading-cancellationtoken)) * `Task WaitAsync(TimeSpan)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.threading.tasks.task.waitasync#system-threading-tasks-task-waitasync(system-timespan)) * `Task WaitAsync(TimeSpan, CancellationToken)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.threading.tasks.task.waitasync#system-threading-tasks-task-waitasync(system-timespan-system-threading-cancellationtoken)) -### Task +#### Task * `Task WaitAsync(CancellationToken)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.threading.tasks.task.waitasync#system-threading-tasks-task-waitasync(system-threading-cancellationtoken)) * `Task WaitAsync(TimeSpan)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.threading.tasks.task-1.waitasync#system-threading-tasks-task-1-waitasync(system-timespan)) * `Task WaitAsync(TimeSpan, CancellationToken)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.threading.tasks.task-1.waitasync#system-threading-tasks-task-1-waitasync(system-timespan-system-threading-cancellationtoken)) -### TimeSpan +#### TimeSpan * `Int32 Microseconds()` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.timespan.microseconds) * `Int32 Nanoseconds()` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.timespan.nanoseconds) * `Boolean TryFormat(Span, Int32&, ReadOnlySpan, IFormatProvider)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.timespan.tryformat#system-timespan-tryformat(system-span((system-byte))-system-int32@-system-readonlyspan((system-char))-system-iformatprovider)) -### Type +#### Type * `Boolean IsGenericMethodParameter()` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.type.isgenericmethodparameter) -### UInt16 +#### UInt16 * `Boolean TryFormat(Span, Int32&, ReadOnlySpan, IFormatProvider)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.uint16.tryformat) -### UInt32 +#### UInt32 * `Boolean TryFormat(Span, Int32&, ReadOnlySpan, IFormatProvider)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.uint32.tryformat) -### UInt64 +#### UInt64 * `Boolean TryFormat(Span, Int32&, ReadOnlySpan, IFormatProvider)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.uint64.tryformat) + +### Static helpers + +#### EnumPolyfill + + * `String[] GetNames()` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.enum.getnames) + * `TEnum[] GetValues()` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.enum.getvalues) + + +#### RegexPolyfill + + * `Boolean IsMatch(String, RegularExpressions.RegexOptions, TimeSpan)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.text.regularexpressions.regex.ismatch#system-text-regularexpressions-regex-ismatch(system-readonlyspan((system-char))-system-string-system-text-regularexpressions-regexoptions-system-timespan)) + * `Boolean IsMatch(String, RegularExpressions.RegexOptions)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.text.regularexpressions.regex.ismatch#system-text-regularexpressions-regex-ismatch(system-readonlyspan((system-char))-system-string-system-text-regularexpressions-regexoptions)) + * `Boolean IsMatch(String)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.text.regularexpressions.regex.ismatch#system-text-regularexpressions-regex-ismatch(system-readonlyspan((system-char))-system-string)) + diff --git a/src/Consume/Consume.cs b/src/Consume/Consume.cs index a7074f5d..9eb2745d 100644 --- a/src/Consume/Consume.cs +++ b/src/Consume/Consume.cs @@ -13,6 +13,7 @@ using System.Runtime.InteropServices; using System.Runtime.Versioning; using System.Text; +using System.Text.RegularExpressions; using System.Threading; using System.Threading.Tasks; #pragma warning disable CS4014 @@ -198,6 +199,13 @@ async Task StreamReaderReadAsync() var reader = new StreamReader(new MemoryStream()); var read = await reader.ReadAsync(memory); } + + void RegexIsMatch() + { + var regex = new Regex("result"); + regex.IsMatch("value".AsSpan()); + } + async Task StreamReadAsync() { var input = new byte[] diff --git a/src/Consume/Consume.csproj b/src/Consume/Consume.csproj index 86a0acf2..12027444 100644 --- a/src/Consume/Consume.csproj +++ b/src/Consume/Consume.csproj @@ -9,27 +9,7 @@ - - Pollyfill\%(RecursiveDir)%(Filename).cs - - - Pollyfill\Nullable\%(RecursiveDir)%(Filename).cs - - - Pollyfill\Nullability\%(RecursiveDir)%(Filename).cs - - - Pollyfill\IndexRange\%(RecursiveDir)%(Filename).cs - - - Pollyfill\StringInterpolation\%(RecursiveDir)%(Filename).cs - - - Pollyfill\Trimming\%(RecursiveDir)%(Filename).cs - - - Pollyfill\PlatformCompatibility\%(RecursiveDir)%(Filename).cs - - + + \ No newline at end of file diff --git a/src/ConsumeClassicReferences/ConsumeClassicReferences.csproj b/src/ConsumeClassicReferences/ConsumeClassicReferences.csproj index fb125224..cbbe0bab 100644 --- a/src/ConsumeClassicReferences/ConsumeClassicReferences.csproj +++ b/src/ConsumeClassicReferences/ConsumeClassicReferences.csproj @@ -10,27 +10,7 @@ - - Pollyfill\%(RecursiveDir)%(Filename).cs - - - Pollyfill\Nullable\%(RecursiveDir)%(Filename).cs - - - Pollyfill\Nullability\%(RecursiveDir)%(Filename).cs - - - Pollyfill\IndexRange\%(RecursiveDir)%(Filename).cs - - - Pollyfill\StringInterpolation\%(RecursiveDir)%(Filename).cs - - - Pollyfill\Trimming\%(RecursiveDir)%(Filename).cs - - - Pollyfill\PlatformCompatibility\%(RecursiveDir)%(Filename).cs - - + + \ No newline at end of file diff --git a/src/ConsumeIndirect/ConsumeIndirect.csproj b/src/ConsumeIndirect/ConsumeIndirect.csproj index b972413d..300eb491 100644 --- a/src/ConsumeIndirect/ConsumeIndirect.csproj +++ b/src/ConsumeIndirect/ConsumeIndirect.csproj @@ -10,28 +10,7 @@ - - Pollyfill\%(RecursiveDir)%(Filename).cs - - - Pollyfill\Nullable\%(RecursiveDir)%(Filename).cs - - - Pollyfill\Nullability\%(RecursiveDir)%(Filename).cs - - - Pollyfill\IndexRange\%(RecursiveDir)%(Filename).cs - - - Pollyfill\StringInterpolation\%(RecursiveDir)%(Filename).cs - - - Pollyfill\Trimming\%(RecursiveDir)%(Filename).cs - - - Pollyfill\PlatformCompatibility\%(RecursiveDir)%(Filename).cs - - - + + \ No newline at end of file diff --git a/src/ConsumeNoRefs/ConsumeNoRefs.csproj b/src/ConsumeNoRefs/ConsumeNoRefs.csproj index 6d33b5ac..b67fec37 100644 --- a/src/ConsumeNoRefs/ConsumeNoRefs.csproj +++ b/src/ConsumeNoRefs/ConsumeNoRefs.csproj @@ -6,27 +6,7 @@ - - Pollyfill\%(RecursiveDir)%(Filename).cs - - - Pollyfill\Nullable\%(RecursiveDir)%(Filename).cs - - - Pollyfill\Nullability\%(RecursiveDir)%(Filename).cs - - - Pollyfill\IndexRange\%(RecursiveDir)%(Filename).cs - - - Pollyfill\StringInterpolation\%(RecursiveDir)%(Filename).cs - - - Pollyfill\Trimming\%(RecursiveDir)%(Filename).cs - - - Pollyfill\PlatformCompatibility\%(RecursiveDir)%(Filename).cs - - + + \ No newline at end of file diff --git a/src/ConsumeTasksWithNoMemory/ConsumeTasksWithNoMemory.csproj b/src/ConsumeTasksWithNoMemory/ConsumeTasksWithNoMemory.csproj index a6dd9ad0..60ebae2e 100644 --- a/src/ConsumeTasksWithNoMemory/ConsumeTasksWithNoMemory.csproj +++ b/src/ConsumeTasksWithNoMemory/ConsumeTasksWithNoMemory.csproj @@ -6,24 +6,7 @@ - - Pollyfill\%(RecursiveDir)%(Filename).cs - - - Pollyfill\Nullable\%(RecursiveDir)%(Filename).cs - - - Pollyfill\Nullability\%(RecursiveDir)%(Filename).cs - - - Pollyfill\IndexRange\%(RecursiveDir)%(Filename).cs - - - Pollyfill\Trimming\%(RecursiveDir)%(Filename).cs - - - Pollyfill\PlatformCompatibility\%(RecursiveDir)%(Filename).cs - - + + \ No newline at end of file diff --git a/src/NoRefsTests/NoRefsTests.csproj b/src/NoRefsTests/NoRefsTests.csproj index 0a605ee1..8495d864 100644 --- a/src/NoRefsTests/NoRefsTests.csproj +++ b/src/NoRefsTests/NoRefsTests.csproj @@ -4,27 +4,6 @@ $(TargetFrameworks);netcoreapp3.1;net5.0;net6.0;net7.0;net8.0;net9.0 - - Pollyfill\%(RecursiveDir)%(Filename).cs - - - Pollyfill\Nullable\%(RecursiveDir)%(Filename).cs - - - Pollyfill\Nullability\%(RecursiveDir)%(Filename).cs - - - Pollyfill\IndexRange\%(RecursiveDir)%(Filename).cs - - - Pollyfill\StringInterpolation\%(RecursiveDir)%(Filename).cs - - - Pollyfill\Trimming\%(RecursiveDir)%(Filename).cs - - - Pollyfill\PlatformCompatibility\%(RecursiveDir)%(Filename).cs - @@ -38,5 +17,6 @@ - + + \ No newline at end of file diff --git a/src/Polyfill/Polyfill.nuspec b/src/Polyfill/Polyfill.nuspec index 9d340323..b447dd2e 100644 --- a/src/Polyfill/Polyfill.nuspec +++ b/src/Polyfill/Polyfill.nuspec @@ -27,6 +27,8 @@ target="contentFiles/cs/netstandard2.0/Polyfill/StringInterpolation"/> + true - - Pollyfill\%(RecursiveDir)%(Filename).cs - - - Pollyfill\Nullable\%(RecursiveDir)%(Filename).cs - - - Pollyfill\Nullability\%(RecursiveDir)%(Filename).cs - - - Pollyfill\IndexRange\%(RecursiveDir)%(Filename).cs - - - Pollyfill\StringInterpolation\%(RecursiveDir)%(Filename).cs - - - Pollyfill\Trimming\%(RecursiveDir)%(Filename).cs - - - Pollyfill\PlatformCompatibility\%(RecursiveDir)%(Filename).cs - @@ -36,5 +15,6 @@ - + + \ No newline at end of file diff --git a/src/TestIncludes.targets b/src/TestIncludes.targets new file mode 100644 index 00000000..1b349f16 --- /dev/null +++ b/src/TestIncludes.targets @@ -0,0 +1,28 @@ + + + + Pollyfill\%(Filename).cs + + + Pollyfill\Nullable\%(RecursiveDir)%(Filename).cs + + + Pollyfill\Nullability\%(RecursiveDir)%(Filename).cs + + + Pollyfill\IndexRange\%(RecursiveDir)%(Filename).cs + + + Pollyfill\StringInterpolation\%(RecursiveDir)%(Filename).cs + + + Pollyfill\Trimming\%(RecursiveDir)%(Filename).cs + + + Pollyfill\PlatformCompatibility\%(RecursiveDir)%(Filename).cs + + + Pollyfill\Regex\%(RecursiveDir)%(Filename).cs + + + \ No newline at end of file diff --git a/src/Tests/BuildApiTest.cs b/src/Tests/BuildApiTest.cs index 34a9ade6..9691521e 100644 --- a/src/Tests/BuildApiTest.cs +++ b/src/Tests/BuildApiTest.cs @@ -1,3 +1,6 @@ +using System.Diagnostics.CodeAnalysis; +using Mono.Cecil; + #if NET8_0 && DEBUG [TestFixture] class BuildApiTest @@ -21,59 +24,51 @@ public void Run() var path = Path.Combine(solutionDirectory, "Consume", "bin", "Debug", "netstandard2.0", "Consume.dll"); var md = Path.Combine(solutionDirectory, "..", "api_list.include.md"); File.Delete(md); - using var module = Mono.Cecil.ModuleDefinition.ReadModule(path); - var extensions = module.GetTypes().Single(_ => _.Name == nameof(Polyfill)); + using var module = ModuleDefinition.ReadModule(path); + var types = module.GetTypes().ToList(); + var extensions = types.Single(_ => _.Name == nameof(Polyfill)); using var writer = File.CreateText(md); - foreach (var type in extensions.Methods - .Where(_ => !_.IsConstructor) + writer.WriteLine($"### Extension methods"); + writer.WriteLine(); + foreach (var type in PublicMethods(extensions.Methods) .GroupBy(_ => _.Parameters[0].ParameterType.FullName) .OrderBy(_ => _.Key)) { - if (!type.Any(_ => _.IsPublic)) - { - continue; - } - - var targetType = type.Key; - var targetFullName = targetType.Replace("`1", "").Replace("`2", ""); - writer.WriteLine($"### {SimpleTypeName(targetFullName)}"); + writer.WriteLine($"#### {GetTypeName(type.Key)}"); writer.WriteLine(); - foreach (var method in type.OrderBy(_ => _.Name)) + foreach (var method in type) { - if (!method.IsPublic) - { - continue; - } - - var parameters = string.Join(", ", method.Parameters.Skip(1).Select(_ => SimpleTypeName(_.ParameterType.FullName))); - var typeArgs = ""; - if (method.HasGenericParameters) - { - typeArgs = $"<{string.Join(", ", method.GenericParameters.Select(_ => _.Name))}>"; - } - - var signature = $"{SimpleTypeName(method.ReturnType.FullName)} {method.Name}{typeArgs}({parameters})"; - var descriptionAttribute = method.CustomAttributes - .SingleOrDefault(_ => _.AttributeType.Name == "DescriptionAttribute"); - if (descriptionAttribute == null) - { - writer.WriteLine($" * `{signature}`"); - } - else - { - writer.WriteLine($" * `{signature}` [reference]({descriptionAttribute.ConstructorArguments.Single().Value})"); - } + WriteSignature(method, writer); } writer.WriteLine(); writer.WriteLine(); } + writer.WriteLine($"### Static helpers"); + writer.WriteLine(); + + WriteHelper(types, nameof(EnumPolyfill), writer); + WriteHelper(types, "RegexPolyfill", writer); + } + + static void WriteHelper(List types, string name, StreamWriter writer) + { + var helper = types.Single(_ => _.Name == name); + + writer.WriteLine($"#### {helper.Name}"); + writer.WriteLine(); + foreach (var method in PublicMethods(helper.Methods)) + { + WriteSignature(method, writer); + } + writer.WriteLine(); + writer.WriteLine(); } - static string SimpleTypeName(string fullName) + static string GetTypeName(string targetType) { - var name = fullName.Replace("`1", "").Replace("`2", ""); + var name = targetType.Replace("`1", "").Replace("`2", ""); foreach (var toClean in namespacesToClean) { name = name.Replace(toClean, ""); @@ -81,5 +76,52 @@ static string SimpleTypeName(string fullName) return name; } + + static IEnumerable PublicMethods(IEnumerable type) => + type.Where(_=>_ is {IsPublic: true, IsConstructor: false}) + .OrderBy(_ => _.Name); + + static void WriteSignature(MethodDefinition method, StreamWriter writer) + { + var parameters = BuildParameters(method); + var typeArgs = BuildTypeArgs(method); + var signature = $"{GetTypeName(method.ReturnType.FullName)} {method.Name}{typeArgs}({parameters})"; + if (TryGetReference(method, out var reference)) + { + writer.WriteLine($" * `{signature}` [reference]({reference})"); + } + else + { + writer.WriteLine($" * `{signature}`"); + } + } + + static string BuildParameters(MethodDefinition method) => + string.Join(", ", method.Parameters.Skip(1).Select(_ => GetTypeName(_.ParameterType.FullName))); + + static string BuildTypeArgs(MethodDefinition method) + { + var typeArgs = ""; + if (method.HasGenericParameters) + { + typeArgs = $"<{string.Join(", ", method.GenericParameters.Select(_ => _.Name))}>"; + } + + return typeArgs; + } + + static bool TryGetReference(MethodDefinition method,[NotNullWhen(true)] out string? reference) + { + var descriptionAttribute = method.CustomAttributes + .SingleOrDefault(_ => _.AttributeType.Name == "DescriptionAttribute"); + if (descriptionAttribute == null) + { + reference = null; + return false; + } + + reference = (string) descriptionAttribute.ConstructorArguments.Single().Value!; + return true; + } } #endif \ No newline at end of file diff --git a/src/Tests/Tests.csproj b/src/Tests/Tests.csproj index 4af6ec0b..eeb9482e 100644 --- a/src/Tests/Tests.csproj +++ b/src/Tests/Tests.csproj @@ -4,27 +4,6 @@ $(TargetFrameworks);netcoreapp3.1;net5.0;net6.0;net7.0;net8.0;net9.0 - - Pollyfill\%(RecursiveDir)%(Filename).cs - - - Pollyfill\Nullable\%(RecursiveDir)%(Filename).cs - - - Pollyfill\Nullability\%(RecursiveDir)%(Filename).cs - - - Pollyfill\IndexRange\%(RecursiveDir)%(Filename).cs - - - Pollyfill\StringInterpolation\%(RecursiveDir)%(Filename).cs - - - Pollyfill\Trimming\%(RecursiveDir)%(Filename).cs - - - Pollyfill\PlatformCompatibility\%(RecursiveDir)%(Filename).cs - @@ -36,5 +15,6 @@ - + + \ No newline at end of file diff --git a/src/UnsafeTests/UnsafeTests.csproj b/src/UnsafeTests/UnsafeTests.csproj index da4668f2..d5d9896c 100644 --- a/src/UnsafeTests/UnsafeTests.csproj +++ b/src/UnsafeTests/UnsafeTests.csproj @@ -5,27 +5,6 @@ True - - Pollyfill\%(RecursiveDir)%(Filename).cs - - - Pollyfill\Nullable\%(RecursiveDir)%(Filename).cs - - - Pollyfill\Nullability\%(RecursiveDir)%(Filename).cs - - - Pollyfill\IndexRange\%(RecursiveDir)%(Filename).cs - - - Pollyfill\StringInterpolation\%(RecursiveDir)%(Filename).cs - - - Pollyfill\Trimming\%(RecursiveDir)%(Filename).cs - - - Pollyfill\PlatformCompatibility\%(RecursiveDir)%(Filename).cs - @@ -36,5 +15,6 @@ - + + \ No newline at end of file