Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apiCount.include.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
**API count: 646**
**API count: 647**
1 change: 1 addition & 0 deletions api_list.include.md
Original file line number Diff line number Diff line change
Expand Up @@ -805,6 +805,7 @@
#### Type

* `MemberInfo GetMemberWithSameMetadataDefinitionAs(MemberInfo)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.type.getmemberwithsamemetadatadefinitionas?view=net-10.0)
* `MethodInfo? GetMethod(string, int, BindingFlags, Binder?, Type[], ParameterModifier[]?)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.type.getmethod?view=net-10.0#system-type-getmethod(system-string-system-int32-system-reflection-bindingflags-system-reflection-binder-system-type()-system-reflection-parametermodifier()))
* `MethodInfo? GetMethod(string, int, BindingFlags, Type[])` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.type.getmethod?view=net-10.0#system-type-getmethod(system-string-system-int32-system-reflection-bindingflags-system-type()))
* `bool IsAssignableFrom<T>()`
* `bool IsAssignableTo(Type?)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.type.isassignableto?view=net-10.0)
Expand Down
58 changes: 29 additions & 29 deletions assemblySize.include.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@

| | Empty Assembly | With Polyfill | Diff | Ensure | ArgumentExceptions | StringInterpolation | Nullability |
|----------------|----------------|---------------|-----------|-----------|--------------------|---------------------|-------------|
| netstandard2.0 | 8.0 KB | 184.0 KB | +176.0 KB | +8.5 KB | +5.5 KB | +9.0 KB | +14.0 KB |
| netstandard2.0 | 8.0 KB | 185.5 KB | +177.5 KB | +8.5 KB | +5.0 KB | +9.0 KB | +13.5 KB |
| netstandard2.1 | 8.5 KB | 148.0 KB | +139.5 KB | +8.5 KB | +5.0 KB | +9.0 KB | +14.0 KB |
| net461 | 7.0 KB | 189.0 KB | +182.0 KB | +8.5 KB | +5.5 KB | +9.0 KB | +14.0 KB |
| net462 | 7.0 KB | 189.0 KB | +182.0 KB | +8.5 KB | +5.5 KB | +9.0 KB | +14.0 KB |
| net47 | 7.0 KB | 189.0 KB | +182.0 KB | +8.5 KB | +5.0 KB | +9.0 KB | +13.5 KB |
| net471 | 8.5 KB | 189.0 KB | +180.5 KB | +8.5 KB | +5.5 KB | +9.0 KB | +14.0 KB |
| net472 | 8.5 KB | 187.5 KB | +179.0 KB | +8.5 KB | +5.5 KB | +9.0 KB | +14.0 KB |
| net48 | 8.5 KB | 187.5 KB | +179.0 KB | +8.5 KB | +5.5 KB | +9.0 KB | +14.0 KB |
| net481 | 8.5 KB | 187.5 KB | +179.0 KB | +8.5 KB | +5.5 KB | +9.0 KB | +14.0 KB |
| netcoreapp2.0 | 9.0 KB | 165.0 KB | +156.0 KB | +8.0 KB | +5.0 KB | +8.5 KB | +13.5 KB |
| net461 | 7.0 KB | 190.5 KB | +183.5 KB | +8.5 KB | +5.0 KB | +9.0 KB | +13.5 KB |
| net462 | 7.0 KB | 190.5 KB | +183.5 KB | +8.5 KB | +5.0 KB | +9.0 KB | +13.5 KB |
| net47 | 7.0 KB | 190.0 KB | +183.0 KB | +8.5 KB | +5.5 KB | +9.0 KB | +14.0 KB |
| net471 | 8.5 KB | 190.0 KB | +181.5 KB | +8.5 KB | +5.5 KB | +9.0 KB | +14.0 KB |
| net472 | 8.5 KB | 189.0 KB | +180.5 KB | +8.5 KB | +5.0 KB | +9.0 KB | +13.5 KB |
| net48 | 8.5 KB | 189.0 KB | +180.5 KB | +8.5 KB | +5.0 KB | +9.0 KB | +13.5 KB |
| net481 | 8.5 KB | 189.0 KB | +180.5 KB | +8.5 KB | +5.5 KB | +9.0 KB | +13.5 KB |
| netcoreapp2.0 | 9.0 KB | 166.0 KB | +157.0 KB | +8.5 KB | +5.0 KB | +9.0 KB | +13.5 KB |
| netcoreapp2.1 | 9.0 KB | 157.5 KB | +148.5 KB | +8.5 KB | +5.0 KB | +9.0 KB | +14.0 KB |
| netcoreapp2.2 | 9.0 KB | 157.5 KB | +148.5 KB | +8.5 KB | +5.0 KB | +9.0 KB | +14.0 KB |
| netcoreapp3.0 | 9.5 KB | 151.5 KB | +142.0 KB | +8.5 KB | +5.5 KB | +9.5 KB | +14.0 KB |
Expand All @@ -28,23 +28,23 @@

| | Empty Assembly | With Polyfill | Diff | Ensure | ArgumentExceptions | StringInterpolation | Nullability |
|----------------|----------------|---------------|-----------|-----------|--------------------|---------------------|-------------|
| netstandard2.0 | 8.0 KB | 292.0 KB | +284.0 KB | +16.4 KB | +7.0 KB | +14.4 KB | +19.9 KB |
| netstandard2.1 | 8.5 KB | 236.7 KB | +228.2 KB | +16.4 KB | +6.5 KB | +14.4 KB | +19.9 KB |
| net461 | 7.0 KB | 297.5 KB | +290.5 KB | +16.4 KB | +7.0 KB | +14.4 KB | +19.9 KB |
| net462 | 7.0 KB | 297.5 KB | +290.5 KB | +16.4 KB | +7.0 KB | +14.4 KB | +19.9 KB |
| net47 | 7.0 KB | 297.2 KB | +290.2 KB | +16.4 KB | +6.5 KB | +14.4 KB | +19.4 KB |
| net471 | 8.5 KB | 297.2 KB | +288.7 KB | +16.4 KB | +7.0 KB | +14.4 KB | +19.9 KB |
| net472 | 8.5 KB | 294.6 KB | +286.1 KB | +16.4 KB | +7.0 KB | +14.4 KB | +19.9 KB |
| net48 | 8.5 KB | 294.6 KB | +286.1 KB | +16.4 KB | +7.0 KB | +14.4 KB | +19.9 KB |
| net481 | 8.5 KB | 294.6 KB | +286.1 KB | +16.4 KB | +7.0 KB | +14.4 KB | +19.9 KB |
| netcoreapp2.0 | 9.0 KB | 263.6 KB | +254.6 KB | +15.9 KB | +6.5 KB | +13.9 KB | +19.4 KB |
| netcoreapp2.1 | 9.0 KB | 249.9 KB | +240.9 KB | +16.4 KB | +6.5 KB | +14.4 KB | +19.9 KB |
| netcoreapp2.2 | 9.0 KB | 249.9 KB | +240.9 KB | +16.4 KB | +6.5 KB | +14.4 KB | +19.9 KB |
| netcoreapp3.0 | 9.5 KB | 236.5 KB | +227.0 KB | +16.4 KB | +7.0 KB | +14.9 KB | +19.9 KB |
| netcoreapp3.1 | 9.5 KB | 235.0 KB | +225.5 KB | +16.4 KB | +6.5 KB | +14.4 KB | +19.9 KB |
| net5.0 | 9.5 KB | 210.2 KB | +200.7 KB | +16.4 KB | +6.5 KB | +14.4 KB | +19.4 KB |
| net6.0 | 10.0 KB | 165.1 KB | +155.1 KB | +16.9 KB | +6.4 KB | +1.6 KB | +4.5 KB |
| net7.0 | 10.0 KB | 129.5 KB | +119.5 KB | +16.8 KB | +6.3 KB | +2.1 KB | +4.5 KB |
| net8.0 | 9.5 KB | 102.6 KB | +93.1 KB | +16.3 KB | +1.8 KB | +1.6 KB | +4.5 KB |
| net9.0 | 10.0 KB | 62.2 KB | +52.2 KB | +16.8 KB | +1.7 KB | +2.1 KB | +5.0 KB |
| net10.0 | 10.0 KB | 48.5 KB | +38.5 KB | +17.3 KB | +2.2 KB | +2.1 KB | +5.0 KB |
| netstandard2.0 | 8.0 KB | 292.1 KB | +284.1 KB | +16.2 KB | +6.4 KB | +14.4 KB | +19.3 KB |
| netstandard2.1 | 8.5 KB | 235.3 KB | +226.8 KB | +16.2 KB | +6.4 KB | +14.4 KB | +19.8 KB |
| net461 | 7.0 KB | 297.6 KB | +290.6 KB | +16.2 KB | +6.4 KB | +14.4 KB | +19.3 KB |
| net462 | 7.0 KB | 297.6 KB | +290.6 KB | +16.2 KB | +6.4 KB | +14.4 KB | +19.3 KB |
| net47 | 7.0 KB | 296.8 KB | +289.8 KB | +16.2 KB | +6.9 KB | +14.4 KB | +19.8 KB |
| net471 | 8.5 KB | 296.8 KB | +288.3 KB | +16.2 KB | +6.9 KB | +14.4 KB | +19.8 KB |
| net472 | 8.5 KB | 294.7 KB | +286.2 KB | +16.2 KB | +6.4 KB | +14.4 KB | +19.3 KB |
| net48 | 8.5 KB | 294.7 KB | +286.2 KB | +16.2 KB | +6.4 KB | +14.4 KB | +19.3 KB |
| net481 | 8.5 KB | 294.7 KB | +286.2 KB | +16.2 KB | +6.9 KB | +14.4 KB | +19.3 KB |
| netcoreapp2.0 | 9.0 KB | 263.3 KB | +254.3 KB | +16.2 KB | +6.4 KB | +14.4 KB | +19.3 KB |
| netcoreapp2.1 | 9.0 KB | 248.4 KB | +239.4 KB | +16.2 KB | +6.4 KB | +14.4 KB | +19.8 KB |
| netcoreapp2.2 | 9.0 KB | 248.4 KB | +239.4 KB | +16.2 KB | +6.4 KB | +14.4 KB | +19.8 KB |
| netcoreapp3.0 | 9.5 KB | 235.1 KB | +225.6 KB | +16.2 KB | +6.9 KB | +14.9 KB | +19.8 KB |
| netcoreapp3.1 | 9.5 KB | 233.5 KB | +224.0 KB | +16.2 KB | +6.4 KB | +14.4 KB | +19.8 KB |
| net5.0 | 9.5 KB | 208.9 KB | +199.4 KB | +16.2 KB | +6.4 KB | +14.4 KB | +19.3 KB |
| net6.0 | 10.0 KB | 163.9 KB | +153.9 KB | +16.7 KB | +6.4 KB | +1.6 KB | +4.5 KB |
| net7.0 | 10.0 KB | 128.5 KB | +118.5 KB | +16.7 KB | +6.3 KB | +2.1 KB | +4.5 KB |
| net8.0 | 9.5 KB | 101.7 KB | +92.2 KB | +16.2 KB | +1.8 KB | +1.6 KB | +4.5 KB |
| net9.0 | 10.0 KB | 61.5 KB | +51.5 KB | +16.7 KB | +1.6 KB | +2.1 KB | +5.0 KB |
| net10.0 | 10.0 KB | 47.9 KB | +37.9 KB | +17.2 KB | +2.1 KB | +2.1 KB | +5.0 KB |
7 changes: 4 additions & 3 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ The package targets `netstandard2.0` and is designed to support the following ru
* `uap10`


**API count: 646**<!-- singleLineInclude: apiCount. path: /apiCount.include.md -->
**API count: 647**<!-- singleLineInclude: apiCount. path: /apiCount.include.md -->


**See [Milestones](../../milestones?state=closed) for release notes.**
Expand Down Expand Up @@ -1250,6 +1250,7 @@ The class `Polyfill` includes the following extension methods:
#### Type

* `MemberInfo GetMemberWithSameMetadataDefinitionAs(MemberInfo)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.type.getmemberwithsamemetadatadefinitionas?view=net-10.0)
* `MethodInfo? GetMethod(string, int, BindingFlags, Binder?, Type[], ParameterModifier[]?)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.type.getmethod?view=net-10.0#system-type-getmethod(system-string-system-int32-system-reflection-bindingflags-system-reflection-binder-system-type()-system-reflection-parametermodifier()))
* `MethodInfo? GetMethod(string, int, BindingFlags, Type[])` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.type.getmethod?view=net-10.0#system-type-getmethod(system-string-system-int32-system-reflection-bindingflags-system-type()))
* `bool IsAssignableFrom<T>()`
* `bool IsAssignableTo(Type?)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.type.isassignableto?view=net-10.0)
Expand Down Expand Up @@ -1576,7 +1577,7 @@ void ArgumentExceptionExample(Order order, Customer customer, string customerId,
this.quantity = quantity;
}
```
<sup><a href='/src/Consume/Consume.cs#L378-L396' title='Snippet source file'>snippet source</a> | <a href='#snippet-ArgumentExceptionUsage' title='Start of snippet'>anchor</a></sup>
<sup><a href='/src/Consume/Consume.cs#L384-L402' title='Snippet source file'>snippet source</a> | <a href='#snippet-ArgumentExceptionUsage' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->


Expand All @@ -1595,7 +1596,7 @@ void EnsureExample(Order order, Customer customer, string customerId, string ema
this.quantity = Ensure.NotNegativeOrZero(quantity);
}
```
<sup><a href='/src/Consume/Consume.cs#L402-L414' title='Snippet source file'>snippet source</a> | <a href='#snippet-EnsureUsage' title='Start of snippet'>anchor</a></sup>
<sup><a href='/src/Consume/Consume.cs#L408-L420' title='Snippet source file'>snippet source</a> | <a href='#snippet-EnsureUsage' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->


Expand Down
22 changes: 14 additions & 8 deletions src/Consume/Consume.cs
Original file line number Diff line number Diff line change
Expand Up @@ -295,20 +295,26 @@ async Task CancellationTokenSource_Methods()
}


#if !NETFRAMEWORK && !NETSTANDARD2_0 && !NETCOREAPP2_0
class WithGenericMethod
class WithMethods
{
public void GenericMethod<T>(string value)
{
}
public void NonGenericMethod(string value) { }
public void GenericMethod<T>(string value) { }
public void GenericMethod<T1, T2>(string value, int count) { }
}

void Type_GetMethod()
{
var type = typeof(WithGenericMethod);
type.GetMethod("GenericMethod", 1, BindingFlags.Public, [typeof(string)]);
var type = typeof(WithMethods);

// Non-generic method
var nonGeneric = type.GetMethod("NonGenericMethod", 0, BindingFlags.Public | BindingFlags.Instance, [typeof(string)]);

// Generic method with 1 type parameter
var generic1 = type.GetMethod("GenericMethod", 1, BindingFlags.Public | BindingFlags.Instance, [typeof(string)]);

// Generic method with 2 type parameters
var generic2 = type.GetMethod("GenericMethod", 2, BindingFlags.Public | BindingFlags.Instance, [typeof(string), typeof(int)]);
}
#endif

void ConcurrentDictionary_Methods()
{
Expand Down
2 changes: 1 addition & 1 deletion src/Polyfill/KeyValuePair.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#if NETFRAMEWORK || NETSTANDARD2_0
#if (NETFRAMEWORK || NETSTANDARD2_0) && !WINDOWS_UWP
#nullable enable

namespace System.Collections.Generic;
Expand Down
2 changes: 1 addition & 1 deletion src/Polyfill/Polyfill_Dictionary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public static ReadOnlyDictionary<TKey, TValue> AsReadOnly<TKey, TValue>(this IDi
new(target);
#endif

#if NETFRAMEWORK || NETSTANDARD2_0
#if (NETFRAMEWORK || NETSTANDARD2_0) && !WINDOWS_UWP

/// <summary>
/// Attempts to add the specified key and value to the <see cref="IDictionary{TKey,TValue}"/>.
Expand Down
2 changes: 1 addition & 1 deletion src/Polyfill/Polyfill_IEnumerable_SkipLast.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#if NETFRAMEWORK || NETSTANDARD2_0
#if (NETFRAMEWORK || NETSTANDARD2_0) && !WINDOWS_UWP

namespace Polyfills;

Expand Down
2 changes: 1 addition & 1 deletion src/Polyfill/Polyfill_IEnumerable_TakeLast.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.


#if NETSTANDARD2_0 || NETFRAMEWORK
#if (NETSTANDARD2_0 || NETFRAMEWORK) && !WINDOWS_UWP

namespace Polyfills;

Expand Down
2 changes: 1 addition & 1 deletion src/Polyfill/Polyfill_IReadOnlyDictionary.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#if NETFRAMEWORK || NETSTANDARD2_0
#if (NETFRAMEWORK || NETSTANDARD2_0) && !WINDOWS_UWP
#pragma warning disable CS8714

namespace Polyfills;
Expand Down
29 changes: 22 additions & 7 deletions src/Polyfill/Polyfill_Type.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,20 @@ public static bool HasSameMetadataDefinitionAs(this MemberInfo target, MemberInf
target.Module.Equals(other.Module);
#endif

#if !NET9_0_OR_GREATER && !NETFRAMEWORK && !NETSTANDARD2_0 && !NETCOREAPP2_0
//Link: https://learn.microsoft.com/en-us/dotnet/api/system.type.getmethod?view=net-10.0#system-type-getmethod(system-string-system-int32-system-reflection-bindingflags-system-type())
public static MethodInfo? GetMethod([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods | DynamicallyAccessedMemberTypes.NonPublicMethods)] this Type target, string name, int genericParameterCount, BindingFlags bindingAttr, Type[] types)
#if NETFRAMEWORK || NETSTANDARD2_0 || NETCOREAPP2_0 || WINDOWS_UWP
/// <summary>
/// Searches for the specified method whose parameters match the specified generic parameter count, argument types and modifiers, using the specified binding constraints.
/// </summary>
//Link: https://learn.microsoft.com/en-us/dotnet/api/system.type.getmethod?view=net-10.0#system-type-getmethod(system-string-system-int32-system-reflection-bindingflags-system-reflection-binder-system-type()-system-reflection-parametermodifier())
public static MethodInfo? GetMethod(
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods | DynamicallyAccessedMemberTypes.NonPublicMethods)] this Type target,
string name,
int genericParameterCount,
BindingFlags bindingAttr,
Binder? binder,
Type[] types,
ParameterModifier[]? modifiers)
{
#if NETFRAMEWORK || NETSTANDARD || NETCOREAPP
return target.GetMethod(name, genericParameterCount, bindingAttr, null, types, null);
#else
var methods = target.GetMethods(bindingAttr);
if (genericParameterCount == 0)
{
Expand Down Expand Up @@ -64,10 +71,18 @@ public static bool HasSameMetadataDefinitionAs(this MemberInfo target, MemberInf
bool IsMatch(MethodInfo method) =>
name == method.Name &&
method.GetParameters().Select(_ => _.ParameterType).SequenceEqual(types);
#endif
}
#endif

#if !NET9_0_OR_GREATER
/// <summary>
/// Searches for the specified method whose parameters match the specified generic parameter count, argument types and modifiers, using the specified binding constraints.
/// </summary>
//Link: https://learn.microsoft.com/en-us/dotnet/api/system.type.getmethod?view=net-10.0#system-type-getmethod(system-string-system-int32-system-reflection-bindingflags-system-type())
public static MethodInfo? GetMethod([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods | DynamicallyAccessedMemberTypes.NonPublicMethods)] this Type target, string name, int genericParameterCount, BindingFlags bindingAttr, Type[] types) =>
target.GetMethod(name, genericParameterCount, bindingAttr, null, types, null);
#endif

/// <summary>
/// Gets a value that indicates whether the current Type represents a type parameter in the definition of a generic method.
/// </summary>
Expand Down
2 changes: 1 addition & 1 deletion src/Polyfill/StringPolyfill.cs
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ public static string Join(string? separator, scoped ReadOnlySpan<object?> values
string.Join(separator, values.ToArray());
#endif

#if NETSTANDARD2_0 || NETFRAMEWORK
#if (NETSTANDARD2_0 || NETFRAMEWORK) && !WINDOWS_UWP

/// <summary>
/// Concatenates an array of strings, using the specified separator between each member.
Expand Down
Loading