From d4d040d9ece210cef39913320323ec75e392ecb8 Mon Sep 17 00:00:00 2001 From: Stephan Date: Sun, 5 Mar 2017 11:43:36 +0100 Subject: [PATCH] More PluginManager TLC --- src/Umbraco.Core/TypeFinder.cs | 1 - src/Umbraco.Core/TypeHelper.cs | 53 ++++++++++++++-------------------- 2 files changed, 22 insertions(+), 32 deletions(-) diff --git a/src/Umbraco.Core/TypeFinder.cs b/src/Umbraco.Core/TypeFinder.cs index 26abad0f2e..2af6e99cc7 100644 --- a/src/Umbraco.Core/TypeFinder.cs +++ b/src/Umbraco.Core/TypeFinder.cs @@ -139,7 +139,6 @@ namespace Umbraco.Core { lock (LocalFilteredAssemblyCacheLocker) { - // double check if (_localFilteredAssemblyCache != null) return _localFilteredAssemblyCache; diff --git a/src/Umbraco.Core/TypeHelper.cs b/src/Umbraco.Core/TypeHelper.cs index b63205ae3d..869b72f1a5 100644 --- a/src/Umbraco.Core/TypeHelper.cs +++ b/src/Umbraco.Core/TypeHelper.cs @@ -13,9 +13,12 @@ namespace Umbraco.Core /// internal static class TypeHelper { - - private static readonly ConcurrentDictionary GetFieldsCache = new ConcurrentDictionary(); - private static readonly ConcurrentDictionary, PropertyInfo[]> GetPropertiesCache = new ConcurrentDictionary, PropertyInfo[]>(); + private static readonly ConcurrentDictionary, PropertyInfo[]> GetPropertiesCache + = new ConcurrentDictionary, PropertyInfo[]>(); + private static readonly ConcurrentDictionary GetFieldsCache + = new ConcurrentDictionary(); + + private static readonly Assembly[] EmptyAssemblies = new Assembly[0]; /// /// Checks if the method is actually overriding a base method @@ -39,12 +42,9 @@ namespace Umbraco.Core /// public static Assembly[] GetReferencingAssemblies(Assembly assembly, IEnumerable assemblies) { - // check if it is the app_code assembly. - // check if it is App_global.asax assembly if (assembly.IsAppCodeAssembly() || assembly.IsGlobalAsaxAssembly()) - { - return Enumerable.Empty().ToArray(); - } + return EmptyAssemblies; + // find all assembly references that are referencing the current type's assembly since we // should only be scanning those assemblies because any other assembly will definitely not @@ -54,7 +54,7 @@ namespace Umbraco.Core } /// - /// checks if the assembly has a reference with the same name as the expected assembly name. + /// Determines if an assembly references another assembly. /// /// /// @@ -105,13 +105,10 @@ namespace Umbraco.Core public static Attempt GetLowestBaseType(params Type[] types) { if (types.Length == 0) - { return Attempt.Fail(); - } - if (types.Length == 1) - { + + if (types.Length == 1) return Attempt.Succeed(types[0]); - } foreach (var curr in types) { @@ -195,20 +192,15 @@ namespace Umbraco.Core /// /// /// - public static PropertyInfo GetProperty(Type type, string name, - bool mustRead = true, - bool mustWrite = true, + public static PropertyInfo GetProperty(Type type, string name, + bool mustRead = true, + bool mustWrite = true, bool includeIndexed = false, bool caseSensitive = true) { - return CachedDiscoverableProperties(type, mustRead, mustWrite, includeIndexed) - .FirstOrDefault(x => - { - if (caseSensitive) - return x.Name == name; - return x.Name.InvariantEquals(name); - }); - } + return CachedDiscoverableProperties(type, mustRead, mustWrite, includeIndexed) + .FirstOrDefault(x => caseSensitive ? (x.Name == name) : x.Name.InvariantEquals(name)); + } /// /// Gets (and caches) discoverable in the current for a given . @@ -221,7 +213,7 @@ namespace Umbraco.Core type, x => type .GetFields(BindingFlags.Public | BindingFlags.Instance) - .Where(y => !y.IsInitOnly) + .Where(y => y.IsInitOnly == false) .ToArray()); } @@ -239,13 +231,12 @@ namespace Umbraco.Core new Tuple(type, mustRead, mustWrite, includeIndexed), x => type .GetProperties(BindingFlags.Public | BindingFlags.Instance) - .Where(y => (!mustRead || y.CanRead) - && (!mustWrite || y.CanWrite) - && (includeIndexed || !y.GetIndexParameters().Any())) + .Where(y => (mustRead == false || y.CanRead) + && (mustWrite == false || y.CanWrite) + && (includeIndexed || y.GetIndexParameters().Any() == false)) .ToArray()); } - #region Match Type //TODO: Need to determine if these methods should replace/combine/merge etc with IsTypeAssignableFrom, IsAssignableFromGeneric @@ -336,9 +327,9 @@ namespace Umbraco.Core // not a generic type, not a generic parameter // so normal class or interface - // fixme structs? enums? array types? // about primitive types, value types, etc: // http://stackoverflow.com/questions/1827425/how-to-check-programatically-if-a-type-is-a-struct-or-a-class + // if it's a primitive type... it needs to be == if (implementation == contract) return true; if (contract.IsClass && implementation.IsClass && implementation.IsSubclassOf(contract)) return true;