diff options
| author | Roy Ben Shabat <Roy.mail.net@gmail.com> | 2020-10-25 16:58:42 +0200 |
|---|---|---|
| committer | Roy Ben Shabat <Roy.mail.net@gmail.com> | 2020-10-25 16:58:42 +0200 |
| commit | d530d39d7ed9b05e3e233adc62dceba2fd17e1fe (patch) | |
| tree | 2e042288fdeedd12e3ca0ee331743ebc115eb4b2 /Software/Visual_Studio/Tango.Core | |
| parent | adaddad79352c156303e9178a6f172a18af50cd2 (diff) | |
| download | Tango-d530d39d7ed9b05e3e233adc62dceba2fd17e1fe.tar.gz Tango-d530d39d7ed9b05e3e233adc62dceba2fd17e1fe.zip | |
Improved extension methods support on procedures.
Drastically reduces procedure designer loading time.
DataStore proto support fully working and tested.
Diffstat (limited to 'Software/Visual_Studio/Tango.Core')
| -rw-r--r-- | Software/Visual_Studio/Tango.Core/ExtensionMethods/TypeExtensions.cs | 74 | ||||
| -rw-r--r-- | Software/Visual_Studio/Tango.Core/Tango.Core.csproj | 4 |
2 files changed, 69 insertions, 9 deletions
diff --git a/Software/Visual_Studio/Tango.Core/ExtensionMethods/TypeExtensions.cs b/Software/Visual_Studio/Tango.Core/ExtensionMethods/TypeExtensions.cs index 66978ec19..44297b277 100644 --- a/Software/Visual_Studio/Tango.Core/ExtensionMethods/TypeExtensions.cs +++ b/Software/Visual_Studio/Tango.Core/ExtensionMethods/TypeExtensions.cs @@ -10,6 +10,19 @@ using System.Threading.Tasks; /// </summary> public static class TypeExtensions { + private class AssemblyExtensionMethods + { + public Assembly Assembly { get; set; } + public List<MethodInfo> Methods { get; set; } + + public AssemblyExtensionMethods() + { + Methods = new List<MethodInfo>(); + } + } + + private static List<AssemblyExtensionMethods> _extensionMethodsCache = new List<AssemblyExtensionMethods>(); + /// <summary> /// Gets all the extension methods registered in the specified assembly. /// </summary> @@ -18,14 +31,61 @@ public static class TypeExtensions /// <returns></returns> public static IEnumerable<MethodInfo> GetExtensionMethods(this Type type, Assembly extensionsAssembly) { - var query = from t in extensionsAssembly.GetTypes() - where !t.IsGenericType && !t.IsNested - from m in t.GetMethods(BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic) - where m.IsDefined(typeof(System.Runtime.CompilerServices.ExtensionAttribute), false) - where m.GetParameters()[0].ParameterType == type - select m; + if (type.Name == "CalculateRequest") + { + + } + + var asmMethods = _extensionMethodsCache.FirstOrDefault(x => x.Assembly == extensionsAssembly); + + if (asmMethods == null) + { + var query = from t in extensionsAssembly.GetTypes() + where !t.IsGenericType && !t.IsNested + from m in t.GetMethods(BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic) + where m.IsDefined(typeof(System.Runtime.CompilerServices.ExtensionAttribute), false) + select m; + + asmMethods = new AssemblyExtensionMethods(); + asmMethods.Assembly = extensionsAssembly; + asmMethods.Methods = query.ToList(); + _extensionMethodsCache.Add(asmMethods); + } + + List<MethodInfo> methods = new List<MethodInfo>(); + + asmMethods.Methods.Where(x => x.GetParameters()[0].ParameterType.IsAssignableFrom(type)); + + foreach (var method in asmMethods.Methods) + { + var parameter = method.GetParameters()[0]; + + if (parameter.ParameterType.IsGenericParameter) + { + var constraints = parameter.ParameterType.GetGenericParameterConstraints().ToList(); + + if (constraints.Count > 0) + { + if (constraints[0].IsAssignableFrom(type)) + { + methods.Add(method); + } + else if (constraints[0].GetInterfaces().Any(x => x.IsAssignableFrom(type))) + { + methods.Add(method); + } + } + } + else + { + if (parameter.ParameterType.IsAssignableFrom(type)) + { + methods.Add(method); + } + } + } - return query; + return methods; } /// <summary> diff --git a/Software/Visual_Studio/Tango.Core/Tango.Core.csproj b/Software/Visual_Studio/Tango.Core/Tango.Core.csproj index 582fa9712..813a31443 100644 --- a/Software/Visual_Studio/Tango.Core/Tango.Core.csproj +++ b/Software/Visual_Studio/Tango.Core/Tango.Core.csproj @@ -155,7 +155,7 @@ <Compile Include="ExtensionMethods\INotifyPropertyChangedExtensions.cs" /> <Compile Include="ExtensionMethods\ObservableCollectionExtensions.cs" /> <Compile Include="ExtensionMethods\IEnumerableExtensions.cs" /> - <Compile Include="ExtensionMethods\IMessageExtensions.cs" /> + <None Include="ExtensionMethods\IMessageExtensions.cs" /> <Compile Include="ExtensionMethods\IParameterizedExtensions.cs" /> <Compile Include="ExtensionMethods\ObjectExtensions.cs" /> <Compile Include="ExtensionMethods\ProcessExtensions.cs" /> @@ -220,7 +220,7 @@ <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <ProjectExtensions> <VisualStudio> - <UserProperties BuildVersion_AssemblyInfoFilename="Properties\AssemblyInfo.cs" BuildVersion_UpdateAssemblyVersion="True" BuildVersion_BuildVersioningStyle="None.None.Increment.TimeStamp" BuildVersion_UseGlobalSettings="False" BuildVersion_StartDate="2000/1/1" /> + <UserProperties BuildVersion_StartDate="2000/1/1" BuildVersion_UseGlobalSettings="False" BuildVersion_BuildVersioningStyle="None.None.Increment.TimeStamp" BuildVersion_UpdateAssemblyVersion="True" BuildVersion_AssemblyInfoFilename="Properties\AssemblyInfo.cs" /> </VisualStudio> </ProjectExtensions> <Import Project="..\packages\System.Data.SQLite.Core.1.0.108.0\build\net46\System.Data.SQLite.Core.targets" Condition="Exists('..\packages\System.Data.SQLite.Core.1.0.108.0\build\net46\System.Data.SQLite.Core.targets')" /> |
