diff options
Diffstat (limited to 'Emby.Server.Implementations/Services')
| -rw-r--r-- | Emby.Server.Implementations/Services/ResponseHelper.cs | 2 | ||||
| -rw-r--r-- | Emby.Server.Implementations/Services/ServiceExec.cs | 39 | ||||
| -rw-r--r-- | Emby.Server.Implementations/Services/UrlExtensions.cs | 14 |
3 files changed, 27 insertions, 28 deletions
diff --git a/Emby.Server.Implementations/Services/ResponseHelper.cs b/Emby.Server.Implementations/Services/ResponseHelper.cs index ca2b22fe0..a566b18dd 100644 --- a/Emby.Server.Implementations/Services/ResponseHelper.cs +++ b/Emby.Server.Implementations/Services/ResponseHelper.cs @@ -6,8 +6,8 @@ using System.Text; using System.Threading; using System.Threading.Tasks; using Emby.Server.Implementations.HttpServer; -using Microsoft.AspNetCore.Http; using MediaBrowser.Model.Services; +using Microsoft.AspNetCore.Http; namespace Emby.Server.Implementations.Services { diff --git a/Emby.Server.Implementations/Services/ServiceExec.cs b/Emby.Server.Implementations/Services/ServiceExec.cs index 9124b9c14..9f5f97028 100644 --- a/Emby.Server.Implementations/Services/ServiceExec.cs +++ b/Emby.Server.Implementations/Services/ServiceExec.cs @@ -87,8 +87,7 @@ namespace Emby.Server.Implementations.Services var response = actionContext.ServiceAction(instance, requestDto); - var taskResponse = response as Task; - if (taskResponse != null) + if (response is Task taskResponse) { return GetTaskResult(taskResponse); } @@ -104,8 +103,7 @@ namespace Emby.Server.Implementations.Services { try { - var taskObject = task as Task<object>; - if (taskObject != null) + if (task is Task<object> taskObject) { return await taskObject.ConfigureAwait(false); } @@ -136,7 +134,7 @@ namespace Emby.Server.Implementations.Services } catch (TypeAccessException) { - return null; //return null for void Task's + return null; // return null for void Task's } } @@ -155,29 +153,22 @@ namespace Emby.Server.Implementations.Services Id = ServiceMethod.Key(serviceType, actionName, requestType.GetMethodName()) }; - try - { - actionCtx.ServiceAction = CreateExecFn(serviceType, requestType, mi); - } - catch - { - //Potential problems with MONO, using reflection for fallback - actionCtx.ServiceAction = (service, request) => - mi.Invoke(service, new[] { request }); - } + actionCtx.ServiceAction = CreateExecFn(serviceType, requestType, mi); var reqFilters = new List<IHasRequestFilter>(); foreach (var attr in mi.GetCustomAttributes(true)) { - var hasReqFilter = attr as IHasRequestFilter; - - if (hasReqFilter != null) + if (attr is IHasRequestFilter hasReqFilter) + { reqFilters.Add(hasReqFilter); + } } if (reqFilters.Count > 0) + { actionCtx.RequestFilters = reqFilters.OrderBy(i => i.Priority).ToArray(); + } actions.Add(actionCtx); } @@ -198,15 +189,19 @@ namespace Emby.Server.Implementations.Services if (mi.ReturnType != typeof(void)) { - var executeFunc = Expression.Lambda<ActionInvokerFn> - (callExecute, serviceParam, requestDtoParam).Compile(); + var executeFunc = Expression.Lambda<ActionInvokerFn>( + callExecute, + serviceParam, + requestDtoParam).Compile(); return executeFunc; } else { - var executeFunc = Expression.Lambda<VoidActionInvokerFn> - (callExecute, serviceParam, requestDtoParam).Compile(); + var executeFunc = Expression.Lambda<VoidActionInvokerFn>( + callExecute, + serviceParam, + requestDtoParam).Compile(); return (service, request) => { diff --git a/Emby.Server.Implementations/Services/UrlExtensions.cs b/Emby.Server.Implementations/Services/UrlExtensions.cs index 8899fbfa3..5d4407f3b 100644 --- a/Emby.Server.Implementations/Services/UrlExtensions.cs +++ b/Emby.Server.Implementations/Services/UrlExtensions.cs @@ -12,10 +12,10 @@ namespace Emby.Server.Implementations.Services { public static string GetMethodName(this Type type) { - var typeName = type.FullName != null //can be null, e.g. generic types - ? LeftPart(type.FullName, "[[") //Generic Fullname - .Replace(type.Namespace + ".", "") //Trim Namespaces - .Replace("+", ".") //Convert nested into normal type + var typeName = type.FullName != null // can be null, e.g. generic types + ? LeftPart(type.FullName, "[[") // Generic Fullname + .Replace(type.Namespace + ".", string.Empty) // Trim Namespaces + .Replace("+", ".") // Convert nested into normal type : type.Name; return type.IsGenericParameter ? "'" + typeName : typeName; @@ -23,7 +23,11 @@ namespace Emby.Server.Implementations.Services private static string LeftPart(string strVal, string needle) { - if (strVal == null) return null; + if (strVal == null) + { + return null; + } + var pos = strVal.IndexOf(needle, StringComparison.OrdinalIgnoreCase); return pos == -1 ? strVal |
