-
Notifications
You must be signed in to change notification settings - Fork 10.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[main] Update dependencies from dotnet/efcore, dotnet/runtime #55339
Changes from 1 commit
f60f963
ef942a0
e10217e
277ecba
3472997
80e11cd
9cdbd54
fd13b17
67ec656
0a9c70c
67acd14
f0bc3b7
7890664
07773cd
84b7c26
48fbe2d
0ccca10
899e787
f6e2347
b7f7cf2
a98ae1f
a5dcb85
add61eb
1462086
4e8dda2
b75a379
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -829,12 +829,22 @@ private void LaunchStreams(ConnectionState connectionState, Dictionary<string, o | |
{ | ||
_ = _sendIAsyncStreamItemsMethod | ||
.MakeGenericMethod(reader.GetType().GetInterface("IAsyncEnumerable`1")!.GetGenericArguments()) | ||
.Invoke(this, new object[] { connectionState, kvp.Key.ToString(), reader, cts }); | ||
.Invoke(this, [connectionState, kvp.Key.ToString(), reader, cts]); | ||
continue; | ||
} | ||
_ = _sendStreamItemsMethod | ||
.MakeGenericMethod(reader.GetType().GetGenericArguments()) | ||
.Invoke(this, new object[] { connectionState, kvp.Key.ToString(), reader, cts }); | ||
else | ||
{ | ||
if (ReflectionHelper.TryGetStreamType(reader.GetType(), out var channelGenericType)) | ||
{ | ||
_ = _sendStreamItemsMethod | ||
.MakeGenericMethod(channelGenericType) | ||
.Invoke(this, [connectionState, kvp.Key.ToString(), reader, cts]); | ||
continue; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: let's use |
||
} | ||
|
||
// Should never get here, we should have already verified the stream types when the user initially calls send/invoke | ||
throw new InvalidOperationException($"{reader.GetType()} is not a {typeof(ChannelReader<>).Name}."); | ||
} | ||
} | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,9 @@ | |
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using System; | ||
using System.Collections.Concurrent; | ||
using System.Collections.Generic; | ||
using System.Diagnostics; | ||
using System.Diagnostics.CodeAnalysis; | ||
using System.Linq; | ||
using System.Threading.Channels; | ||
|
@@ -11,6 +13,8 @@ namespace Microsoft.AspNetCore.SignalR; | |
|
||
internal static class ReflectionHelper | ||
{ | ||
private static ConcurrentDictionary<Type, Type> _streamTypeLookup = new(); | ||
|
||
// mustBeDirectType - Hub methods must use the base 'stream' type and not be a derived class that just implements the 'stream' type | ||
// and 'stream' types from the client are allowed to inherit from accepted 'stream' types | ||
public static bool IsStreamingType([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.Interfaces)] Type type, bool mustBeDirectType = false) | ||
|
@@ -28,6 +32,9 @@ public static bool IsStreamingType([DynamicallyAccessedMembers(DynamicallyAccess | |
{ | ||
if (nullableType.IsGenericType && nullableType.GetGenericTypeDefinition() == typeof(ChannelReader<>)) | ||
{ | ||
Debug.Assert(nullableType.GetGenericArguments().Length == 1); | ||
|
||
_streamTypeLookup.GetOrAdd(type, nullableType.GetGenericArguments()[0]); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we keep the cache, we should use it for repeated calls to |
||
return true; | ||
} | ||
|
||
|
@@ -59,4 +66,7 @@ public static bool IsIAsyncEnumerable([DynamicallyAccessedMembers(DynamicallyAcc | |
} | ||
}); | ||
} | ||
|
||
public static bool TryGetStreamType(Type stream, [NotNullWhen(true)] out Type? streamType) | ||
=> _streamTypeLookup.TryGetValue(stream, out streamType); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This seems fragile because it will give a false negative if we don't call |
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this is the only place we use the
_streamTypeLookup
cache, we might as well cache the closedMethodInfo
returned byMakGenericMethod
or better yet theFunc<ConnectionState, string, ChannelReader<T>, CancellationTokenSource, Task>
we build from a compiledExpression
. Since we're just trying to get the dependency update merged, we can just forget the cache for now.