- Sponsor
-
Notifications
You must be signed in to change notification settings - Fork 433
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Loading status checks…
Merge pull request #712 from Cysharp/feature/MoveDynamicClientFactory…
…Providers Move DynamicClientFactoryProviders to DynamicClient
- Loading branch information
Showing
19 changed files
with
198 additions
and
159 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
41 changes: 41 additions & 0 deletions
41
...ipts/MagicOnion/MagicOnion.Client/DynamicClient/DynamicMagicOnionClientFactoryProvider.cs
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,41 @@ | ||
using System; | ||
using System.Diagnostics.CodeAnalysis; | ||
|
||
namespace MagicOnion.Client.DynamicClient | ||
{ | ||
public class DynamicNotSupportedMagicOnionClientFactoryProvider : IMagicOnionClientFactoryProvider | ||
{ | ||
public static IMagicOnionClientFactoryProvider Instance { get; } = new DynamicNotSupportedMagicOnionClientFactoryProvider(); | ||
|
||
DynamicNotSupportedMagicOnionClientFactoryProvider() { } | ||
|
||
public bool TryGetFactory<T>([NotNullWhen(true)] out MagicOnionClientFactoryDelegate<T>? factory) where T : IService<T> | ||
{ | ||
throw new InvalidOperationException($"Unable to find a client factory of type '{typeof(T)}'. If the application is running on IL2CPP or AOT, dynamic code generation is not supported. Please use the code generator (moc)."); | ||
} | ||
} | ||
|
||
#if ((!ENABLE_IL2CPP || UNITY_EDITOR) && !NET_STANDARD_2_0) | ||
/// <summary> | ||
/// Provides to get a MagicOnionClient factory of the specified service type. The provider is backed by DynamicMagicOnionClientBuilder. | ||
/// </summary> | ||
public class DynamicMagicOnionClientFactoryProvider : IMagicOnionClientFactoryProvider | ||
{ | ||
public static IMagicOnionClientFactoryProvider Instance { get; } = new DynamicMagicOnionClientFactoryProvider(); | ||
|
||
DynamicMagicOnionClientFactoryProvider() { } | ||
|
||
public bool TryGetFactory<T>([NotNullWhen(true)] out MagicOnionClientFactoryDelegate<T>? factory) where T : IService<T> | ||
{ | ||
factory = Cache<T>.Factory; | ||
return true; | ||
} | ||
|
||
static class Cache<T> where T : IService<T> | ||
{ | ||
public static readonly MagicOnionClientFactoryDelegate<T> Factory | ||
= (clientOptions, serializerProvider) => (T)Activator.CreateInstance(DynamicClientBuilder<T>.ClientType, clientOptions, serializerProvider)!; | ||
} | ||
} | ||
#endif | ||
} |
11 changes: 11 additions & 0 deletions
11
...MagicOnion/MagicOnion.Client/DynamicClient/DynamicMagicOnionClientFactoryProvider.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
39 changes: 39 additions & 0 deletions
39
...ts/MagicOnion/MagicOnion.Client/DynamicClient/DynamicStreamingHubClientFactoryProvider.cs
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,39 @@ | ||
using System; | ||
using System.Diagnostics.CodeAnalysis; | ||
|
||
namespace MagicOnion.Client.DynamicClient | ||
{ | ||
public class DynamicNotSupportedStreamingHubClientFactoryProvider : IStreamingHubClientFactoryProvider | ||
{ | ||
public static IStreamingHubClientFactoryProvider Instance { get; } = new DynamicNotSupportedStreamingHubClientFactoryProvider(); | ||
|
||
DynamicNotSupportedStreamingHubClientFactoryProvider() { } | ||
|
||
public bool TryGetFactory<TStreamingHub, TReceiver>([NotNullWhen(true)] out StreamingHubClientFactoryDelegate<TStreamingHub, TReceiver>? factory) where TStreamingHub : IStreamingHub<TStreamingHub, TReceiver> | ||
{ | ||
throw new InvalidOperationException($"Unable to find a client factory of type '{typeof(TStreamingHub)}'. If the application is running on IL2CPP or AOT, dynamic code generation is not supported. Please use the code generator (moc)."); | ||
} | ||
} | ||
|
||
#if ((!ENABLE_IL2CPP || UNITY_EDITOR) && !NET_STANDARD_2_0) | ||
public class DynamicStreamingHubClientFactoryProvider : IStreamingHubClientFactoryProvider | ||
{ | ||
public static IStreamingHubClientFactoryProvider Instance { get; } = new DynamicStreamingHubClientFactoryProvider(); | ||
|
||
DynamicStreamingHubClientFactoryProvider() { } | ||
|
||
public bool TryGetFactory<TStreamingHub, TReceiver>([NotNullWhen(true)] out StreamingHubClientFactoryDelegate<TStreamingHub, TReceiver>? factory) where TStreamingHub : IStreamingHub<TStreamingHub, TReceiver> | ||
{ | ||
factory = Cache<TStreamingHub, TReceiver>.Factory; | ||
return true; | ||
} | ||
|
||
static class Cache<TStreamingHub, TReceiver> where TStreamingHub : IStreamingHub<TStreamingHub, TReceiver> | ||
{ | ||
public static readonly StreamingHubClientFactoryDelegate<TStreamingHub, TReceiver> Factory | ||
= (callInvoker, receiver, host, callOptions, serializerProvider, logger) | ||
=> (TStreamingHub)Activator.CreateInstance(DynamicStreamingHubClientBuilder<TStreamingHub, TReceiver>.ClientType, callInvoker, host, callOptions, serializerProvider, logger)!; | ||
} | ||
} | ||
#endif | ||
} |
11 changes: 11 additions & 0 deletions
11
...gicOnion/MagicOnion.Client/DynamicClient/DynamicStreamingHubClientFactoryProvider.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
41 changes: 41 additions & 0 deletions
41
src/MagicOnion.Client/DynamicClient/DynamicMagicOnionClientFactoryProvider.cs
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,41 @@ | ||
using System; | ||
using System.Diagnostics.CodeAnalysis; | ||
|
||
namespace MagicOnion.Client.DynamicClient | ||
{ | ||
public class DynamicNotSupportedMagicOnionClientFactoryProvider : IMagicOnionClientFactoryProvider | ||
{ | ||
public static IMagicOnionClientFactoryProvider Instance { get; } = new DynamicNotSupportedMagicOnionClientFactoryProvider(); | ||
|
||
DynamicNotSupportedMagicOnionClientFactoryProvider() { } | ||
|
||
public bool TryGetFactory<T>([NotNullWhen(true)] out MagicOnionClientFactoryDelegate<T>? factory) where T : IService<T> | ||
{ | ||
throw new InvalidOperationException($"Unable to find a client factory of type '{typeof(T)}'. If the application is running on IL2CPP or AOT, dynamic code generation is not supported. Please use the code generator (moc)."); | ||
} | ||
} | ||
|
||
#if ((!ENABLE_IL2CPP || UNITY_EDITOR) && !NET_STANDARD_2_0) | ||
/// <summary> | ||
/// Provides to get a MagicOnionClient factory of the specified service type. The provider is backed by DynamicMagicOnionClientBuilder. | ||
/// </summary> | ||
public class DynamicMagicOnionClientFactoryProvider : IMagicOnionClientFactoryProvider | ||
{ | ||
public static IMagicOnionClientFactoryProvider Instance { get; } = new DynamicMagicOnionClientFactoryProvider(); | ||
|
||
DynamicMagicOnionClientFactoryProvider() { } | ||
|
||
public bool TryGetFactory<T>([NotNullWhen(true)] out MagicOnionClientFactoryDelegate<T>? factory) where T : IService<T> | ||
{ | ||
factory = Cache<T>.Factory; | ||
return true; | ||
} | ||
|
||
static class Cache<T> where T : IService<T> | ||
{ | ||
public static readonly MagicOnionClientFactoryDelegate<T> Factory | ||
= (clientOptions, serializerProvider) => (T)Activator.CreateInstance(DynamicClientBuilder<T>.ClientType, clientOptions, serializerProvider)!; | ||
} | ||
} | ||
#endif | ||
} |
39 changes: 39 additions & 0 deletions
39
src/MagicOnion.Client/DynamicClient/DynamicStreamingHubClientFactoryProvider.cs
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,39 @@ | ||
using System; | ||
using System.Diagnostics.CodeAnalysis; | ||
|
||
namespace MagicOnion.Client.DynamicClient | ||
{ | ||
public class DynamicNotSupportedStreamingHubClientFactoryProvider : IStreamingHubClientFactoryProvider | ||
{ | ||
public static IStreamingHubClientFactoryProvider Instance { get; } = new DynamicNotSupportedStreamingHubClientFactoryProvider(); | ||
|
||
DynamicNotSupportedStreamingHubClientFactoryProvider() { } | ||
|
||
public bool TryGetFactory<TStreamingHub, TReceiver>([NotNullWhen(true)] out StreamingHubClientFactoryDelegate<TStreamingHub, TReceiver>? factory) where TStreamingHub : IStreamingHub<TStreamingHub, TReceiver> | ||
{ | ||
throw new InvalidOperationException($"Unable to find a client factory of type '{typeof(TStreamingHub)}'. If the application is running on IL2CPP or AOT, dynamic code generation is not supported. Please use the code generator (moc)."); | ||
} | ||
} | ||
|
||
#if ((!ENABLE_IL2CPP || UNITY_EDITOR) && !NET_STANDARD_2_0) | ||
public class DynamicStreamingHubClientFactoryProvider : IStreamingHubClientFactoryProvider | ||
{ | ||
public static IStreamingHubClientFactoryProvider Instance { get; } = new DynamicStreamingHubClientFactoryProvider(); | ||
|
||
DynamicStreamingHubClientFactoryProvider() { } | ||
|
||
public bool TryGetFactory<TStreamingHub, TReceiver>([NotNullWhen(true)] out StreamingHubClientFactoryDelegate<TStreamingHub, TReceiver>? factory) where TStreamingHub : IStreamingHub<TStreamingHub, TReceiver> | ||
{ | ||
factory = Cache<TStreamingHub, TReceiver>.Factory; | ||
return true; | ||
} | ||
|
||
static class Cache<TStreamingHub, TReceiver> where TStreamingHub : IStreamingHub<TStreamingHub, TReceiver> | ||
{ | ||
public static readonly StreamingHubClientFactoryDelegate<TStreamingHub, TReceiver> Factory | ||
= (callInvoker, receiver, host, callOptions, serializerProvider, logger) | ||
=> (TStreamingHub)Activator.CreateInstance(DynamicStreamingHubClientBuilder<TStreamingHub, TReceiver>.ClientType, callInvoker, host, callOptions, serializerProvider, logger)!; | ||
} | ||
} | ||
#endif | ||
} |
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
Oops, something went wrong.