|
8 | 8 | using System.Collections.Generic;
|
9 | 9 | using System.Linq;
|
10 | 10 | using System.Reflection;
|
| 11 | +using System.Text.Json; |
11 | 12 | using System.Threading.Tasks;
|
12 | 13 |
|
13 | 14 | #nullable enable
|
@@ -122,7 +123,10 @@ internal async Task OnIncomingApplicationMessage(IServiceProvider svcProvider, I
|
122 | 123 |
|
123 | 124 | try
|
124 | 125 | {
|
125 |
| - paramArray = parameters.Select(p => MatchParameterOrThrow(p, routeContext.Parameters)).ToArray(); |
| 126 | + paramArray = parameters.Select(p => |
| 127 | + MatchParameterOrThrow(p, routeContext.Parameters, controllerContext, svcProvider) |
| 128 | + ) |
| 129 | + .ToArray(); |
126 | 130 |
|
127 | 131 | await HandlerInvoker(routeContext.Handler, classInstance, paramArray).ConfigureAwait(false);
|
128 | 132 | }
|
@@ -174,8 +178,20 @@ private static Task HandlerInvoker(MethodInfo method, object instance, object?[]
|
174 | 178 | throw new InvalidOperationException($"Unsupported Action return type \"{method.ReturnType}\" on method {method.DeclaringType.FullName}.{method.Name}. Only void and {nameof(Task)} are allowed.");
|
175 | 179 | }
|
176 | 180 |
|
177 |
| - private static object? MatchParameterOrThrow(ParameterInfo param, IReadOnlyDictionary<string, object> availableParmeters) |
| 181 | + private static object? MatchParameterOrThrow(ParameterInfo param, |
| 182 | + IReadOnlyDictionary<string, object> availableParmeters, MqttControllerContext controllerContext, |
| 183 | + IServiceProvider serviceProvider) |
178 | 184 | {
|
| 185 | + if (param.IsDefined(typeof(FromPayloadAttribute), false)) |
| 186 | + { |
| 187 | + JsonSerializerOptions? defaultOptions = |
| 188 | + serviceProvider.GetService<MqttDefaultJsonOptions>()?.SerializerOptions; |
| 189 | + return JsonSerializer.Deserialize(controllerContext.MqttContext.ApplicationMessage.Payload, |
| 190 | + param.ParameterType, |
| 191 | + defaultOptions |
| 192 | + ); |
| 193 | + } |
| 194 | + |
179 | 195 | if (!availableParmeters.TryGetValue(param.Name, out object? value))
|
180 | 196 | {
|
181 | 197 | if (param.IsOptional)
|
|
0 commit comments