public static async Task <MqConsumerExecutedResult> InvokeAsync(MqConsumerExecutor consumerExecutor, string msgJson) { if (consumerExecutor == null) { throw new ArgumentException("consumerExecutor不能为空"); } if (string.IsNullOrWhiteSpace(msgJson)) { throw new ArgumentException("msgJson不能为空"); } var instance = GetInstance(consumerExecutor); if (instance == null) { throw new ArgumentException("MqConsumerExecutor Instance不能为空"); } var parameters = consumerExecutor.Parameters; var executeParameters = new object[parameters.Count]; for (int i = 0; i < parameters.Count; i++) { var parameter = parameters[i]; object value = null; if (parameter.ParameterType.IsValueType) { value = Activator.CreateInstance(parameter.ParameterType); } else { if (parameter.ParameterType.Name.IndexOf(nameof(MqMessage <object>), StringComparison.OrdinalIgnoreCase) > -1) { value = JsonConvert.DeserializeObject(msgJson, parameter.ParameterType); } } executeParameters[i] = value; } var executor = ObjectMethodExecutor.Create(consumerExecutor.MethodInfo, consumerExecutor.TypeInfo); var executedResult = await ExecuteWithParameterAsync(executor, instance, executeParameters); var consumerExecutedResult = executedResult as MqConsumerExecutedResult; return(consumerExecutedResult); }
private static object GetInstance(MqConsumerExecutor consumerExecutor) { var instance = EasyIocContainer.GetInstance <IMqConsumer>(consumerExecutor.TypeInfo.Name); return(instance); }