From 376f9c0837f7ea98ffc2699ea2aca37df10315d9 Mon Sep 17 00:00:00 2001 From: Chris Cameron Date: Thu, 8 Nov 2018 11:46:14 -0500 Subject: [PATCH] refactor: Removing unused code --- ICD.Common.Utils/AttributeUtils.cs | 67 ++---------------------------- 1 file changed, 3 insertions(+), 64 deletions(-) diff --git a/ICD.Common.Utils/AttributeUtils.cs b/ICD.Common.Utils/AttributeUtils.cs index ac671ef..d2977d8 100644 --- a/ICD.Common.Utils/AttributeUtils.cs +++ b/ICD.Common.Utils/AttributeUtils.cs @@ -24,7 +24,6 @@ namespace ICD.Common.Utils private static readonly IcdHashSet s_CachedAssemblies; private static readonly IcdHashSet s_CachedTypes; - private static readonly Dictionary s_AttributeToMethodCache; private static readonly Dictionary s_AttributeToTypeCache; private static readonly Dictionary> s_TypeToAttributesCache; @@ -38,26 +37,12 @@ namespace ICD.Common.Utils s_CachedAssemblies = new IcdHashSet(); s_CachedTypes = new IcdHashSet(); - s_AttributeToMethodCache = new Dictionary(); s_AttributeToTypeCache = new Dictionary(); s_TypeToAttributesCache = new Dictionary>(); } #region Caching - /// - /// Pre-emptively caches the given assemblies for lookup. - /// - /// - public static void CacheAssemblies(IEnumerable assemblies) - { - if (assemblies == null) - throw new ArgumentNullException("assemblies"); - - foreach (Assembly assembly in assemblies) - CacheAssembly(assembly); - } - /// /// Pre-emptively caches the given assembly for lookup. /// @@ -70,6 +55,8 @@ namespace ICD.Common.Utils if (s_CachedAssemblies.Contains(assembly)) return true; + s_CachedAssemblies.Add(assembly); + #if SIMPLSHARP CType[] types; #else @@ -114,7 +101,6 @@ namespace ICD.Common.Utils foreach (var type in types) CacheType(type); - s_CachedAssemblies.Add(assembly); return true; } @@ -133,44 +119,23 @@ namespace ICD.Common.Utils if (s_CachedTypes.Contains(type)) return; + s_CachedTypes.Add(type); - MethodInfo[] methods; - try { s_TypeToAttributesCache[type] = new IcdHashSet(type.GetCustomAttributes(false)); foreach (Attribute attribute in s_TypeToAttributesCache[type]) s_AttributeToTypeCache[attribute] = type; - - methods = type.GetMethods(); } // GetMethods for Open Generic Types is not supported. catch (NotSupportedException) { - return; } // Not sure why this happens :/ catch (InvalidProgramException) { - return; } - - foreach (MethodInfo method in methods) - CacheMethod(method); - } - - /// - /// Caches the method. - /// - /// - private static void CacheMethod(MethodInfo method) - { - if (method == null) - throw new ArgumentNullException("method"); - - foreach (Attribute attribute in ReflectionExtensions.GetCustomAttributes(method, false)) - s_AttributeToMethodCache[attribute] = method; } #endregion @@ -252,32 +217,6 @@ namespace ICD.Common.Utils return s_AttributeToTypeCache[attribute]; } - /// - /// Gets all of the cached method attributes of the given type. - /// - /// - /// - public static IEnumerable GetMethodAttributes() - where T : Attribute - { - return s_AttributeToMethodCache.Select(p => p.Key) - .OfType() - .ToArray(); - } - - /// - /// Gets the cached method for the given attribute. - /// - /// - /// - public static MethodInfo GetMethod(Attribute attribute) - { - if (attribute == null) - throw new ArgumentNullException("attribute"); - - return s_AttributeToMethodCache[attribute]; - } - #endregion } }