diff --git a/ICD.Common.Utils.Tests/Attributes/KrangPluginAttributeTest.cs b/ICD.Common.Utils.Tests/Attributes/KrangPluginAttributeTest.cs deleted file mode 100644 index 7822902..0000000 --- a/ICD.Common.Utils.Tests/Attributes/KrangPluginAttributeTest.cs +++ /dev/null @@ -1,9 +0,0 @@ -using NUnit.Framework; - -namespace ICD.Common.Utils.Tests.Attributes -{ - [TestFixture] - public sealed class KrangPluginAttributeTest : AbstractIcdAttributeTest - { - } -} diff --git a/ICD.Common.Utils.Tests/Attributes/Rpc/RpcAttributeTest.cs b/ICD.Common.Utils.Tests/Attributes/Rpc/RpcAttributeTest.cs deleted file mode 100644 index e583b1c..0000000 --- a/ICD.Common.Utils.Tests/Attributes/Rpc/RpcAttributeTest.cs +++ /dev/null @@ -1,55 +0,0 @@ -using System.Collections.Generic; -using System.Linq; -using ICD.Common.Utils.Attributes.Rpc; -using NUnit.Framework; - -namespace ICD.Common.Utils.Tests.Attributes.Rpc -{ - [TestFixture] - public sealed class RpcAttributeTest : AbstractIcdAttributeTest - { - private class TestClass - { - [Rpc("A")] - public string TestProperty { get; set; } - - [Rpc("A")] - public void TestMethod() - { - } - - [Rpc("B")] - public void TestMethod(int a) - { - } - - [Rpc("C")] - public void TestMethod(int a, string b) - { - } - } - - [Test] - public void GetMethodTest() - { - TestClass instance = new TestClass(); - - Assert.NotNull(RpcAttribute.GetMethod(instance, "A", new object[] { })); - Assert.Null(RpcAttribute.GetMethod(instance, "B", new object[] { })); - Assert.NotNull(RpcAttribute.GetMethod(instance, "B", new object[] { 1 })); - Assert.NotNull(RpcAttribute.GetMethod(instance, "C", new object[] { 1, null })); - Assert.NotNull(RpcAttribute.GetMethod(instance, "C", new object[] { 1, "test" })); - } - - [Test] - public void GetPropertyTest() - { - TestClass instance = new TestClass(); - - Assert.NotNull(RpcAttribute.GetProperty(instance, "A", "test")); - Assert.NotNull(RpcAttribute.GetProperty(instance, "A", null)); - Assert.Null(RpcAttribute.GetProperty(instance, "B", "test")); - Assert.Null(RpcAttribute.GetProperty(instance, "B", 1)); - } - } -} diff --git a/ICD.Common.Utils/Attributes/Rpc/RpcAttribute.cs b/ICD.Common.Utils/Attributes/Rpc/RpcAttribute.cs deleted file mode 100644 index 067c7c1..0000000 --- a/ICD.Common.Utils/Attributes/Rpc/RpcAttribute.cs +++ /dev/null @@ -1,176 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using ICD.Common.Properties; -using ICD.Common.Utils.Collections; -using ICD.Common.Utils.Extensions; -#if SIMPLSHARP -using Crestron.SimplSharp.Reflection; -#else -using System.Reflection; -#endif - -namespace ICD.Common.Utils.Attributes.Rpc -{ - /// - /// Represents a method that can be called by the server via RPC. - /// - [PublicAPI] - [MeansImplicitUse] - [AttributeUsage(AttributeTargets.Method | AttributeTargets.Property, Inherited = true, AllowMultiple = false)] - public sealed class RpcAttribute : AbstractIcdAttribute - { - private static readonly Dictionary>> s_MethodCache; - private static readonly Dictionary>> s_PropertyCache; - - private static readonly SafeCriticalSection s_MethodCacheSection; - private static readonly SafeCriticalSection s_PropertyCacheSection; - - private readonly string m_Key; - - #region Constructors - - /// - /// Constructor. - /// - static RpcAttribute() - { - s_MethodCache = new Dictionary>>(); - s_PropertyCache = new Dictionary>>(); - - s_MethodCacheSection = new SafeCriticalSection(); - s_PropertyCacheSection = new SafeCriticalSection(); - } - - /// - /// Constructor. - /// - /// - public RpcAttribute(string key) - { - m_Key = key; - } - - #endregion - - #region Methods - - /// - /// Gets the method on the client with the given key, matching the parameter types. - /// - /// - /// - /// - /// - [CanBeNull] - public static MethodInfo GetMethod(object client, string key, IEnumerable parameters) - { - return GetMethods(client, key).FirstOrDefault(m => ReflectionUtils.MatchesMethodParameters(m, parameters)); - } - - /// - /// Gets the property on the client with the given key, matching the parameter type. - /// - /// - /// - /// - /// - [CanBeNull] - public static PropertyInfo GetProperty(object client, string key, object parameter) - { - return GetProperties(client, key).FirstOrDefault(p => ReflectionUtils.MatchesPropertyParameter(p, parameter)); - } - - #endregion - - #region Private Methods - - /// - /// Returns the methods on the client with the given key. - /// - /// - /// - /// - private static IEnumerable GetMethods(object client, string key) - { - s_MethodCacheSection.Enter(); - - try - { - Type clientType = client.GetType(); - - // Cache the methods for the key so subsequent calls are faster. - if (!s_MethodCache.ContainsKey(clientType)) - s_MethodCache[clientType] = new Dictionary>(); - - if (!s_MethodCache[clientType].ContainsKey(key)) - { - s_MethodCache[clientType][key] = - clientType -#if SIMPLSHARP - .GetCType() -#else - .GetTypeInfo() -#endif - .GetMethods(BindingFlags.Public | - BindingFlags.NonPublic | - BindingFlags.Instance) - .Where(m => ReflectionExtensions.GetCustomAttributes(m, true) - .Any(a => a.m_Key == key)) - .ToIcdHashSet(); - } - - return s_MethodCache[clientType][key]; - } - finally - { - s_MethodCacheSection.Leave(); - } - } - - /// - /// Returns the properties on the client with the given key. - /// - /// - /// - /// - private static IEnumerable GetProperties(object client, string key) - { - s_PropertyCacheSection.Enter(); - - try - { - Type clientType = client.GetType(); - - // Cache the properties for the key so subsequent calls are faster. - if (!s_PropertyCache.ContainsKey(clientType)) - s_PropertyCache[clientType] = new Dictionary>(); - - if (!s_PropertyCache[clientType].ContainsKey(key)) - { - s_PropertyCache[clientType][key] = - clientType -#if SIMPLSHARP - .GetCType() -#else - .GetTypeInfo() -#endif - .GetProperties(BindingFlags.Public | - BindingFlags.NonPublic | - BindingFlags.Instance) - .Where(p => p.CanWrite && ReflectionExtensions.GetCustomAttributes(p, true) - .Any(a => a.m_Key == key)) - .ToIcdHashSet(); - } - - return s_PropertyCache[clientType][key]; - } - finally - { - s_PropertyCacheSection.Leave(); - } - } - - #endregion - } -} diff --git a/ICD.Common.Utils/ICD.Common.Utils_SimplSharp.csproj b/ICD.Common.Utils/ICD.Common.Utils_SimplSharp.csproj index bea8f4e..e6a5e80 100644 --- a/ICD.Common.Utils/ICD.Common.Utils_SimplSharp.csproj +++ b/ICD.Common.Utils/ICD.Common.Utils_SimplSharp.csproj @@ -74,7 +74,6 @@ -