diff --git a/src/Cuemon.Core/ActionFactory.cs b/src/Cuemon.Core/ActionFactory.cs index 11f1c0254..ecca65a15 100644 --- a/src/Cuemon.Core/ActionFactory.cs +++ b/src/Cuemon.Core/ActionFactory.cs @@ -486,7 +486,7 @@ public ActionFactory(Action method, TTuple tuple) : this(method, tuple, internal ActionFactory(Action method, TTuple tuple, Delegate originalDelegate) : base(tuple, originalDelegate != null) { Method = method; - DelegateInfo = Infrastructure.ResolveDelegateInfo(method, originalDelegate); + DelegateInfo = Decorator.RawEnclose(method).ResolveDelegateInfo(originalDelegate); } /// diff --git a/src/Cuemon.Core/Decorator.cs b/src/Cuemon.Core/Decorator.cs index e4a9295b6..e7d9864f2 100644 --- a/src/Cuemon.Core/Decorator.cs +++ b/src/Cuemon.Core/Decorator.cs @@ -29,6 +29,18 @@ public static Decorator Enclose(T inner, bool throwIfNull = true) return new Decorator(inner, throwIfNull); } + /// + /// Encloses the specified so that it can be extended by non-common extension methods. + /// + /// The type of the to wrap for non-common extension methods. + /// The object to extend for non-common extension methods. + /// An instance of . + /// Unlike , this method does not perform a null-check when wrapping the value. + public static Decorator RawEnclose(T inner) + { + return Enclose(inner, false); + } + /// /// Encloses the specified so that it can be extended by both common and non-common extension methods. /// diff --git a/src/Cuemon.Core/Extensions/ByteArrayDecoratorExtensions.cs b/src/Cuemon.Core/Extensions/ByteArrayDecoratorExtensions.cs index 4488b8ac9..2051e97bb 100644 --- a/src/Cuemon.Core/Extensions/ByteArrayDecoratorExtensions.cs +++ b/src/Cuemon.Core/Extensions/ByteArrayDecoratorExtensions.cs @@ -1,7 +1,5 @@ using System; using System.IO; -using System.Threading; -using System.Threading.Tasks; using Cuemon.Text; namespace Cuemon @@ -44,29 +42,5 @@ public static Stream ToStream(this IDecorator decorator) return ms; }); } - - /// - /// Converts the enclosed of the specified to its equivalent representation. - /// - /// The to extend. - /// The token to monitor for cancellation requests. The default value is . - /// A task that represents the asynchronous operation. The task result contains a that is equivalent to the enclosed of the specified . - /// - /// cannot be null. - /// - public static Task ToStreamAsync(this IDecorator decorator, CancellationToken ct = default) - { - Validator.ThrowIfNull(decorator); - return Patterns.SafeInvokeAsync(() => new MemoryStream(decorator.Inner.Length), async (ms, cti) => - { -#if NETSTANDARD - await ms.WriteAsync(decorator.Inner, 0, decorator.Inner.Length, cti).ConfigureAwait(false); -#else - await ms.WriteAsync(decorator.Inner.AsMemory(0, decorator.Inner.Length), cti).ConfigureAwait(false); -#endif - ms.Position = 0; - return ms; - }, ct); - } } } diff --git a/src/Cuemon.Core/Extensions/DelegateDecoratorExtensions.cs b/src/Cuemon.Core/Extensions/DelegateDecoratorExtensions.cs new file mode 100644 index 000000000..abe2e4fcb --- /dev/null +++ b/src/Cuemon.Core/Extensions/DelegateDecoratorExtensions.cs @@ -0,0 +1,27 @@ +using System; +using System.Reflection; + +namespace Cuemon +{ + /// + /// Extension methods for the hidden behind the interface. + /// + /// + /// + public static class DelegateDecoratorExtensions + { + /// + /// Resolves the of the specified delegate or the enclosed of the . + /// + /// The to extend. + /// The original delegate to resolve the method information from. + /// The of the specified delegate or the enclosed of the ; otherwise, null if both are null. + public static MethodInfo ResolveDelegateInfo(this IDecorator decorator, Delegate original) + { + var wrapper = decorator?.Inner; + if (original != null) { return original.GetMethodInfo(); } + if (wrapper != null) { return wrapper.GetMethodInfo(); } + return null; + } + } +} diff --git a/src/Cuemon.Core/Extensions/StringDecoratorExtensions.cs b/src/Cuemon.Core/Extensions/StringDecoratorExtensions.cs index 1b3120777..0e5bab3b5 100644 --- a/src/Cuemon.Core/Extensions/StringDecoratorExtensions.cs +++ b/src/Cuemon.Core/Extensions/StringDecoratorExtensions.cs @@ -5,7 +5,6 @@ using System.IO; using System.Linq; using System.Text; -using System.Threading.Tasks; using Cuemon.Text; namespace Cuemon @@ -149,36 +148,6 @@ public static Stream ToStream(this IDecorator decorator, Action - /// Converts the enclosed of the specified to a . - /// - /// The to extend. - /// The which may be configured. - /// A task that represents the asynchronous operation. The task result contains a containing the result of the enclosed of the specified . - /// will be initialized with and . - /// - /// cannot be null. - /// - /// - /// was initialized with an invalid . - /// - public static Task ToStreamAsync(this IDecorator decorator, Action setup = null) - { - Validator.ThrowIfNull(decorator); - var options = Patterns.Configure(setup); - return Patterns.SafeInvokeAsync(() => new MemoryStream(), async (ms, token) => - { - var bytes = Convertible.GetBytes(decorator.Inner, Patterns.ConfigureExchange(setup)); -#if NETSTANDARD - await ms.WriteAsync(bytes, 0, bytes.Length, token).ConfigureAwait(false); -#else - await ms.WriteAsync(bytes.AsMemory(0, bytes.Length), token).ConfigureAwait(false); -#endif - ms.Position = 0; - return ms; - }, options.CancellationToken); - } - /// /// Converts the enclosed of the specified to its equivalent representation. /// diff --git a/src/Cuemon.Core/FuncFactory.cs b/src/Cuemon.Core/FuncFactory.cs index afb0d6b59..d89be450d 100644 --- a/src/Cuemon.Core/FuncFactory.cs +++ b/src/Cuemon.Core/FuncFactory.cs @@ -506,7 +506,7 @@ public FuncFactory(Func method, TTuple tuple) : this(method, tu internal FuncFactory(Func method, TTuple tuple, Delegate originalDelegate) : base(tuple, originalDelegate != null) { Method = method; - DelegateInfo = Infrastructure.ResolveDelegateInfo(method, originalDelegate); + DelegateInfo = Decorator.RawEnclose(method).ResolveDelegateInfo(originalDelegate); } /// diff --git a/src/Cuemon.Core/GlobalSuppressions.cs b/src/Cuemon.Core/GlobalSuppressions.cs index 70def55c9..8444fea6f 100644 --- a/src/Cuemon.Core/GlobalSuppressions.cs +++ b/src/Cuemon.Core/GlobalSuppressions.cs @@ -118,49 +118,6 @@ [assembly: SuppressMessage("Major Code Smell", "S107:Methods should not have too many parameters", Justification = "By design; think about it as a Tuple/Variadic - but for Func delegates.", Scope = "member", Target = "~M:Cuemon.FuncFactory.Create``8(System.Func{``0,``1,``2,``3,``4,``5,``6,``7},``0,``1,``2,``3,``4,``5,``6)~Cuemon.FuncFactory{Cuemon.Template{``0,``1,``2,``3,``4,``5,``6},``7}")] [assembly: SuppressMessage("Major Code Smell", "S107:Methods should not have too many parameters", Justification = "By design; think about it as a Tuple/Variadic - but for Func delegates.", Scope = "member", Target = "~M:Cuemon.FuncFactory.Create``9(System.Func{``0,``1,``2,``3,``4,``5,``6,``7,``8},``0,``1,``2,``3,``4,``5,``6,``7)~Cuemon.FuncFactory{Cuemon.Template{``0,``1,``2,``3,``4,``5,``6,``7},``8}")] [assembly: SuppressMessage("Major Code Smell", "S2436:Types and methods should not have too many generic parameters", Justification = "By design; think about it as a Tuple/Variadic - but for Func delegates.", Scope = "member", Target = "~M:Cuemon.FuncFactory.Create``9(System.Func{``0,``1,``2,``3,``4,``5,``6,``7,``8},``0,``1,``2,``3,``4,``5,``6,``7)~Cuemon.FuncFactory{Cuemon.Template{``0,``1,``2,``3,``4,``5,``6,``7},``8}")] -[assembly: SuppressMessage("Major Code Smell", "S107:Methods should not have too many parameters", Justification = "By design; think about it as a Tuple/Variadic - but for Task based Func delegates.", Scope = "member", Target = "~M:Cuemon.TaskActionFactory.Create``10(System.Func{``0,``1,``2,``3,``4,``5,``6,``7,``8,``9,System.Threading.CancellationToken,System.Threading.Tasks.Task},``0,``1,``2,``3,``4,``5,``6,``7,``8,``9)~Cuemon.TaskActionFactory{Cuemon.Template{``0,``1,``2,``3,``4,``5,``6,``7,``8,``9}}")] -[assembly: SuppressMessage("Major Code Smell", "S2436:Types and methods should not have too many generic parameters", Justification = "By design; think about it as a Tuple/Variadic - but for Task based Func delegates.", Scope = "member", Target = "~M:Cuemon.TaskActionFactory.Create``10(System.Func{``0,``1,``2,``3,``4,``5,``6,``7,``8,``9,System.Threading.CancellationToken,System.Threading.Tasks.Task},``0,``1,``2,``3,``4,``5,``6,``7,``8,``9)~Cuemon.TaskActionFactory{Cuemon.Template{``0,``1,``2,``3,``4,``5,``6,``7,``8,``9}}")] -[assembly: SuppressMessage("Major Code Smell", "S2436:Types and methods should not have too many generic parameters", Justification = "By design; think about it as a Tuple/Variadic - but for Task based Func delegates.", Scope = "member", Target = "~M:Cuemon.TaskActionFactory.Create``11(System.Func{``0,``1,``2,``3,``4,``5,``6,``7,``8,``9,``10,System.Threading.CancellationToken,System.Threading.Tasks.Task},``0,``1,``2,``3,``4,``5,``6,``7,``8,``9,``10)~Cuemon.TaskActionFactory{Cuemon.Template{``0,``1,``2,``3,``4,``5,``6,``7,``8,``9,``10}}")] -[assembly: SuppressMessage("Major Code Smell", "S107:Methods should not have too many parameters", Justification = "By design; think about it as a Tuple/Variadic - but for Task based Func delegates.", Scope = "member", Target = "~M:Cuemon.TaskActionFactory.Create``11(System.Func{``0,``1,``2,``3,``4,``5,``6,``7,``8,``9,``10,System.Threading.CancellationToken,System.Threading.Tasks.Task},``0,``1,``2,``3,``4,``5,``6,``7,``8,``9,``10)~Cuemon.TaskActionFactory{Cuemon.Template{``0,``1,``2,``3,``4,``5,``6,``7,``8,``9,``10}}")] -[assembly: SuppressMessage("Major Code Smell", "S2436:Types and methods should not have too many generic parameters", Justification = "By design; think about it as a Tuple/Variadic - but for Task based Func delegates.", Scope = "member", Target = "~M:Cuemon.TaskActionFactory.Create``12(System.Func{``0,``1,``2,``3,``4,``5,``6,``7,``8,``9,``10,``11,System.Threading.CancellationToken,System.Threading.Tasks.Task},``0,``1,``2,``3,``4,``5,``6,``7,``8,``9,``10,``11)~Cuemon.TaskActionFactory{Cuemon.Template{``0,``1,``2,``3,``4,``5,``6,``7,``8,``9,``10,``11}}")] -[assembly: SuppressMessage("Major Code Smell", "S107:Methods should not have too many parameters", Justification = "By design; think about it as a Tuple/Variadic - but for Task based Func delegates.", Scope = "member", Target = "~M:Cuemon.TaskActionFactory.Create``12(System.Func{``0,``1,``2,``3,``4,``5,``6,``7,``8,``9,``10,``11,System.Threading.CancellationToken,System.Threading.Tasks.Task},``0,``1,``2,``3,``4,``5,``6,``7,``8,``9,``10,``11)~Cuemon.TaskActionFactory{Cuemon.Template{``0,``1,``2,``3,``4,``5,``6,``7,``8,``9,``10,``11}}")] -[assembly: SuppressMessage("Major Code Smell", "S107:Methods should not have too many parameters", Justification = "By design; think about it as a Tuple/Variadic - but for Task based Func delegates.", Scope = "member", Target = "~M:Cuemon.TaskActionFactory.Create``13(System.Func{``0,``1,``2,``3,``4,``5,``6,``7,``8,``9,``10,``11,``12,System.Threading.CancellationToken,System.Threading.Tasks.Task},``0,``1,``2,``3,``4,``5,``6,``7,``8,``9,``10,``11,``12)~Cuemon.TaskActionFactory{Cuemon.Template{``0,``1,``2,``3,``4,``5,``6,``7,``8,``9,``10,``11,``12}}")] -[assembly: SuppressMessage("Major Code Smell", "S2436:Types and methods should not have too many generic parameters", Justification = "By design; think about it as a Tuple/Variadic - but for Task based Func delegates.", Scope = "member", Target = "~M:Cuemon.TaskActionFactory.Create``13(System.Func{``0,``1,``2,``3,``4,``5,``6,``7,``8,``9,``10,``11,``12,System.Threading.CancellationToken,System.Threading.Tasks.Task},``0,``1,``2,``3,``4,``5,``6,``7,``8,``9,``10,``11,``12)~Cuemon.TaskActionFactory{Cuemon.Template{``0,``1,``2,``3,``4,``5,``6,``7,``8,``9,``10,``11,``12}}")] -[assembly: SuppressMessage("Major Code Smell", "S107:Methods should not have too many parameters", Justification = "By design; think about it as a Tuple/Variadic - but for Task based Func delegates.", Scope = "member", Target = "~M:Cuemon.TaskActionFactory.Create``14(System.Func{``0,``1,``2,``3,``4,``5,``6,``7,``8,``9,``10,``11,``12,``13,System.Threading.CancellationToken,System.Threading.Tasks.Task},``0,``1,``2,``3,``4,``5,``6,``7,``8,``9,``10,``11,``12,``13)~Cuemon.TaskActionFactory{Cuemon.Template{``0,``1,``2,``3,``4,``5,``6,``7,``8,``9,``10,``11,``12,``13}}")] -[assembly: SuppressMessage("Major Code Smell", "S2436:Types and methods should not have too many generic parameters", Justification = "By design; think about it as a Tuple/Variadic - but for Task based Func delegates.", Scope = "member", Target = "~M:Cuemon.TaskActionFactory.Create``14(System.Func{``0,``1,``2,``3,``4,``5,``6,``7,``8,``9,``10,``11,``12,``13,System.Threading.CancellationToken,System.Threading.Tasks.Task},``0,``1,``2,``3,``4,``5,``6,``7,``8,``9,``10,``11,``12,``13)~Cuemon.TaskActionFactory{Cuemon.Template{``0,``1,``2,``3,``4,``5,``6,``7,``8,``9,``10,``11,``12,``13}}")] -[assembly: SuppressMessage("Major Code Smell", "S2436:Types and methods should not have too many generic parameters", Justification = "By design; think about it as a Tuple/Variadic - but for Task based Func delegates.", Scope = "member", Target = "~M:Cuemon.TaskActionFactory.Create``15(System.Func{``0,``1,``2,``3,``4,``5,``6,``7,``8,``9,``10,``11,``12,``13,``14,System.Threading.CancellationToken,System.Threading.Tasks.Task},``0,``1,``2,``3,``4,``5,``6,``7,``8,``9,``10,``11,``12,``13,``14)~Cuemon.TaskActionFactory{Cuemon.Template{``0,``1,``2,``3,``4,``5,``6,``7,``8,``9,``10,``11,``12,``13,``14}}")] -[assembly: SuppressMessage("Major Code Smell", "S107:Methods should not have too many parameters", Justification = "By design; think about it as a Tuple/Variadic - but for Task based Func delegates.", Scope = "member", Target = "~M:Cuemon.TaskActionFactory.Create``15(System.Func{``0,``1,``2,``3,``4,``5,``6,``7,``8,``9,``10,``11,``12,``13,``14,System.Threading.CancellationToken,System.Threading.Tasks.Task},``0,``1,``2,``3,``4,``5,``6,``7,``8,``9,``10,``11,``12,``13,``14)~Cuemon.TaskActionFactory{Cuemon.Template{``0,``1,``2,``3,``4,``5,``6,``7,``8,``9,``10,``11,``12,``13,``14}}")] -[assembly: SuppressMessage("Major Code Smell", "S2436:Types and methods should not have too many generic parameters", Justification = "By design; think about it as a Tuple/Variadic - but for Task based Func delegates.", Scope = "member", Target = "~M:Cuemon.TaskActionFactory.Create``4(System.Func{``0,``1,``2,``3,System.Threading.CancellationToken,System.Threading.Tasks.Task},``0,``1,``2,``3)~Cuemon.TaskActionFactory{Cuemon.Template{``0,``1,``2,``3}}")] -[assembly: SuppressMessage("Major Code Smell", "S2436:Types and methods should not have too many generic parameters", Justification = "By design; think about it as a Tuple/Variadic - but for Task based Func delegates.", Scope = "member", Target = "~M:Cuemon.TaskActionFactory.Create``5(System.Func{``0,``1,``2,``3,``4,System.Threading.CancellationToken,System.Threading.Tasks.Task},``0,``1,``2,``3,``4)~Cuemon.TaskActionFactory{Cuemon.Template{``0,``1,``2,``3,``4}}")] -[assembly: SuppressMessage("Major Code Smell", "S2436:Types and methods should not have too many generic parameters", Justification = "By design; think about it as a Tuple/Variadic - but for Task based Func delegates.", Scope = "member", Target = "~M:Cuemon.TaskActionFactory.Create``6(System.Func{``0,``1,``2,``3,``4,``5,System.Threading.CancellationToken,System.Threading.Tasks.Task},``0,``1,``2,``3,``4,``5)~Cuemon.TaskActionFactory{Cuemon.Template{``0,``1,``2,``3,``4,``5}}")] -[assembly: SuppressMessage("Major Code Smell", "S2436:Types and methods should not have too many generic parameters", Justification = "By design; think about it as a Tuple/Variadic - but for Task based Func delegates.", Scope = "member", Target = "~M:Cuemon.TaskActionFactory.Create``7(System.Func{``0,``1,``2,``3,``4,``5,``6,System.Threading.CancellationToken,System.Threading.Tasks.Task},``0,``1,``2,``3,``4,``5,``6)~Cuemon.TaskActionFactory{Cuemon.Template{``0,``1,``2,``3,``4,``5,``6}}")] -[assembly: SuppressMessage("Major Code Smell", "S107:Methods should not have too many parameters", Justification = "By design; think about it as a Tuple/Variadic - but for Task based Func delegates.", Scope = "member", Target = "~M:Cuemon.TaskActionFactory.Create``7(System.Func{``0,``1,``2,``3,``4,``5,``6,System.Threading.CancellationToken,System.Threading.Tasks.Task},``0,``1,``2,``3,``4,``5,``6)~Cuemon.TaskActionFactory{Cuemon.Template{``0,``1,``2,``3,``4,``5,``6}}")] -[assembly: SuppressMessage("Major Code Smell", "S2436:Types and methods should not have too many generic parameters", Justification = "By design; think about it as a Tuple/Variadic - but for Task based Func delegates.", Scope = "member", Target = "~M:Cuemon.TaskActionFactory.Create``8(System.Func{``0,``1,``2,``3,``4,``5,``6,``7,System.Threading.CancellationToken,System.Threading.Tasks.Task},``0,``1,``2,``3,``4,``5,``6,``7)~Cuemon.TaskActionFactory{Cuemon.Template{``0,``1,``2,``3,``4,``5,``6,``7}}")] -[assembly: SuppressMessage("Major Code Smell", "S107:Methods should not have too many parameters", Justification = "By design; think about it as a Tuple/Variadic - but for Task based Func delegates.", Scope = "member", Target = "~M:Cuemon.TaskActionFactory.Create``8(System.Func{``0,``1,``2,``3,``4,``5,``6,``7,System.Threading.CancellationToken,System.Threading.Tasks.Task},``0,``1,``2,``3,``4,``5,``6,``7)~Cuemon.TaskActionFactory{Cuemon.Template{``0,``1,``2,``3,``4,``5,``6,``7}}")] -[assembly: SuppressMessage("Major Code Smell", "S107:Methods should not have too many parameters", Justification = "By design; think about it as a Tuple/Variadic - but for Task based Func delegates.", Scope = "member", Target = "~M:Cuemon.TaskActionFactory.Create``9(System.Func{``0,``1,``2,``3,``4,``5,``6,``7,``8,System.Threading.CancellationToken,System.Threading.Tasks.Task},``0,``1,``2,``3,``4,``5,``6,``7,``8)~Cuemon.TaskActionFactory{Cuemon.Template{``0,``1,``2,``3,``4,``5,``6,``7,``8}}")] -[assembly: SuppressMessage("Major Code Smell", "S2436:Types and methods should not have too many generic parameters", Justification = "By design; think about it as a Tuple/Variadic - but for Task based Func delegates.", Scope = "member", Target = "~M:Cuemon.TaskActionFactory.Create``9(System.Func{``0,``1,``2,``3,``4,``5,``6,``7,``8,System.Threading.CancellationToken,System.Threading.Tasks.Task},``0,``1,``2,``3,``4,``5,``6,``7,``8)~Cuemon.TaskActionFactory{Cuemon.Template{``0,``1,``2,``3,``4,``5,``6,``7,``8}}")] -[assembly: SuppressMessage("Major Code Smell", "S107:Methods should not have too many parameters", Justification = "By design; think about it as a Tuple/Variadic - but for Task based Func delegates.", Scope = "member", Target = "~M:Cuemon.TaskFuncFactory.Create``10(System.Func{``0,``1,``2,``3,``4,``5,``6,``7,``8,System.Threading.CancellationToken,System.Threading.Tasks.Task{``9}},``0,``1,``2,``3,``4,``5,``6,``7,``8)~Cuemon.TaskFuncFactory{Cuemon.Template{``0,``1,``2,``3,``4,``5,``6,``7,``8},``9}")] -[assembly: SuppressMessage("Major Code Smell", "S107:Methods should not have too many parameters", Justification = "By design; think about it as a Tuple/Variadic - but for Task based Func delegates.", Scope = "member", Target = "~M:Cuemon.TaskFuncFactory.Create``11(System.Func{``0,``1,``2,``3,``4,``5,``6,``7,``8,``9,System.Threading.CancellationToken,System.Threading.Tasks.Task{``10}},``0,``1,``2,``3,``4,``5,``6,``7,``8,``9)~Cuemon.TaskFuncFactory{Cuemon.Template{``0,``1,``2,``3,``4,``5,``6,``7,``8,``9},``10}")] -[assembly: SuppressMessage("Major Code Smell", "S107:Methods should not have too many parameters", Justification = "By design; think about it as a Tuple/Variadic - but for Task based Func delegates.", Scope = "member", Target = "~M:Cuemon.TaskFuncFactory.Create``12(System.Func{``0,``1,``2,``3,``4,``5,``6,``7,``8,``9,``10,System.Threading.CancellationToken,System.Threading.Tasks.Task{``11}},``0,``1,``2,``3,``4,``5,``6,``7,``8,``9,``10)~Cuemon.TaskFuncFactory{Cuemon.Template{``0,``1,``2,``3,``4,``5,``6,``7,``8,``9,``10},``11}")] -[assembly: SuppressMessage("Major Code Smell", "S107:Methods should not have too many parameters", Justification = "By design; think about it as a Tuple/Variadic - but for Task based Func delegates.", Scope = "member", Target = "~M:Cuemon.TaskFuncFactory.Create``13(System.Func{``0,``1,``2,``3,``4,``5,``6,``7,``8,``9,``10,``11,System.Threading.CancellationToken,System.Threading.Tasks.Task{``12}},``0,``1,``2,``3,``4,``5,``6,``7,``8,``9,``10,``11)~Cuemon.TaskFuncFactory{Cuemon.Template{``0,``1,``2,``3,``4,``5,``6,``7,``8,``9,``10,``11},``12}")] -[assembly: SuppressMessage("Major Code Smell", "S107:Methods should not have too many parameters", Justification = "By design; think about it as a Tuple/Variadic - but for Task based Func delegates.", Scope = "member", Target = "~M:Cuemon.TaskFuncFactory.Create``14(System.Func{``0,``1,``2,``3,``4,``5,``6,``7,``8,``9,``10,``11,``12,System.Threading.CancellationToken,System.Threading.Tasks.Task{``13}},``0,``1,``2,``3,``4,``5,``6,``7,``8,``9,``10,``11,``12)~Cuemon.TaskFuncFactory{Cuemon.Template{``0,``1,``2,``3,``4,``5,``6,``7,``8,``9,``10,``11,``12},``13}")] -[assembly: SuppressMessage("Major Code Smell", "S107:Methods should not have too many parameters", Justification = "By design; think about it as a Tuple/Variadic - but for Task based Func delegates.", Scope = "member", Target = "~M:Cuemon.TaskFuncFactory.Create``15(System.Func{``0,``1,``2,``3,``4,``5,``6,``7,``8,``9,``10,``11,``12,``13,System.Threading.CancellationToken,System.Threading.Tasks.Task{``14}},``0,``1,``2,``3,``4,``5,``6,``7,``8,``9,``10,``11,``12,``13)~Cuemon.TaskFuncFactory{Cuemon.Template{``0,``1,``2,``3,``4,``5,``6,``7,``8,``9,``10,``11,``12,``13},``14}")] -[assembly: SuppressMessage("Major Code Smell", "S107:Methods should not have too many parameters", Justification = "By design; think about it as a Tuple/Variadic - but for Task based Func delegates.", Scope = "member", Target = "~M:Cuemon.TaskFuncFactory.Create``16(System.Func{``0,``1,``2,``3,``4,``5,``6,``7,``8,``9,``10,``11,``12,``13,``14,System.Threading.CancellationToken,System.Threading.Tasks.Task{``15}},``0,``1,``2,``3,``4,``5,``6,``7,``8,``9,``10,``11,``12,``13,``14)~Cuemon.TaskFuncFactory{Cuemon.Template{``0,``1,``2,``3,``4,``5,``6,``7,``8,``9,``10,``11,``12,``13,``14},``15}")] -[assembly: SuppressMessage("Major Code Smell", "S107:Methods should not have too many parameters", Justification = "By design; think about it as a Tuple/Variadic - but for Task based Func delegates.", Scope = "member", Target = "~M:Cuemon.TaskFuncFactory.Create``8(System.Func{``0,``1,``2,``3,``4,``5,``6,System.Threading.CancellationToken,System.Threading.Tasks.Task{``7}},``0,``1,``2,``3,``4,``5,``6)~Cuemon.TaskFuncFactory{Cuemon.Template{``0,``1,``2,``3,``4,``5,``6},``7}")] -[assembly: SuppressMessage("Major Code Smell", "S107:Methods should not have too many parameters", Justification = "By design; think about it as a Tuple/Variadic - but for Task based Func delegates.", Scope = "member", Target = "~M:Cuemon.TaskFuncFactory.Create``9(System.Func{``0,``1,``2,``3,``4,``5,``6,``7,System.Threading.CancellationToken,System.Threading.Tasks.Task{``8}},``0,``1,``2,``3,``4,``5,``6,``7)~Cuemon.TaskFuncFactory{Cuemon.Template{``0,``1,``2,``3,``4,``5,``6,``7},``8}")] -[assembly: SuppressMessage("Major Code Smell", "S2436:Types and methods should not have too many generic parameters", Justification = "By design; think about it as a Tuple/Variadic - but for Task based Func delegates.", Scope = "member", Target = "~M:Cuemon.TaskFuncFactory.Create``10(System.Func{``0,``1,``2,``3,``4,``5,``6,``7,``8,System.Threading.CancellationToken,System.Threading.Tasks.Task{``9}},``0,``1,``2,``3,``4,``5,``6,``7,``8)~Cuemon.TaskFuncFactory{Cuemon.Template{``0,``1,``2,``3,``4,``5,``6,``7,``8},``9}")] -[assembly: SuppressMessage("Major Code Smell", "S2436:Types and methods should not have too many generic parameters", Justification = "By design; think about it as a Tuple/Variadic - but for Task based Func delegates.", Scope = "member", Target = "~M:Cuemon.TaskFuncFactory.Create``11(System.Func{``0,``1,``2,``3,``4,``5,``6,``7,``8,``9,System.Threading.CancellationToken,System.Threading.Tasks.Task{``10}},``0,``1,``2,``3,``4,``5,``6,``7,``8,``9)~Cuemon.TaskFuncFactory{Cuemon.Template{``0,``1,``2,``3,``4,``5,``6,``7,``8,``9},``10}")] -[assembly: SuppressMessage("Major Code Smell", "S2436:Types and methods should not have too many generic parameters", Justification = "By design; think about it as a Tuple/Variadic - but for Task based Func delegates.", Scope = "member", Target = "~M:Cuemon.TaskFuncFactory.Create``12(System.Func{``0,``1,``2,``3,``4,``5,``6,``7,``8,``9,``10,System.Threading.CancellationToken,System.Threading.Tasks.Task{``11}},``0,``1,``2,``3,``4,``5,``6,``7,``8,``9,``10)~Cuemon.TaskFuncFactory{Cuemon.Template{``0,``1,``2,``3,``4,``5,``6,``7,``8,``9,``10},``11}")] -[assembly: SuppressMessage("Major Code Smell", "S2436:Types and methods should not have too many generic parameters", Justification = "By design; think about it as a Tuple/Variadic - but for Task based Func delegates.", Scope = "member", Target = "~M:Cuemon.TaskFuncFactory.Create``13(System.Func{``0,``1,``2,``3,``4,``5,``6,``7,``8,``9,``10,``11,System.Threading.CancellationToken,System.Threading.Tasks.Task{``12}},``0,``1,``2,``3,``4,``5,``6,``7,``8,``9,``10,``11)~Cuemon.TaskFuncFactory{Cuemon.Template{``0,``1,``2,``3,``4,``5,``6,``7,``8,``9,``10,``11},``12}")] -[assembly: SuppressMessage("Major Code Smell", "S2436:Types and methods should not have too many generic parameters", Justification = "By design; think about it as a Tuple/Variadic - but for Task based Func delegates.", Scope = "member", Target = "~M:Cuemon.TaskFuncFactory.Create``14(System.Func{``0,``1,``2,``3,``4,``5,``6,``7,``8,``9,``10,``11,``12,System.Threading.CancellationToken,System.Threading.Tasks.Task{``13}},``0,``1,``2,``3,``4,``5,``6,``7,``8,``9,``10,``11,``12)~Cuemon.TaskFuncFactory{Cuemon.Template{``0,``1,``2,``3,``4,``5,``6,``7,``8,``9,``10,``11,``12},``13}")] -[assembly: SuppressMessage("Major Code Smell", "S2436:Types and methods should not have too many generic parameters", Justification = "By design; think about it as a Tuple/Variadic - but for Task based Func delegates.", Scope = "member", Target = "~M:Cuemon.TaskFuncFactory.Create``15(System.Func{``0,``1,``2,``3,``4,``5,``6,``7,``8,``9,``10,``11,``12,``13,System.Threading.CancellationToken,System.Threading.Tasks.Task{``14}},``0,``1,``2,``3,``4,``5,``6,``7,``8,``9,``10,``11,``12,``13)~Cuemon.TaskFuncFactory{Cuemon.Template{``0,``1,``2,``3,``4,``5,``6,``7,``8,``9,``10,``11,``12,``13},``14}")] -[assembly: SuppressMessage("Major Code Smell", "S2436:Types and methods should not have too many generic parameters", Justification = "By design; think about it as a Tuple/Variadic - but for Task based Func delegates.", Scope = "member", Target = "~M:Cuemon.TaskFuncFactory.Create``16(System.Func{``0,``1,``2,``3,``4,``5,``6,``7,``8,``9,``10,``11,``12,``13,``14,System.Threading.CancellationToken,System.Threading.Tasks.Task{``15}},``0,``1,``2,``3,``4,``5,``6,``7,``8,``9,``10,``11,``12,``13,``14)~Cuemon.TaskFuncFactory{Cuemon.Template{``0,``1,``2,``3,``4,``5,``6,``7,``8,``9,``10,``11,``12,``13,``14},``15}")] -[assembly: SuppressMessage("Major Code Smell", "S2436:Types and methods should not have too many generic parameters", Justification = "By design; think about it as a Tuple/Variadic - but for Task based Func delegates.", Scope = "member", Target = "~M:Cuemon.TaskFuncFactory.Create``4(System.Func{``0,``1,``2,System.Threading.CancellationToken,System.Threading.Tasks.Task{``3}},``0,``1,``2)~Cuemon.TaskFuncFactory{Cuemon.Template{``0,``1,``2},``3}")] -[assembly: SuppressMessage("Major Code Smell", "S2436:Types and methods should not have too many generic parameters", Justification = "By design; think about it as a Tuple/Variadic - but for Task based Func delegates.", Scope = "member", Target = "~M:Cuemon.TaskFuncFactory.Create``5(System.Func{``0,``1,``2,``3,System.Threading.CancellationToken,System.Threading.Tasks.Task{``4}},``0,``1,``2,``3)~Cuemon.TaskFuncFactory{Cuemon.Template{``0,``1,``2,``3},``4}")] -[assembly: SuppressMessage("Major Code Smell", "S2436:Types and methods should not have too many generic parameters", Justification = "By design; think about it as a Tuple/Variadic - but for Task based Func delegates.", Scope = "member", Target = "~M:Cuemon.TaskFuncFactory.Create``6(System.Func{``0,``1,``2,``3,``4,System.Threading.CancellationToken,System.Threading.Tasks.Task{``5}},``0,``1,``2,``3,``4)~Cuemon.TaskFuncFactory{Cuemon.Template{``0,``1,``2,``3,``4},``5}")] -[assembly: SuppressMessage("Major Code Smell", "S2436:Types and methods should not have too many generic parameters", Justification = "By design; think about it as a Tuple/Variadic - but for Task based Func delegates.", Scope = "member", Target = "~M:Cuemon.TaskFuncFactory.Create``7(System.Func{``0,``1,``2,``3,``4,``5,System.Threading.CancellationToken,System.Threading.Tasks.Task{``6}},``0,``1,``2,``3,``4,``5)~Cuemon.TaskFuncFactory{Cuemon.Template{``0,``1,``2,``3,``4,``5},``6}")] -[assembly: SuppressMessage("Major Code Smell", "S2436:Types and methods should not have too many generic parameters", Justification = "By design; think about it as a Tuple/Variadic - but for Task based Func delegates.", Scope = "member", Target = "~M:Cuemon.TaskFuncFactory.Create``8(System.Func{``0,``1,``2,``3,``4,``5,``6,System.Threading.CancellationToken,System.Threading.Tasks.Task{``7}},``0,``1,``2,``3,``4,``5,``6)~Cuemon.TaskFuncFactory{Cuemon.Template{``0,``1,``2,``3,``4,``5,``6},``7}")] -[assembly: SuppressMessage("Major Code Smell", "S2436:Types and methods should not have too many generic parameters", Justification = "By design; think about it as a Tuple/Variadic - but for Task based Func delegates.", Scope = "member", Target = "~M:Cuemon.TaskFuncFactory.Create``9(System.Func{``0,``1,``2,``3,``4,``5,``6,``7,System.Threading.CancellationToken,System.Threading.Tasks.Task{``8}},``0,``1,``2,``3,``4,``5,``6,``7)~Cuemon.TaskFuncFactory{Cuemon.Template{``0,``1,``2,``3,``4,``5,``6,``7},``8}")] [assembly: SuppressMessage("Major Code Smell", "S107:Methods should not have too many parameters", Justification = "A Func designed for the Tester pattern. Microsoft allows 17 arguments in there Func impl; so do i here.", Scope = "type", Target = "~T:Cuemon.TesterFunc`10")] [assembly: SuppressMessage("Major Code Smell", "S107:Methods should not have too many parameters", Justification = "A Func designed for the Tester pattern. Microsoft allows 17 arguments in there Func impl; so do i here.", Scope = "type", Target = "~T:Cuemon.TesterFunc`11")] [assembly: SuppressMessage("Major Code Smell", "S107:Methods should not have too many parameters", Justification = "A Func designed for the Tester pattern. Microsoft allows 17 arguments in there Func impl; so do i here.", Scope = "type", Target = "~T:Cuemon.TesterFunc`12")] @@ -198,14 +155,9 @@ [assembly: SuppressMessage("Major Code Smell", "S2436:Types and methods should not have too many generic parameters", Justification = "By design; think about it as a Tuple/Variadic - but for TesterFunc delegates.", Scope = "member", Target = "~M:Cuemon.TesterFuncFactory.Create``9(Cuemon.TesterFunc{``0,``1,``2,``3,``4,``5,``6,``7,``8},``0,``1,``2,``3,``4,``5,``6)~Cuemon.TesterFuncFactory{Cuemon.Template{``0,``1,``2,``3,``4,``5,``6},``7,``8}")] [assembly: SuppressMessage("Major Code Smell", "S2436:Types and methods should not have too many generic parameters", Justification = "By design; think about it as a Tuple/Variadic - but for TesterFunc delegates.", Scope = "type", Target = "~T:Cuemon.TesterFuncFactory`3")] [assembly: SuppressMessage("Major Code Smell", "S107:Methods should not have too many parameters", Justification = "By design; allow up till 5 arguments (more under certain conditions)..", Scope = "member", Target = "~M:Cuemon.Patterns.SafeInvoke``6(System.Func{``5},System.Func{``5,``0,``1,``2,``3,``4,``5},``0,``1,``2,``3,``4,System.Action{System.Exception,``0,``1,``2,``3,``4})~``5")] -[assembly: SuppressMessage("Major Code Smell", "S107:Methods should not have too many parameters", Justification = "By design; allow up till 5 arguments (more under certain conditions)..", Scope = "member", Target = "~M:Cuemon.Patterns.SafeInvokeAsync``5(System.Func{``4},System.Func{``4,``0,``1,``2,``3,System.Threading.CancellationToken,System.Threading.Tasks.Task{``4}},``0,``1,``2,``3,System.Threading.CancellationToken,System.Func{System.Exception,``0,``1,``2,``3,System.Threading.CancellationToken,System.Threading.Tasks.Task})~System.Threading.Tasks.Task{``4}")] -[assembly: SuppressMessage("Major Code Smell", "S107:Methods should not have too many parameters", Justification = "By design; allow up till 5 arguments (more under certain conditions)..", Scope = "member", Target = "~M:Cuemon.Patterns.SafeInvokeAsync``6(System.Func{``5},System.Func{``5,``0,``1,``2,``3,``4,System.Threading.CancellationToken,System.Threading.Tasks.Task{``5}},``0,``1,``2,``3,``4,System.Threading.CancellationToken,System.Func{System.Exception,``0,``1,``2,``3,``4,System.Threading.CancellationToken,System.Threading.Tasks.Task})~System.Threading.Tasks.Task{``5}")] [assembly: SuppressMessage("Major Code Smell", "S2436:Types and methods should not have too many generic parameters", Justification = "By design; allow up till 5 arguments (more under certain conditions)..", Scope = "member", Target = "~M:Cuemon.Patterns.SafeInvoke``4(System.Func{``3},System.Func{``3,``0,``1,``2,``3},``0,``1,``2,System.Action{System.Exception,``0,``1,``2})~``3")] [assembly: SuppressMessage("Major Code Smell", "S2436:Types and methods should not have too many generic parameters", Justification = "By design; allow up till 5 arguments (more under certain conditions)..", Scope = "member", Target = "~M:Cuemon.Patterns.SafeInvoke``5(System.Func{``4},System.Func{``4,``0,``1,``2,``3,``4},``0,``1,``2,``3,System.Action{System.Exception,``0,``1,``2,``3})~``4")] [assembly: SuppressMessage("Major Code Smell", "S2436:Types and methods should not have too many generic parameters", Justification = "By design; allow up till 5 arguments (more under certain conditions)..", Scope = "member", Target = "~M:Cuemon.Patterns.SafeInvoke``6(System.Func{``5},System.Func{``5,``0,``1,``2,``3,``4,``5},``0,``1,``2,``3,``4,System.Action{System.Exception,``0,``1,``2,``3,``4})~``5")] -[assembly: SuppressMessage("Major Code Smell", "S2436:Types and methods should not have too many generic parameters", Justification = "By design; allow up till 5 arguments (more under certain conditions)..", Scope = "member", Target = "~M:Cuemon.Patterns.SafeInvokeAsync``4(System.Func{``3},System.Func{``3,``0,``1,``2,System.Threading.CancellationToken,System.Threading.Tasks.Task{``3}},``0,``1,``2,System.Threading.CancellationToken,System.Func{System.Exception,``0,``1,``2,System.Threading.CancellationToken,System.Threading.Tasks.Task})~System.Threading.Tasks.Task{``3}")] -[assembly: SuppressMessage("Major Code Smell", "S2436:Types and methods should not have too many generic parameters", Justification = "By design; allow up till 5 arguments (more under certain conditions)..", Scope = "member", Target = "~M:Cuemon.Patterns.SafeInvokeAsync``5(System.Func{``4},System.Func{``4,``0,``1,``2,``3,System.Threading.CancellationToken,System.Threading.Tasks.Task{``4}},``0,``1,``2,``3,System.Threading.CancellationToken,System.Func{System.Exception,``0,``1,``2,``3,System.Threading.CancellationToken,System.Threading.Tasks.Task})~System.Threading.Tasks.Task{``4}")] -[assembly: SuppressMessage("Major Code Smell", "S2436:Types and methods should not have too many generic parameters", Justification = "By design; allow up till 5 arguments (more under certain conditions)..", Scope = "member", Target = "~M:Cuemon.Patterns.SafeInvokeAsync``6(System.Func{``5},System.Func{``5,``0,``1,``2,``3,``4,System.Threading.CancellationToken,System.Threading.Tasks.Task{``5}},``0,``1,``2,``3,``4,System.Threading.CancellationToken,System.Func{System.Exception,``0,``1,``2,``3,``4,System.Threading.CancellationToken,System.Threading.Tasks.Task})~System.Threading.Tasks.Task{``5}")] [assembly: SuppressMessage("Major Code Smell", "S2436:Types and methods should not have too many generic parameters", Justification = "By design; allow up till 5 arguments (more under certain conditions).", Scope = "member", Target = "~M:Cuemon.Condition.FlipFlop``4(System.Boolean,System.Action{``0,``1,``2,``3},System.Action{``0,``1,``2,``3},``0,``1,``2,``3)")] [assembly: SuppressMessage("Major Code Smell", "S2436:Types and methods should not have too many generic parameters", Justification = "By design; allow up till 5 arguments (more under certain conditions).", Scope = "member", Target = "~M:Cuemon.Condition.FlipFlop``5(System.Boolean,System.Action{``0,``1,``2,``3,``4},System.Action{``0,``1,``2,``3,``4},``0,``1,``2,``3,``4)")] [assembly: SuppressMessage("Major Code Smell", "S107:Methods should not have too many parameters", Justification = "By design; allow up till 5 arguments (more under certain conditions).", Scope = "member", Target = "~M:Cuemon.Condition.FlipFlop``5(System.Boolean,System.Action{``0,``1,``2,``3,``4},System.Action{``0,``1,``2,``3,``4},``0,``1,``2,``3,``4)")] @@ -217,15 +169,7 @@ [assembly: SuppressMessage("Major Code Smell", "S2436:Types and methods should not have too many generic parameters", Justification = "By design; allow up till 5 arguments (more under certain conditions).", Scope = "member", Target = "~M:Cuemon.Reflection.ActivatorFactory.CreateInstance``5(``0,``1,``2,``3,System.Action{Cuemon.Reflection.ActivatorOptions})~``4")] [assembly: SuppressMessage("Major Code Smell", "S2436:Types and methods should not have too many generic parameters", Justification = "By design; allow up till 5 arguments (more under certain conditions).", Scope = "member", Target = "~M:Cuemon.Reflection.ActivatorFactory.CreateInstance``6(``0,``1,``2,``3,``4,System.Action{Cuemon.Reflection.ActivatorOptions})~``5")] [assembly: SuppressMessage("Critical Code Smell", "S3776:Cognitive Complexity of methods should not be too high", Justification = "By design; although a good rule, this is the exception to the rule.", Scope = "member", Target = "~M:Cuemon.Calculator.CalculateCore``1(``0,``0,Cuemon.AssignmentOperator)~``0")] -[assembly: SuppressMessage("Design", "CA1068:CancellationToken parameters must come last", Justification = "CancellationToken (ct) is more likely to be used than function delegate catcher, hence optimized for flow and consistency.", Scope = "member", Target = "~M:Cuemon.Patterns.SafeInvokeAsync``1(System.Func{``0},System.Func{``0,System.Threading.CancellationToken,System.Threading.Tasks.Task{``0}},System.Threading.CancellationToken,System.Func{System.Exception,System.Threading.CancellationToken,System.Threading.Tasks.Task})~System.Threading.Tasks.Task{``0}")] -[assembly: SuppressMessage("Design", "CA1068:CancellationToken parameters must come last", Justification = "CancellationToken (ct) is more likely to be used than function delegate catcher, hence optimized for flow and consistency.", Scope = "member", Target = "~M:Cuemon.Patterns.SafeInvokeAsync``2(System.Func{``1},System.Func{``1,``0,System.Threading.CancellationToken,System.Threading.Tasks.Task{``1}},``0,System.Threading.CancellationToken,System.Func{System.Exception,``0,System.Threading.CancellationToken,System.Threading.Tasks.Task})~System.Threading.Tasks.Task{``1}")] -[assembly: SuppressMessage("Design", "CA1068:CancellationToken parameters must come last", Justification = "CancellationToken (ct) is more likely to be used than function delegate catcher, hence optimized for flow and consistency.", Scope = "member", Target = "~M:Cuemon.Patterns.SafeInvokeAsync``3(System.Func{``2},System.Func{``2,``0,``1,System.Threading.CancellationToken,System.Threading.Tasks.Task{``2}},``0,``1,System.Threading.CancellationToken,System.Func{System.Exception,``0,``1,System.Threading.CancellationToken,System.Threading.Tasks.Task})~System.Threading.Tasks.Task{``2}")] -[assembly: SuppressMessage("Design", "CA1068:CancellationToken parameters must come last", Justification = "CancellationToken (ct) is more likely to be used than function delegate catcher, hence optimized for flow and consistency.", Scope = "member", Target = "~M:Cuemon.Patterns.SafeInvokeAsync``4(System.Func{``3},System.Func{``3,``0,``1,``2,System.Threading.CancellationToken,System.Threading.Tasks.Task{``3}},``0,``1,``2,System.Threading.CancellationToken,System.Func{System.Exception,``0,``1,``2,System.Threading.CancellationToken,System.Threading.Tasks.Task})~System.Threading.Tasks.Task{``3}")] -[assembly: SuppressMessage("Design", "CA1068:CancellationToken parameters must come last", Justification = "CancellationToken (ct) is more likely to be used than function delegate catcher, hence optimized for flow and consistency.", Scope = "member", Target = "~M:Cuemon.Patterns.SafeInvokeAsync``5(System.Func{``4},System.Func{``4,``0,``1,``2,``3,System.Threading.CancellationToken,System.Threading.Tasks.Task{``4}},``0,``1,``2,``3,System.Threading.CancellationToken,System.Func{System.Exception,``0,``1,``2,``3,System.Threading.CancellationToken,System.Threading.Tasks.Task})~System.Threading.Tasks.Task{``4}")] -[assembly: SuppressMessage("Design", "CA1068:CancellationToken parameters must come last", Justification = "CancellationToken (ct) is more likely to be used than function delegate catcher, hence optimized for flow and consistency.", Scope = "member", Target = "~M:Cuemon.Patterns.SafeInvokeAsync``6(System.Func{``5},System.Func{``5,``0,``1,``2,``3,``4,System.Threading.CancellationToken,System.Threading.Tasks.Task{``5}},``0,``1,``2,``3,``4,System.Threading.CancellationToken,System.Func{System.Exception,``0,``1,``2,``3,``4,System.Threading.CancellationToken,System.Threading.Tasks.Task})~System.Threading.Tasks.Task{``5}")] [assembly: SuppressMessage("Major Code Smell", "S3925:\"ISerializable\" should be implemented correctly", Justification = "Out of scope.", Scope = "type", Target = "~T:Cuemon.Collections.DataPairDictionary")] -[assembly: SuppressMessage("Performance", "CA1835:Prefer the 'Memory'-based overloads for 'ReadAsync' and 'WriteAsync'", Justification = "Already fixed for .NET 5, but SonarCloud cannot figure out multiple framework support, eg. NETStandard 2.", Scope = "member", Target = "~M:Cuemon.ByteArrayDecoratorExtensions.ToStreamAsync(Cuemon.IDecorator{System.Byte[]},System.Threading.CancellationToken)~System.Threading.Tasks.Task{System.IO.Stream}")] -[assembly: SuppressMessage("Performance", "CA1835:Prefer the 'Memory'-based overloads for 'ReadAsync' and 'WriteAsync'", Justification = "Already fixed for .NET 5, but SonarCloud cannot figure out multiple framework support, eg. NETStandard 2.", Scope = "member", Target = "~M:Cuemon.StringDecoratorExtensions.ToStreamAsync(Cuemon.IDecorator{System.String},System.Action{Cuemon.Text.AsyncEncodingOptions})~System.Threading.Tasks.Task{System.IO.Stream}")] [assembly: SuppressMessage("Major Code Smell", "S3011:Reflection should not be used to increase accessibility of classes, methods, or fields", Justification = "By design.", Scope = "member", Target = "~F:Cuemon.Reflection.MemberReflection.Everything")] [assembly: SuppressMessage("Major Code Smell", "S3011:Reflection should not be used to increase accessibility of classes, methods, or fields", Justification = "By design.", Scope = "member", Target = "~M:Cuemon.Reflection.MemberReflection.#ctor(System.Action{Cuemon.Reflection.MemberReflectionOptions})")] [assembly: SuppressMessage("Major Code Smell", "S3011:Reflection should not be used to increase accessibility of classes, methods, or fields", Justification = "By design.", Scope = "member", Target = "~M:Cuemon.Globalization.ResourceAttribute.GetString(System.String)~System.String")] diff --git a/src/Cuemon.Core/Infrastructure.cs b/src/Cuemon.Core/Infrastructure.cs index 7dbeeb0e2..0bee963ba 100644 --- a/src/Cuemon.Core/Infrastructure.cs +++ b/src/Cuemon.Core/Infrastructure.cs @@ -1,20 +1,12 @@ -using System; -using System.Reflection; +using System.Reflection; namespace Cuemon { internal static class Infrastructure { - internal static MethodInfo ResolveDelegateInfo(Delegate wrapper, Delegate original) - { - if (original != null) { return original.GetMethodInfo(); } - if (wrapper != null) { return wrapper.GetMethodInfo(); } - return null; - } - internal static object DefaultPropertyValueResolver(object source, PropertyInfo pi) { return source == null ? null : pi.GetValue(source, null); } } -} \ No newline at end of file +} diff --git a/src/Cuemon.Core/Patterns.cs b/src/Cuemon.Core/Patterns.cs index 480fcc031..83b81e792 100644 --- a/src/Cuemon.Core/Patterns.cs +++ b/src/Cuemon.Core/Patterns.cs @@ -1,8 +1,6 @@ using System; using System.Linq; using System.Runtime.InteropServices; -using System.Threading; -using System.Threading.Tasks; using Cuemon.Configuration; namespace Cuemon @@ -210,7 +208,7 @@ public static Action ConfigureRevertExchange(TSource /// The type of the return value of the function delegate . /// The function delegate that initializes an object implementing the interface. /// The function delegate that is used to ensure that operations performed on abides CA2000. - /// The delegate that will handle any exceptions might thrown by . + /// The delegate that will handle any exceptions that might have been thrown by . /// The return value of the function delegate if the operations succeeded; otherwise null if the operation failed. public static TResult SafeInvoke(Func initializer, Func tester, Action catcher = null) where TResult : class, IDisposable { @@ -229,7 +227,7 @@ public static TResult SafeInvoke(Func initializer, FuncThe function delegate that initializes an object implementing the interface. /// The function delegate that is used to ensure that operations performed on abides CA2000. /// The parameter of the function delegate and delegate . - /// The delegate that will handle any exceptions might thrown by . + /// The delegate that will handle any exceptions that might have been thrown by . /// The return value of the function delegate if the operations succeeded; otherwise null if the operation failed. public static TResult SafeInvoke(Func initializer, Func tester, T arg, Action catcher = null) where TResult : class, IDisposable { @@ -250,7 +248,7 @@ public static TResult SafeInvoke(Func initializer, FuncThe function delegate that is used to ensure that operations performed on abides CA2000. /// The first parameter of the function delegate and delegate . /// The second parameter of the function delegate and delegate . - /// The delegate that will handle any exceptions might thrown by . + /// The delegate that will handle any exceptions that might have been thrown by . /// The return value of the function delegate if the operations succeeded; otherwise null if the operation failed. public static TResult SafeInvoke(Func initializer, Func tester, T1 arg1, T2 arg2, Action catcher = null) where TResult : class, IDisposable { @@ -273,7 +271,7 @@ public static TResult SafeInvoke(Func initializer, Fun /// The first parameter of the function delegate and delegate . /// The second parameter of the function delegate and delegate . /// The third parameter of the function delegate and delegate . - /// The delegate that will handle any exceptions might thrown by . + /// The delegate that will handle any exceptions that might have been thrown by . /// The return value of the function delegate if the operations succeeded; otherwise null if the operation failed. public static TResult SafeInvoke(Func initializer, Func tester, T1 arg1, T2 arg2, T3 arg3, Action catcher = null) where TResult : class, IDisposable { @@ -298,7 +296,7 @@ public static TResult SafeInvoke(Func initializer, /// The second parameter of the function delegate and delegate . /// The third parameter of the function delegate and delegate . /// The fourth parameter of the function delegate and delegate . - /// The delegate that will handle any exceptions might thrown by . + /// The delegate that will handle any exceptions that might have been thrown by . /// The return value of the function delegate if the operations succeeded; otherwise null if the operation failed. public static TResult SafeInvoke(Func initializer, Func tester, T1 arg1, T2 arg2, T3 arg3, T4 arg4, Action catcher = null) where TResult : class, IDisposable { @@ -325,7 +323,7 @@ public static TResult SafeInvoke(Func initiali /// The third parameter of the function delegate and delegate . /// The fourth parameter of the function delegate and delegate . /// The fifth parameter of the function delegate and delegate . - /// The delegate that will handle any exceptions might thrown by . + /// The delegate that will handle any exceptions that might have been thrown by . /// The return value of the function delegate if the operations succeeded; otherwise null if the operation failed. public static TResult SafeInvoke(Func initializer, Func tester, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, Action catcher = null) where TResult : class, IDisposable { @@ -336,144 +334,6 @@ public static TResult SafeInvoke(Func init return SafeInvokeCore(f1, initializer, f2); } - /// - /// Provides a generic way to abide the rule description of CA2000 (Dispose objects before losing scope). - /// - /// The type of the return value of the function delegate . - /// The function delegate that initializes an object implementing the interface. - /// The function delegate that is used to ensure that operations performed on abides CA2000. - /// The token to monitor for cancellation requests. The default value is . - /// The function delegate that will handle any exceptions might thrown by . - /// A task that represents the asynchronous operation. The task result contains the return value of the function delegate if the operations succeeded; otherwise null if the operation failed. - public static Task SafeInvokeAsync(Func initializer, Func> tester, CancellationToken ct = default, Func catcher = null) where TResult : class, IDisposable - { - Validator.ThrowIfNull(initializer); - Validator.ThrowIfNull(tester); - var f1 = TaskFuncFactory.Create(tester, default); - var f2 = TaskActionFactory.Create(catcher, default); - return SafeInvokeAsyncCore(f1, initializer, f2, ct); - } - - /// - /// Provides a generic way to abide the rule description of CA2000 (Dispose objects before losing scope). - /// - /// The type of the parameter of the function delegate and delegate . - /// The type of the return value of the function delegate . - /// The function delegate that initializes an object implementing the interface. - /// The function delegate that is used to ensure that operations performed on abides CA2000. - /// The parameter of the function delegate and delegate . - /// The token to monitor for cancellation requests. The default value is . - /// The function delegate that will handle any exceptions might thrown by . - /// A task that represents the asynchronous operation. The task result contains the return value of the function delegate if the operations succeeded; otherwise null if the operation failed. - public static Task SafeInvokeAsync(Func initializer, Func> tester, T arg, CancellationToken ct = default, Func catcher = null) where TResult : class, IDisposable - { - Validator.ThrowIfNull(initializer); - Validator.ThrowIfNull(tester); - var f1 = TaskFuncFactory.Create(tester, default, arg); - var f2 = TaskActionFactory.Create(catcher, default, arg); - return SafeInvokeAsyncCore(f1, initializer, f2, ct); - } - - /// - /// Provides a generic way to abide the rule description of CA2000 (Dispose objects before losing scope). - /// - /// The type of the first parameter of the function delegate and delegate . - /// The type of the second parameter of the function delegate and delegate . - /// The type of the return value of the function delegate . - /// The function delegate that initializes an object implementing the interface. - /// The function delegate that is used to ensure that operations performed on abides CA2000. - /// The first parameter of the function delegate and delegate . - /// The second parameter of the function delegate and delegate . - /// The token to monitor for cancellation requests. The default value is . - /// The function delegate that will handle any exceptions might thrown by . - /// A task that represents the asynchronous operation. The task result contains the return value of the function delegate if the operations succeeded; otherwise null if the operation failed. - public static Task SafeInvokeAsync(Func initializer, Func> tester, T1 arg1, T2 arg2, CancellationToken ct = default, Func catcher = null) where TResult : class, IDisposable - { - Validator.ThrowIfNull(initializer); - Validator.ThrowIfNull(tester); - var f1 = TaskFuncFactory.Create(tester, default, arg1, arg2); - var f2 = TaskActionFactory.Create(catcher, default, arg1, arg2); - return SafeInvokeAsyncCore(f1, initializer, f2, ct); - } - - /// - /// Provides a generic way to abide the rule description of CA2000 (Dispose objects before losing scope). - /// - /// The type of the first parameter of the function delegate and delegate . - /// The type of the second parameter of the function delegate and delegate . - /// The type of the third parameter of the function delegate and delegate . - /// The type of the return value of the function delegate . - /// The function delegate that initializes an object implementing the interface. - /// The function delegate that is used to ensure that operations performed on abides CA2000. - /// The first parameter of the function delegate and delegate . - /// The second parameter of the function delegate and delegate . - /// The third parameter of the function delegate and delegate . - /// The token to monitor for cancellation requests. The default value is . - /// The function delegate that will handle any exceptions might thrown by . - /// A task that represents the asynchronous operation. The task result contains the return value of the function delegate if the operations succeeded; otherwise null if the operation failed. - public static Task SafeInvokeAsync(Func initializer, Func> tester, T1 arg1, T2 arg2, T3 arg3, CancellationToken ct = default, Func catcher = null) where TResult : class, IDisposable - { - Validator.ThrowIfNull(initializer); - Validator.ThrowIfNull(tester); - var f1 = TaskFuncFactory.Create(tester, default, arg1, arg2, arg3); - var f2 = TaskActionFactory.Create(catcher, default, arg1, arg2, arg3); - return SafeInvokeAsyncCore(f1, initializer, f2, ct); - } - - /// - /// Provides a generic way to abide the rule description of CA2000 (Dispose objects before losing scope). - /// - /// The type of the first parameter of the function delegate and delegate . - /// The type of the second parameter of the function delegate and delegate . - /// The type of the third parameter of the function delegate and delegate . - /// The type of the fourth parameter of the function delegate and delegate . - /// The type of the return value of the function delegate . - /// The function delegate that initializes an object implementing the interface. - /// The function delegate that is used to ensure that operations performed on abides CA2000. - /// The first parameter of the function delegate and delegate . - /// The second parameter of the function delegate and delegate . - /// The third parameter of the function delegate and delegate . - /// The fourth parameter of the function delegate and delegate . - /// The token to monitor for cancellation requests. The default value is . - /// The function delegate that will handle any exceptions might thrown by . - /// A task that represents the asynchronous operation. The task result contains the return value of the function delegate if the operations succeeded; otherwise null if the operation failed. - public static Task SafeInvokeAsync(Func initializer, Func> tester, T1 arg1, T2 arg2, T3 arg3, T4 arg4, CancellationToken ct = default, Func catcher = null) where TResult : class, IDisposable - { - Validator.ThrowIfNull(initializer); - Validator.ThrowIfNull(tester); - var f1 = TaskFuncFactory.Create(tester, default, arg1, arg2, arg3, arg4); - var f2 = TaskActionFactory.Create(catcher, default, arg1, arg2, arg3, arg4); - return SafeInvokeAsyncCore(f1, initializer, f2, ct); - } - - /// - /// Provides a generic way to abide the rule description of CA2000 (Dispose objects before losing scope). - /// - /// The type of the first parameter of the function delegate and delegate . - /// The type of the second parameter of the function delegate and delegate . - /// The type of the third parameter of the function delegate and delegate . - /// The type of the fourth parameter of the function delegate and delegate . - /// The type of the fifth parameter of the function delegate and delegate . - /// The type of the return value of the function delegate . - /// The function delegate that initializes an object implementing the interface. - /// The function delegate that is used to ensure that operations performed on abides CA2000. - /// The first parameter of the function delegate and delegate . - /// The second parameter of the function delegate and delegate . - /// The third parameter of the function delegate and delegate . - /// The fourth parameter of the function delegate and delegate . - /// The fifth parameter of the function delegate and delegate . - /// The token to monitor for cancellation requests. The default value is . - /// The function delegate that will handle any exceptions might thrown by . - /// A task that represents the asynchronous operation. The task result contains the return value of the function delegate if the operations succeeded; otherwise null if the operation failed. - public static Task SafeInvokeAsync(Func initializer, Func> tester, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, CancellationToken ct = default, Func catcher = null) where TResult : class, IDisposable - { - Validator.ThrowIfNull(initializer); - Validator.ThrowIfNull(tester); - var f1 = TaskFuncFactory.Create(tester, default, arg1, arg2, arg3, arg4, arg5); - var f2 = TaskActionFactory.Create(catcher, default, arg1, arg2, arg3, arg4, arg5); - return SafeInvokeAsyncCore(f1, initializer, f2, ct); - } - private static TResult SafeInvokeCore(FuncFactory testerFactory, Func initializer, ActionFactory catcherFactory) where TResult : class, IDisposable where TTester : Template @@ -505,37 +365,5 @@ private static TResult SafeInvokeCore(FuncFactory SafeInvokeAsyncCore(TaskFuncFactory testerFactory, Func initializer, TaskActionFactory catcherFactory, CancellationToken ct) - where TResult : class, IDisposable - where TTester : Template - where TCatcher : Template - { - TResult result = null; - try - { - testerFactory.GenericArguments.Arg1 = initializer(); - testerFactory.GenericArguments.Arg1 = await testerFactory.ExecuteMethodAsync(ct).ConfigureAwait(false); - result = testerFactory.GenericArguments.Arg1; - testerFactory.GenericArguments.Arg1 = null; - } - catch (Exception e) - { - if (!catcherFactory.HasDelegate) - { - throw; - } - else - { - catcherFactory.GenericArguments.Arg1 = e; - await catcherFactory.ExecuteMethodAsync(ct).ConfigureAwait(false); - } - } - finally - { - testerFactory.GenericArguments.Arg1?.Dispose(); - } - return result; - } } } diff --git a/src/Cuemon.Core/TesterFuncFactory.cs b/src/Cuemon.Core/TesterFuncFactory.cs index 68cb80c84..f43b51d40 100644 --- a/src/Cuemon.Core/TesterFuncFactory.cs +++ b/src/Cuemon.Core/TesterFuncFactory.cs @@ -527,7 +527,7 @@ public TesterFuncFactory(TesterFunc method, TTuple tu internal TesterFuncFactory(TesterFunc method, TTuple tuple, Delegate originalDelegate) : base(tuple, originalDelegate != null) { Method = method; - DelegateInfo = Infrastructure.ResolveDelegateInfo(method, originalDelegate); + DelegateInfo = Decorator.RawEnclose(method).ResolveDelegateInfo(originalDelegate); } /// diff --git a/src/Cuemon.Core/Threading/AsyncActionFactory.cs b/src/Cuemon.Core/Threading/AsyncActionFactory.cs new file mode 100644 index 000000000..075096cc9 --- /dev/null +++ b/src/Cuemon.Core/Threading/AsyncActionFactory.cs @@ -0,0 +1,68 @@ +using System; +using System.Threading; +using System.Threading.Tasks; + +namespace Cuemon.Threading +{ + /// + /// Provides an easy way of invoking an delegate regardless of the amount of parameters provided. + /// + /// The type of the n-tuple representation of a . + public sealed class AsyncActionFactory : TemplateFactory where TTuple : Template + { + /// + /// Initializes a new instance of the class. + /// + /// The based function delegate to invoke. + /// The n-tuple argument of . + public AsyncActionFactory(Func method, TTuple tuple) : this(method, tuple, method) + { + } + + /// + /// Initializes a new instance of the class. + /// + /// The based function delegate to invoke. + /// The n-tuple argument of . + /// The original delegate wrapped by . + public AsyncActionFactory(Func method, TTuple tuple, Delegate originalDelegate) : base(tuple, originalDelegate != null) + { + Method = method; + DelegateInfo = Decorator.RawEnclose(method).ResolveDelegateInfo(originalDelegate); + } + + /// + /// Gets the delegate to invoke. + /// + /// The delegate to invoke. + private Func Method { get; } + + /// + /// Executes the delegate associated with this instance. + /// + /// The token to monitor for cancellation requests. The default value is . + /// A task that represents the asynchronous operation. + /// + /// No delegate was specified on the factory. + /// + /// + /// The was canceled. + /// + public Task ExecuteMethodAsync(CancellationToken ct) + { + ThrowIfNoValidDelegate(Condition.IsNull(Method)); + ct.ThrowIfCancellationRequested(); + return Method.Invoke(GenericArguments, ct); + } + + /// + /// Creates a shallow copy of the current object. + /// + /// A new that is a copy of this instance. + /// When thread safety is required this is the method to invoke. + public override TemplateFactory Clone() + { + return new AsyncActionFactory(Method, GenericArguments.Clone() as TTuple); + } + } +} diff --git a/src/Cuemon.Core/Threading/AsyncFuncFactory.cs b/src/Cuemon.Core/Threading/AsyncFuncFactory.cs new file mode 100644 index 000000000..312e959b5 --- /dev/null +++ b/src/Cuemon.Core/Threading/AsyncFuncFactory.cs @@ -0,0 +1,69 @@ +using System; +using System.Threading; +using System.Threading.Tasks; + +namespace Cuemon.Threading +{ + /// + /// Provides an easy way of invoking an function delegate regardless of the amount of parameters provided. + /// + /// The type of the n-tuple representation of a . + /// The type of the return value of the function delegate . + public sealed class AsyncFuncFactory : TemplateFactory where TTuple : Template + { + /// + /// Initializes a new instance of the class. + /// + /// The function delegate to invoke. + /// The n-tuple argument of . + public AsyncFuncFactory(Func> method, TTuple tuple) : this(method, tuple, method) + { + } + + /// + /// Initializes a new instance of the class. + /// + /// The function delegate to invoke. + /// The n-tuple argument of . + /// The original delegate wrapped by . + public AsyncFuncFactory(Func> method, TTuple tuple, Delegate originalDelegate) : base(tuple, originalDelegate != null) + { + Method = method; + DelegateInfo = Decorator.RawEnclose(method).ResolveDelegateInfo(originalDelegate); + } + + /// + /// Gets the function delegate to invoke. + /// + /// The function delegate to invoke. + private Func> Method { get; set; } + + /// + /// Executes the function delegate associated with this instance. + /// + /// The token to monitor for cancellation requests. The default value is . + /// A task that represents the asynchronous operation. The task result contains the return value of the function delegate associated with this instance. + /// + /// No delegate was specified on the factory. + /// + /// + /// The was canceled. + /// + public Task ExecuteMethodAsync(CancellationToken ct) + { + ThrowIfNoValidDelegate(Condition.IsNull(Method)); + ct.ThrowIfCancellationRequested(); + return Method.Invoke(GenericArguments, ct); + } + + /// + /// Creates a shallow copy of the current object. + /// + /// A new that is a copy of this instance. + /// When thread safety is required this is the method to invoke. + public override TemplateFactory Clone() + { + return new AsyncFuncFactory(Method, GenericArguments.Clone() as TTuple); + } + } +} diff --git a/src/Cuemon.Diagnostics/Cuemon.Diagnostics.csproj b/src/Cuemon.Diagnostics/Cuemon.Diagnostics.csproj index 7ac56f284..919d59dd5 100644 --- a/src/Cuemon.Diagnostics/Cuemon.Diagnostics.csproj +++ b/src/Cuemon.Diagnostics/Cuemon.Diagnostics.csproj @@ -11,6 +11,7 @@ + - \ No newline at end of file + diff --git a/src/Cuemon.Diagnostics/TimeMeasure.Async.cs b/src/Cuemon.Diagnostics/TimeMeasure.Async.cs index 322001e3a..59f1d6d22 100644 --- a/src/Cuemon.Diagnostics/TimeMeasure.Async.cs +++ b/src/Cuemon.Diagnostics/TimeMeasure.Async.cs @@ -3,6 +3,7 @@ using System.Threading; using System.Threading.Tasks; using Cuemon.Reflection; +using Cuemon.Threading; namespace Cuemon.Diagnostics { @@ -20,7 +21,7 @@ public static partial class TimeMeasure public static Task WithActionAsync(Func action, Action setup = null) { Validator.ThrowIfNull(action); - var factory = TaskActionFactory.Create(action); + var factory = AsyncActionFactory.Create(action); return WithActionAsyncCore(factory, setup); } @@ -38,7 +39,7 @@ public static Task WithActionAsync(Func WithActionAsync(Func action, T arg, Action setup = null) { Validator.ThrowIfNull(action); - var factory = TaskActionFactory.Create(action, arg); + var factory = AsyncActionFactory.Create(action, arg); return WithActionAsyncCore(factory, setup); } @@ -58,7 +59,7 @@ public static Task WithActionAsync(Func WithActionAsync(Func action, T1 arg1, T2 arg2, Action setup = null) { Validator.ThrowIfNull(action); - var factory = TaskActionFactory.Create(action, arg1, arg2); + var factory = AsyncActionFactory.Create(action, arg1, arg2); return WithActionAsyncCore(factory, setup); } @@ -80,7 +81,7 @@ public static Task WithActionAsync(Func WithActionAsync(Func action, T1 arg1, T2 arg2, T3 arg3, Action setup = null) { Validator.ThrowIfNull(action); - var factory = TaskActionFactory.Create(action, arg1, arg2, arg3); + var factory = AsyncActionFactory.Create(action, arg1, arg2, arg3); return WithActionAsyncCore(factory, setup); } @@ -104,7 +105,7 @@ public static Task WithActionAsync(Func WithActionAsync(Func action, T1 arg1, T2 arg2, T3 arg3, T4 arg4, Action setup = null) { Validator.ThrowIfNull(action); - var factory = TaskActionFactory.Create(action, arg1, arg2, arg3, arg4); + var factory = AsyncActionFactory.Create(action, arg1, arg2, arg3, arg4); return WithActionAsyncCore(factory, setup); } @@ -130,7 +131,7 @@ public static Task WithActionAsync(Func WithActionAsync(Func action, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, Action setup = null) { Validator.ThrowIfNull(action); - var factory = TaskActionFactory.Create(action, arg1, arg2, arg3, arg4, arg5); + var factory = AsyncActionFactory.Create(action, arg1, arg2, arg3, arg4, arg5); return WithActionAsyncCore(factory, setup); } @@ -158,7 +159,7 @@ public static Task WithActionAsync(Func public static Task WithActionAsync(Func action, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, Action setup = null) { Validator.ThrowIfNull(action); - var factory = TaskActionFactory.Create(action, arg1, arg2, arg3, arg4, arg5, arg6); + var factory = AsyncActionFactory.Create(action, arg1, arg2, arg3, arg4, arg5, arg6); return WithActionAsyncCore(factory, setup); } @@ -188,7 +189,7 @@ public static Task WithActionAsync( public static Task WithActionAsync(Func action, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, Action setup = null) { Validator.ThrowIfNull(action); - var factory = TaskActionFactory.Create(action, arg1, arg2, arg3, arg4, arg5, arg6, arg7); + var factory = AsyncActionFactory.Create(action, arg1, arg2, arg3, arg4, arg5, arg6, arg7); return WithActionAsyncCore(factory, setup); } @@ -220,7 +221,7 @@ public static Task WithActionAsync WithActionAsync(Func action, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, Action setup = null) { Validator.ThrowIfNull(action); - var factory = TaskActionFactory.Create(action, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8); + var factory = AsyncActionFactory.Create(action, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8); return WithActionAsyncCore(factory, setup); } @@ -254,7 +255,7 @@ public static Task WithActionAsync WithActionAsync(Func action, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, Action setup = null) { Validator.ThrowIfNull(action); - var factory = TaskActionFactory.Create(action, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9); + var factory = AsyncActionFactory.Create(action, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9); return WithActionAsyncCore(factory, setup); } @@ -290,7 +291,7 @@ public static Task WithActionAsync WithActionAsync(Func action, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, Action setup = null) { Validator.ThrowIfNull(action); - var factory = TaskActionFactory.Create(action, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10); + var factory = AsyncActionFactory.Create(action, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10); return WithActionAsyncCore(factory, setup); } @@ -305,7 +306,7 @@ public static Task WithActionAsync> WithFuncAsync(Func> function, Action setup = null) { Validator.ThrowIfNull(function); - var factory = TaskFuncFactory.Create(function); + var factory = AsyncFuncFactory.Create(function); return WithFunctionAsyncCore(factory, setup); } @@ -321,7 +322,7 @@ public static Task> WithFuncAsync(Func> WithFuncAsync(Func> function, T arg, Action setup = null) { Validator.ThrowIfNull(function); - var factory = TaskFuncFactory.Create(function, arg); + var factory = AsyncFuncFactory.Create(function, arg); return WithFunctionAsyncCore(factory, setup); } @@ -339,7 +340,7 @@ public static Task> WithFuncAsync(Func< public static Task> WithFuncAsync(Func> function, T1 arg1, T2 arg2, Action setup = null) { Validator.ThrowIfNull(function); - var factory = TaskFuncFactory.Create(function, arg1, arg2); + var factory = AsyncFuncFactory.Create(function, arg1, arg2); return WithFunctionAsyncCore(factory, setup); } @@ -359,7 +360,7 @@ public static Task> WithFuncAsync( public static Task> WithFuncAsync(Func> function, T1 arg1, T2 arg2, T3 arg3, Action setup = null) { Validator.ThrowIfNull(function); - var factory = TaskFuncFactory.Create(function, arg1, arg2, arg3); + var factory = AsyncFuncFactory.Create(function, arg1, arg2, arg3); return WithFunctionAsyncCore(factory, setup); } @@ -381,7 +382,7 @@ public static Task> WithFuncAsync> WithFuncAsync(Func> function, T1 arg1, T2 arg2, T3 arg3, T4 arg4, Action setup = null) { Validator.ThrowIfNull(function); - var factory = TaskFuncFactory.Create(function, arg1, arg2, arg3, arg4); + var factory = AsyncFuncFactory.Create(function, arg1, arg2, arg3, arg4); return WithFunctionAsyncCore(factory, setup); } @@ -405,7 +406,7 @@ public static Task> WithFuncAsync> WithFuncAsync(Func> function, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, Action setup = null) { Validator.ThrowIfNull(function); - var factory = TaskFuncFactory.Create(function, arg1, arg2, arg3, arg4, arg5); + var factory = AsyncFuncFactory.Create(function, arg1, arg2, arg3, arg4, arg5); return WithFunctionAsyncCore(factory, setup); } @@ -431,7 +432,7 @@ public static Task> WithFuncAsync> WithFuncAsync(Func> function, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, Action setup = null) { Validator.ThrowIfNull(function); - var factory = TaskFuncFactory.Create(function, arg1, arg2, arg3, arg4, arg5, arg6); + var factory = AsyncFuncFactory.Create(function, arg1, arg2, arg3, arg4, arg5, arg6); return WithFunctionAsyncCore(factory, setup); } @@ -459,7 +460,7 @@ public static Task> WithFuncAsync> WithFuncAsync(Func> function, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, Action setup = null) { Validator.ThrowIfNull(function); - var factory = TaskFuncFactory.Create(function, arg1, arg2, arg3, arg4, arg5, arg6, arg7); + var factory = AsyncFuncFactory.Create(function, arg1, arg2, arg3, arg4, arg5, arg6, arg7); return WithFunctionAsyncCore(factory, setup); } @@ -489,7 +490,7 @@ public static Task> WithFuncAsync> WithFuncAsync(Func> function, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, Action setup = null) { Validator.ThrowIfNull(function); - var factory = TaskFuncFactory.Create(function, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8); + var factory = AsyncFuncFactory.Create(function, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8); return WithFunctionAsyncCore(factory, setup); } @@ -521,7 +522,7 @@ public static Task> WithFuncAsync> WithFuncAsync(Func> function, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, Action setup = null) { Validator.ThrowIfNull(function); - var factory = TaskFuncFactory.Create(function, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9); + var factory = AsyncFuncFactory.Create(function, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9); return WithFunctionAsyncCore(factory, setup); } @@ -555,11 +556,11 @@ public static Task> WithFuncAsync> WithFuncAsync(Func> function, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, Action setup = null) { Validator.ThrowIfNull(function); - var factory = TaskFuncFactory.Create(function, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10); + var factory = AsyncFuncFactory.Create(function, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10); return WithFunctionAsyncCore(factory, setup); } - private static async Task WithActionAsyncCore(TaskActionFactory factory, Action setup) where TTuple : Template + private static async Task WithActionAsyncCore(AsyncActionFactory factory, Action setup) where TTuple : Template { var options = Patterns.Configure(setup); var descriptor = options.MethodDescriptor?.Invoke() ?? new MethodDescriptor(factory.DelegateInfo); @@ -572,7 +573,7 @@ private static async Task WithActionAsyncCore(TaskA return profiler; } - private static async Task> WithFunctionAsyncCore(TaskFuncFactory factory, Action setup) where TTuple : Template + private static async Task> WithFunctionAsyncCore(AsyncFuncFactory factory, Action setup) where TTuple : Template { var options = Patterns.Configure(setup); var descriptor = options.MethodDescriptor?.Invoke() ?? new MethodDescriptor(factory.DelegateInfo); diff --git a/src/Cuemon.Extensions.Globalization/Cuemon.Extensions.Globalization.csproj b/src/Cuemon.Extensions.Globalization/Cuemon.Extensions.Globalization.csproj index 8f4c3bf71..088e67c75 100644 --- a/src/Cuemon.Extensions.Globalization/Cuemon.Extensions.Globalization.csproj +++ b/src/Cuemon.Extensions.Globalization/Cuemon.Extensions.Globalization.csproj @@ -1200,7 +1200,7 @@ - + diff --git a/src/Cuemon.Extensions.IO/ByteArrayExtensions.cs b/src/Cuemon.Extensions.IO/ByteArrayExtensions.cs index d5f2e5b07..4fb8ddf15 100644 --- a/src/Cuemon.Extensions.IO/ByteArrayExtensions.cs +++ b/src/Cuemon.Extensions.IO/ByteArrayExtensions.cs @@ -1,6 +1,8 @@ using System; using System.IO; +using System.Threading; using System.Threading.Tasks; +using Cuemon.Threading; namespace Cuemon.Extensions.IO { @@ -24,17 +26,27 @@ public static Stream ToStream(this byte[] bytes) } /// - /// Converts the the specified to its equivalent representation. + /// Converts the specified to its equivalent representation. /// /// The to extend. + /// The token to monitor for cancellation requests. The default value is . /// A task that represents the asynchronous operation. The task result contains a that is equivalent to . /// /// cannot be null. /// - public static Task ToStreamAsync(this byte[] bytes) + public static Task ToStreamAsync(this byte[] bytes, CancellationToken cancellationToken = default) { Validator.ThrowIfNull(bytes); - return Decorator.Enclose(bytes).ToStreamAsync(); + return AsyncPatterns.SafeInvokeAsync(() => new MemoryStream(bytes.Length), async (ms, cti) => + { +#if NETSTANDARD + await ms.WriteAsync(bytes, 0, bytes.Length, cti).ConfigureAwait(false); +#else + await ms.WriteAsync(bytes.AsMemory(0, bytes.Length), cti).ConfigureAwait(false); +#endif + ms.Position = 0; + return ms; + }, ct: cancellationToken); } } -} \ No newline at end of file +} diff --git a/src/Cuemon.Extensions.IO/StringExtensions.cs b/src/Cuemon.Extensions.IO/StringExtensions.cs index b1674108b..e6c585c45 100644 --- a/src/Cuemon.Extensions.IO/StringExtensions.cs +++ b/src/Cuemon.Extensions.IO/StringExtensions.cs @@ -3,6 +3,7 @@ using System.IO; using System.Threading.Tasks; using Cuemon.Text; +using Cuemon.Threading; namespace Cuemon.Extensions.IO { @@ -44,7 +45,18 @@ public static Stream ToStream(this string value, Action setup = /// public static Task ToStreamAsync(this string value, Action setup = null) { - return Decorator.Enclose(value).ToStreamAsync(setup); + Validator.ThrowIfInvalidConfigurator(setup, out var options); + return AsyncPatterns.SafeInvokeAsync(() => new MemoryStream(), async (ms, token) => + { + var bytes = Convertible.GetBytes(value, Patterns.ConfigureExchange(setup)); +#if NETSTANDARD + await ms.WriteAsync(bytes, 0, bytes.Length, token).ConfigureAwait(false); +#else + await ms.WriteAsync(bytes.AsMemory(0, bytes.Length), token).ConfigureAwait(false); +#endif + ms.Position = 0; + return ms; + }, ct: options.CancellationToken); } /// diff --git a/src/Cuemon.Extensions.Text.Json/Converters/FailureConverter.cs b/src/Cuemon.Extensions.Text.Json/Converters/FailureConverter.cs deleted file mode 100644 index e7b6b83c5..000000000 --- a/src/Cuemon.Extensions.Text.Json/Converters/FailureConverter.cs +++ /dev/null @@ -1,110 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text.Json; -using System.Text.Json.Serialization; -using Cuemon.Diagnostics; - -namespace Cuemon.Extensions.Text.Json.Converters -{ - /// - /// Converts a object to JSON. - /// - public class FailureConverter : JsonConverter - { - /// - /// Reads and converts the JSON to type . - /// - /// The reader. - /// The type to convert. - /// An object that specifies serialization options to use. - /// The converted value. - /// - public override Failure Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) - { - throw new NotImplementedException(); - } - - /// - /// Writes a specified value as JSON. - /// - /// The writer to write to. - /// The value to convert to JSON. - /// An object that specifies serialization options to use. - public override void Write(Utf8JsonWriter writer, Failure value, JsonSerializerOptions options) - { - writer.WriteStartObject(); - writer.WriteString(options.PropertyNamingPolicy.DefaultOrConvertName(nameof(value.Type)), value.Type); - - WriteException(writer, value, options); - - writer.WriteEndObject(); - } - - private static void WriteException(Utf8JsonWriter writer, Failure value, JsonSerializerOptions options) - { - if (!string.IsNullOrWhiteSpace(value.Source)) { writer.WriteString(options.SetPropertyName(nameof(value.Source)), value.Source); } - if (!string.IsNullOrWhiteSpace(value.Message)) { writer.WriteString(options.SetPropertyName(nameof(value.Message)), value.Message); } - - if (value.Stack.Any()) - { - writer.WritePropertyName(options.SetPropertyName(nameof(value.Stack))); - writer.WriteStartArray(); - foreach (var line in value.Stack) - { - writer.WriteStringValue(line); - } - writer.WriteEndArray(); - } - - if (value.Data.Count > 0) - { - writer.WritePropertyName(options.SetPropertyName(nameof(value.Data))); - writer.WriteStartObject(); - foreach (var kvp in value.Data) - { - writer.WritePropertyName(options.SetPropertyName(nameof(kvp.Key))); - writer.WriteObject(kvp.Value, options); - } - writer.WriteEndObject(); - } - - foreach (var kvp in value) - { - writer.WritePropertyName(options.SetPropertyName(kvp.Key)); - writer.WriteObject(kvp.Value, options); - } - - WriteInnerExceptions(writer, value, options); - } - - private static void WriteInnerExceptions(Utf8JsonWriter writer, Failure value, JsonSerializerOptions options) - { - var exception = value.GetUnderlyingException(); - var innerExceptions = new List(); - if (exception is AggregateException aggregated) - { - innerExceptions.AddRange(aggregated.Flatten().InnerExceptions); - } - else - { - if (exception.InnerException != null) { innerExceptions.Add(exception.InnerException); } - } - if (innerExceptions.Count > 0) - { - var endElementsToWrite = 0; - foreach (var inner in innerExceptions) - { - var innerValue = new Failure(inner, value.GetUnderlyingSensitivity()); - writer.WritePropertyName(options.SetPropertyName("Inner")); - writer.WriteStartObject(); - writer.WriteString(options.SetPropertyName(nameof(value.Type)), innerValue.Type); - WriteException(writer, innerValue, options); - endElementsToWrite++; - } - - for (var i = 0; i < endElementsToWrite; i++) { writer.WriteEndObject(); } - } - } - } -} diff --git a/src/Cuemon.Extensions.Text.Json/Converters/JsonConverterCollectionExtensions.cs b/src/Cuemon.Extensions.Text.Json/Converters/JsonConverterCollectionExtensions.cs index 4a9206b8a..e384ddb53 100644 --- a/src/Cuemon.Extensions.Text.Json/Converters/JsonConverterCollectionExtensions.cs +++ b/src/Cuemon.Extensions.Text.Json/Converters/JsonConverterCollectionExtensions.cs @@ -181,7 +181,10 @@ public static ICollection AddExceptionConverter(this ICollection< /// A reference to after the operation has completed. public static ICollection AddFailureConverter(this ICollection converters) { - converters.Add(new FailureConverter()); + converters.Add(DynamicJsonConverter.Create((writer, failure, options) => + { + new ExceptionConverter(failure.GetUnderlyingSensitivity().HasFlag(FaultSensitivityDetails.StackTrace), failure.GetUnderlyingSensitivity().HasFlag(FaultSensitivityDetails.Data)).Write(writer, failure.GetUnderlyingException(), options); + })); return converters; } diff --git a/src/Cuemon.Extensions.Text.Json/GlobalSuppressions.cs b/src/Cuemon.Extensions.Text.Json/GlobalSuppressions.cs index 5369adb23..cbabe6827 100644 --- a/src/Cuemon.Extensions.Text.Json/GlobalSuppressions.cs +++ b/src/Cuemon.Extensions.Text.Json/GlobalSuppressions.cs @@ -8,4 +8,3 @@ [assembly: SuppressMessage("Critical Code Smell", "S3776:Cognitive Complexity of methods should not be too high", Justification = "Transitioned legacy code ;-)", Scope = "member", Target = "~M:Cuemon.Extensions.Text.Json.JsonReaderExtensions.ToHierarchy(System.Text.Json.Utf8JsonReader)~Cuemon.IHierarchy{Cuemon.DataPair}")] [assembly: SuppressMessage("Major Code Smell", "S907:\"goto\" statement should not be used", Justification = "Transitioned legacy code ;-)", Scope = "member", Target = "~M:Cuemon.Extensions.Text.Json.JsonReaderExtensions.ToHierarchy(System.Text.Json.Utf8JsonReader)~Cuemon.IHierarchy{Cuemon.DataPair}")] [assembly: SuppressMessage("CodeQuality", "IDE0052:Remove unread private members", Justification = "False-positive; .NET 7 reads this value.", Scope = "member", Target = "~P:Cuemon.Extensions.Text.Json.Converters.FlagsEnumConverter.TypeToConvert")] -[assembly: SuppressMessage("Major Code Smell", "S1172:Unused method parameters should be removed", Justification = "False-positive; value is conditionally used.", Scope = "member", Target = "~M:Cuemon.Extensions.Text.Json.Converters.ExceptionConverter.ParseJsonReader(System.Text.Json.Utf8JsonReader@,System.Type)~System.Collections.Generic.Stack{System.Collections.Generic.IList{Cuemon.Reflection.MemberArgument}}")] diff --git a/src/Cuemon.IO/Extensions/StreamDecoratorExtensions.cs b/src/Cuemon.IO/Extensions/StreamDecoratorExtensions.cs index cfe2aa658..02d2411ec 100644 --- a/src/Cuemon.IO/Extensions/StreamDecoratorExtensions.cs +++ b/src/Cuemon.IO/Extensions/StreamDecoratorExtensions.cs @@ -5,6 +5,7 @@ using System.Threading; using System.Threading.Tasks; using Cuemon.Text; +using Cuemon.Threading; namespace Cuemon.IO { @@ -458,7 +459,7 @@ private static Stream Compress(IDecorator decorator, StreamCompressio private static Task CompressAsync(IDecorator decorator, AsyncStreamCompressionOptions options, Func decompressor) where T : Stream { - return Patterns.SafeInvokeAsync(() => new MemoryStream(), async (target, ct) => + return AsyncPatterns.SafeInvokeAsync(() => new MemoryStream(), async (target, ct) => { #if NETSTANDARD2_1_OR_GREATER || NET8_0_OR_GREATER await using (var compressed = decompressor(target, options.Level, true)) @@ -474,7 +475,7 @@ private static Task CompressAsync(IDecorator decorator, Async await target.FlushAsync(ct).ConfigureAwait(false); target.Position = 0; return target; - }, options.CancellationToken); + }, ct: options.CancellationToken); } private static Stream Decompress(IDecorator decorator, StreamCopyOptions options, Func compressor) where T : Stream @@ -494,7 +495,7 @@ private static Stream Decompress(IDecorator decorator, StreamCopyOpti private static Task DecompressAsync(IDecorator decorator, AsyncStreamCopyOptions options, Func compressor) where T : Stream { - return Patterns.SafeInvokeAsync(() => new MemoryStream(), async (target, ct) => + return AsyncPatterns.SafeInvokeAsync(() => new MemoryStream(), async (target, ct) => { #if NETSTANDARD2_1_OR_GREATER || NET8_0_OR_GREATER await using (var uncompressed = compressor(decorator.Inner, CompressionMode.Decompress, true)) @@ -510,7 +511,7 @@ private static Task DecompressAsync(IDecorator decorator, Asy await target.FlushAsync(ct).ConfigureAwait(false); target.Position = 0; return target; - }, options.CancellationToken); + }, ct:options.CancellationToken); } /// diff --git a/src/Cuemon.Resilience/Cuemon.Resilience.csproj b/src/Cuemon.Resilience/Cuemon.Resilience.csproj index 07208406e..4258390d0 100644 --- a/src/Cuemon.Resilience/Cuemon.Resilience.csproj +++ b/src/Cuemon.Resilience/Cuemon.Resilience.csproj @@ -11,6 +11,7 @@ + \ No newline at end of file diff --git a/src/Cuemon.Resilience/TransientOperation.Async.cs b/src/Cuemon.Resilience/TransientOperation.Async.cs index fd9641c17..a073f4c24 100644 --- a/src/Cuemon.Resilience/TransientOperation.Async.cs +++ b/src/Cuemon.Resilience/TransientOperation.Async.cs @@ -1,6 +1,7 @@ using System; using System.Threading; using System.Threading.Tasks; +using Cuemon.Threading; namespace Cuemon.Resilience { @@ -30,7 +31,7 @@ public static partial class TransientOperation public static Task WithFuncAsync(Func> faultSensitiveMethod, Action setup = null) { Validator.ThrowIfNull(faultSensitiveMethod); - var factory = TaskFuncFactory.Create(faultSensitiveMethod); + var factory = AsyncFuncFactory.Create(faultSensitiveMethod); return WithFuncAsyncCore(factory, setup); } @@ -60,7 +61,7 @@ public static Task WithFuncAsync(Func WithFuncAsync(Func> faultSensitiveMethod, T arg, Action setup = null) { Validator.ThrowIfNull(faultSensitiveMethod); - var factory = TaskFuncFactory.Create(faultSensitiveMethod, arg); + var factory = AsyncFuncFactory.Create(faultSensitiveMethod, arg); return WithFuncAsyncCore(factory, setup); } @@ -92,7 +93,7 @@ public static Task WithFuncAsync(Func WithFuncAsync(Func> faultSensitiveMethod, T1 arg1, T2 arg2, Action setup = null) { Validator.ThrowIfNull(faultSensitiveMethod); - var factory = TaskFuncFactory.Create(faultSensitiveMethod, arg1, arg2); + var factory = AsyncFuncFactory.Create(faultSensitiveMethod, arg1, arg2); return WithFuncAsyncCore(factory, setup); } @@ -126,7 +127,7 @@ public static Task WithFuncAsync(Func WithFuncAsync(Func> faultSensitiveMethod, T1 arg1, T2 arg2, T3 arg3, Action setup = null) { Validator.ThrowIfNull(faultSensitiveMethod); - var factory = TaskFuncFactory.Create(faultSensitiveMethod, arg1, arg2, arg3); + var factory = AsyncFuncFactory.Create(faultSensitiveMethod, arg1, arg2, arg3); return WithFuncAsyncCore(factory, setup); } @@ -162,7 +163,7 @@ public static Task WithFuncAsync(Func WithFuncAsync(Func> faultSensitiveMethod, T1 arg1, T2 arg2, T3 arg3, T4 arg4, Action setup = null) { Validator.ThrowIfNull(faultSensitiveMethod); - var factory = TaskFuncFactory.Create(faultSensitiveMethod, arg1, arg2, arg3, arg4); + var factory = AsyncFuncFactory.Create(faultSensitiveMethod, arg1, arg2, arg3, arg4); return WithFuncAsyncCore(factory, setup); } @@ -200,7 +201,7 @@ public static Task WithFuncAsync(Func WithFuncAsync(Func> faultSensitiveMethod, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, Action setup = null) { Validator.ThrowIfNull(faultSensitiveMethod); - var factory = TaskFuncFactory.Create(faultSensitiveMethod, arg1, arg2, arg3, arg4, arg5); + var factory = AsyncFuncFactory.Create(faultSensitiveMethod, arg1, arg2, arg3, arg4, arg5); return WithFuncAsyncCore(factory, setup); } @@ -226,7 +227,7 @@ public static Task WithFuncAsync(Func faultSensitiveMethod, Action setup = null) { Validator.ThrowIfNull(faultSensitiveMethod); - var factory = TaskActionFactory.Create(faultSensitiveMethod); + var factory = AsyncActionFactory.Create(faultSensitiveMethod); return WithActionAsyncCore(factory, setup); } @@ -254,7 +255,7 @@ public static Task WithActionAsync(Func faultSensitiveM public static Task WithActionAsync(Func faultSensitiveMethod, T arg, Action setup = null) { Validator.ThrowIfNull(faultSensitiveMethod); - var factory = TaskActionFactory.Create(faultSensitiveMethod, arg); + var factory = AsyncActionFactory.Create(faultSensitiveMethod, arg); return WithActionAsyncCore(factory, setup); } @@ -284,7 +285,7 @@ public static Task WithActionAsync(Func faultSens public static Task WithActionAsync(Func faultSensitiveMethod, T1 arg1, T2 arg2, Action setup = null) { Validator.ThrowIfNull(faultSensitiveMethod); - var factory = TaskActionFactory.Create(faultSensitiveMethod, arg1, arg2); + var factory = AsyncActionFactory.Create(faultSensitiveMethod, arg1, arg2); return WithActionAsyncCore(factory, setup); } @@ -316,7 +317,7 @@ public static Task WithActionAsync(Func public static Task WithActionAsync(Func faultSensitiveMethod, T1 arg1, T2 arg2, T3 arg3, Action setup = null) { Validator.ThrowIfNull(faultSensitiveMethod); - var factory = TaskActionFactory.Create(faultSensitiveMethod, arg1, arg2, arg3); + var factory = AsyncActionFactory.Create(faultSensitiveMethod, arg1, arg2, arg3); return WithActionAsyncCore(factory, setup); } @@ -350,7 +351,7 @@ public static Task WithActionAsync(Func(Func faultSensitiveMethod, T1 arg1, T2 arg2, T3 arg3, T4 arg4, Action setup = null) { Validator.ThrowIfNull(faultSensitiveMethod); - var factory = TaskActionFactory.Create(faultSensitiveMethod, arg1, arg2, arg3, arg4); + var factory = AsyncActionFactory.Create(faultSensitiveMethod, arg1, arg2, arg3, arg4); return WithActionAsyncCore(factory, setup); } @@ -386,16 +387,16 @@ public static Task WithActionAsync(Func(Func faultSensitiveMethod, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, Action setup = null) { Validator.ThrowIfNull(faultSensitiveMethod); - var factory = TaskActionFactory.Create(faultSensitiveMethod, arg1, arg2, arg3, arg4, arg5); + var factory = AsyncActionFactory.Create(faultSensitiveMethod, arg1, arg2, arg3, arg4, arg5); return WithActionAsyncCore(factory, setup); } - private static Task WithActionAsyncCore(TaskActionFactory factory, Action setup) where TTuple : Template + private static Task WithActionAsyncCore(AsyncActionFactory factory, Action setup) where TTuple : Template { return new AsyncActionTransientWorker(factory.DelegateInfo, factory.GenericArguments.ToArray(), setup).ResilientActionAsync(factory.ExecuteMethodAsync); } - private static Task WithFuncAsyncCore(TaskFuncFactory factory, Action setup) where TTuple : Template + private static Task WithFuncAsyncCore(AsyncFuncFactory factory, Action setup) where TTuple : Template { return new AsyncFuncTransientWorker(factory.DelegateInfo, factory.GenericArguments.ToArray(), setup).ResilientFuncAsync(factory.ExecuteMethodAsync); } diff --git a/src/Cuemon.Threading/AdvancedParallelFactory.ForAsync.cs b/src/Cuemon.Threading/AdvancedParallelFactory.ForAsync.cs index cbd971218..426dc8ae7 100644 --- a/src/Cuemon.Threading/AdvancedParallelFactory.ForAsync.cs +++ b/src/Cuemon.Threading/AdvancedParallelFactory.ForAsync.cs @@ -24,7 +24,7 @@ public static Task ForAsync(ForLoopRuleset rules, Func @@ -46,7 +46,7 @@ public static Task ForAsync(ForLoopRuleset rules, Func @@ -70,7 +70,7 @@ public static Task ForAsync(ForLoopRuleset rules, Fu { Validator.ThrowIfNull(rules); Validator.ThrowIfNull(worker); - return ForCoreAsync(rules, TaskActionFactory.Create(worker, default, arg1, arg2), setup); + return ForCoreAsync(rules, AsyncActionFactory.Create(worker, default, arg1, arg2), setup); } /// @@ -96,7 +96,7 @@ public static Task ForAsync(ForLoopRuleset rules { Validator.ThrowIfNull(rules); Validator.ThrowIfNull(worker); - return ForCoreAsync(rules, TaskActionFactory.Create(worker, default, arg1, arg2, arg3), setup); + return ForCoreAsync(rules, AsyncActionFactory.Create(worker, default, arg1, arg2, arg3), setup); } /// @@ -124,7 +124,7 @@ public static Task ForAsync(ForLoopRuleset r { Validator.ThrowIfNull(rules); Validator.ThrowIfNull(worker); - return ForCoreAsync(rules, TaskActionFactory.Create(worker, default, arg1, arg2, arg3, arg4), setup); + return ForCoreAsync(rules, AsyncActionFactory.Create(worker, default, arg1, arg2, arg3, arg4), setup); } /// @@ -154,10 +154,10 @@ public static Task ForAsync(ForLoopRuleset(ForLoopRuleset rules, TaskActionFactory workerFactory, Action setup) + private static async Task ForCoreAsync(ForLoopRuleset rules, AsyncActionFactory workerFactory, Action setup) where TWorker : Template where TOperand : struct, IComparable, IEquatable, IConvertible { diff --git a/src/Cuemon.Threading/AdvancedParallelFactory.ForResultAsync.cs b/src/Cuemon.Threading/AdvancedParallelFactory.ForResultAsync.cs index 69a4c2e29..a5c2a52af 100644 --- a/src/Cuemon.Threading/AdvancedParallelFactory.ForResultAsync.cs +++ b/src/Cuemon.Threading/AdvancedParallelFactory.ForResultAsync.cs @@ -30,7 +30,7 @@ public static Task> ForResultAsync @@ -54,7 +54,7 @@ public static Task> ForResultAsync @@ -80,7 +80,7 @@ public static Task> ForResultAsync @@ -108,7 +108,7 @@ public static Task> ForResultAsync @@ -138,7 +138,7 @@ public static Task> ForResultAsync @@ -170,10 +170,10 @@ public static Task> ForResultAsync> ForResultCoreAsync(ForLoopRuleset rules, TaskFuncFactory workerFactory, Action setup) + private static async Task> ForResultCoreAsync(ForLoopRuleset rules, AsyncFuncFactory workerFactory, Action setup) where TWorker : Template where TOperand : struct, IComparable, IEquatable, IConvertible { diff --git a/src/Cuemon.Threading/AdvancedParallelFactory.WhileAsync.cs b/src/Cuemon.Threading/AdvancedParallelFactory.WhileAsync.cs index 3873ff8c6..4f0d310ac 100644 --- a/src/Cuemon.Threading/AdvancedParallelFactory.WhileAsync.cs +++ b/src/Cuemon.Threading/AdvancedParallelFactory.WhileAsync.cs @@ -23,7 +23,7 @@ public static Task WhileAsync(TReader reader, Func Validator.ThrowIfNull(condition); Validator.ThrowIfNull(provider); Validator.ThrowIfNull(worker); - return WhileCoreAsync(new AsyncForwardIterator(reader, condition, provider), TaskActionFactory.Create(worker, default), setup); + return WhileCoreAsync(new AsyncForwardIterator(reader, condition, provider), AsyncActionFactory.Create(worker, default), setup); } /// @@ -44,7 +44,7 @@ public static Task WhileAsync(TReader reader, Func(reader, condition, provider), TaskActionFactory.Create(worker, default, arg), setup); + return WhileCoreAsync(new AsyncForwardIterator(reader, condition, provider), AsyncActionFactory.Create(worker, default, arg), setup); } /// @@ -67,7 +67,7 @@ public static Task WhileAsync(TReader reader, Func(reader, condition, provider), TaskActionFactory.Create(worker, default, arg1, arg2), setup); + return WhileCoreAsync(new AsyncForwardIterator(reader, condition, provider), AsyncActionFactory.Create(worker, default, arg1, arg2), setup); } /// @@ -92,7 +92,7 @@ public static Task WhileAsync(TReader reader, Fun Validator.ThrowIfNull(condition); Validator.ThrowIfNull(provider); Validator.ThrowIfNull(worker); - return WhileCoreAsync(new AsyncForwardIterator(reader, condition, provider), TaskActionFactory.Create(worker, default, arg1, arg2, arg3), setup); + return WhileCoreAsync(new AsyncForwardIterator(reader, condition, provider), AsyncActionFactory.Create(worker, default, arg1, arg2, arg3), setup); } /// @@ -119,7 +119,7 @@ public static Task WhileAsync(TReader reader, Validator.ThrowIfNull(condition); Validator.ThrowIfNull(provider); Validator.ThrowIfNull(worker); - return WhileCoreAsync(new AsyncForwardIterator(reader, condition, provider), TaskActionFactory.Create(worker, default, arg1, arg2, arg3, arg4), setup); + return WhileCoreAsync(new AsyncForwardIterator(reader, condition, provider), AsyncActionFactory.Create(worker, default, arg1, arg2, arg3, arg4), setup); } /// @@ -148,10 +148,10 @@ public static Task WhileAsync(TReader rea Validator.ThrowIfNull(condition); Validator.ThrowIfNull(provider); Validator.ThrowIfNull(worker); - return WhileCoreAsync(new AsyncForwardIterator(reader, condition, provider), TaskActionFactory.Create(worker, default, arg1, arg2, arg3, arg4, arg5), setup); + return WhileCoreAsync(new AsyncForwardIterator(reader, condition, provider), AsyncActionFactory.Create(worker, default, arg1, arg2, arg3, arg4, arg5), setup); } - private static async Task WhileCoreAsync(AsyncForwardIterator iterator, TaskActionFactory workerFactory, Action setup) + private static async Task WhileCoreAsync(AsyncForwardIterator iterator, AsyncActionFactory workerFactory, Action setup) where TWorker : Template { var options = Patterns.Configure(setup); diff --git a/src/Cuemon.Threading/AdvancedParallelFactory.WhileResultAsync.cs b/src/Cuemon.Threading/AdvancedParallelFactory.WhileResultAsync.cs index 949c5c97c..e7a568619 100644 --- a/src/Cuemon.Threading/AdvancedParallelFactory.WhileResultAsync.cs +++ b/src/Cuemon.Threading/AdvancedParallelFactory.WhileResultAsync.cs @@ -28,7 +28,7 @@ public static Task> WhileResultAsync(reader, condition, provider), TaskFuncFactory.Create(worker, default), setup); + return WhileResultCoreAsync(new AsyncForwardIterator(reader, condition, provider), AsyncFuncFactory.Create(worker, default), setup); } /// @@ -51,7 +51,7 @@ public static Task> WhileResultAsync(reader, condition, provider), TaskFuncFactory.Create(worker, default, arg), setup); + return WhileResultCoreAsync(new AsyncForwardIterator(reader, condition, provider), AsyncFuncFactory.Create(worker, default, arg), setup); } /// @@ -76,7 +76,7 @@ public static Task> WhileResultAsync(reader, condition, provider), TaskFuncFactory.Create(worker, default, arg1, arg2), setup); + return WhileResultCoreAsync(new AsyncForwardIterator(reader, condition, provider), AsyncFuncFactory.Create(worker, default, arg1, arg2), setup); } /// @@ -103,7 +103,7 @@ public static Task> WhileResultAsync(reader, condition, provider), TaskFuncFactory.Create(worker, default, arg1, arg2, arg3), setup); + return WhileResultCoreAsync(new AsyncForwardIterator(reader, condition, provider), AsyncFuncFactory.Create(worker, default, arg1, arg2, arg3), setup); } /// @@ -132,7 +132,7 @@ public static Task> WhileResultAsync(reader, condition, provider), TaskFuncFactory.Create(worker, default, arg1, arg2, arg3, arg4), setup); + return WhileResultCoreAsync(new AsyncForwardIterator(reader, condition, provider), AsyncFuncFactory.Create(worker, default, arg1, arg2, arg3, arg4), setup); } /// @@ -163,10 +163,10 @@ public static Task> WhileResultAsync(reader, condition, provider), TaskFuncFactory.Create(worker, default, arg1, arg2, arg3, arg4, arg5), setup); + return WhileResultCoreAsync(new AsyncForwardIterator(reader, condition, provider), AsyncFuncFactory.Create(worker, default, arg1, arg2, arg3, arg4, arg5), setup); } - private static async Task> WhileResultCoreAsync(AsyncForwardIterator iterator, TaskFuncFactory workerFactory, Action setup) + private static async Task> WhileResultCoreAsync(AsyncForwardIterator iterator, AsyncFuncFactory workerFactory, Action setup) where TWorker : Template { var options = Patterns.Configure(setup); diff --git a/src/Cuemon.Core/TaskActionFactory.cs b/src/Cuemon.Threading/AsyncActionFactory.cs similarity index 63% rename from src/Cuemon.Core/TaskActionFactory.cs rename to src/Cuemon.Threading/AsyncActionFactory.cs index feb950340..e3ba5f77a 100644 --- a/src/Cuemon.Core/TaskActionFactory.cs +++ b/src/Cuemon.Threading/AsyncActionFactory.cs @@ -2,51 +2,51 @@ using System.Threading; using System.Threading.Tasks; -namespace Cuemon +namespace Cuemon.Threading { /// - /// Provides access to factory methods for creating instances that encapsulate a based function delegate with a variable amount of generic arguments. + /// Provides access to factory methods for creating instances that encapsulate a based function delegate with a variable amount of generic arguments. /// - public static class TaskActionFactory + public static class AsyncActionFactory { /// - /// Creates a new instance encapsulating the specified . + /// Creates a new instance encapsulating the specified . /// /// The based function delegate to invoke. - /// An instance of object initialized with the specified . - public static TaskActionFactory