diff --git a/src/MassTransit/Initializers/PropertyConverters/ListPropertyConverter.cs b/src/MassTransit/Initializers/PropertyConverters/ListPropertyConverter.cs index d41c1b69ae1..6eecc794dab 100644 --- a/src/MassTransit/Initializers/PropertyConverters/ListPropertyConverter.cs +++ b/src/MassTransit/Initializers/PropertyConverters/ListPropertyConverter.cs @@ -10,7 +10,8 @@ public class ListPropertyConverter : IPropertyConverter, IEnumerable>, IPropertyConverter, IEnumerable>, IPropertyConverter, IEnumerable>, - IPropertyConverter, IEnumerable> + IPropertyConverter, IEnumerable>, + IPropertyConverter, IEnumerable> { Task> IPropertyConverter, IEnumerable>.Convert(InitializeContext context, IEnumerable input) @@ -64,6 +65,19 @@ public Task> Convert(InitializeContext contex return Task.FromResult(input.ToList()); } } + + Task> IPropertyConverter, IEnumerable>.Convert(InitializeContext context, IEnumerable input) + { + switch (input) + { + case null: + return TaskUtil.Default>(); + case ICollection list: + return Task.FromResult(list); + default: + return Task.FromResult>(input.ToList()); + } + } } @@ -71,7 +85,8 @@ public class ListPropertyConverter : IPropertyConverter, IEnumerable>, IPropertyConverter, IEnumerable>, IPropertyConverter, IEnumerable>, - IPropertyConverter, IEnumerable> + IPropertyConverter, IEnumerable>, + IPropertyConverter, IEnumerable> { readonly IPropertyConverter _converter; @@ -125,6 +140,21 @@ async Task> ConvertAsync() return ConvertAsync(); } + public Task> Convert(InitializeContext context, IEnumerable elements) + where T : class + { + Task> resultTask = ConvertSync(context, elements); + if (resultTask.Status == TaskStatus.RanToCompletion) + return Task.FromResult>(resultTask.Result); + + async Task> ConvertAsync() + { + return await resultTask.ConfigureAwait(false); + } + + return ConvertAsync(); + } + Task> IPropertyConverter, IEnumerable>.Convert(InitializeContext context, IEnumerable elements) {