From a3ce88be4209fba7aa1b4468d84c9b75de47c4cb Mon Sep 17 00:00:00 2001 From: Argo-Tianyi Date: Tue, 2 Nov 2021 19:14:13 +0800 Subject: [PATCH 1/5] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=20ConvertToString?= =?UTF-8?q?=20=E7=A7=81=E6=9C=89=E7=B1=BB=E6=8A=A5=E5=BC=82=E5=B8=B8?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/BootstrapBlazor/Utils/CacheManager.cs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/BootstrapBlazor/Utils/CacheManager.cs b/src/BootstrapBlazor/Utils/CacheManager.cs index 566d888a0..6cce70459 100644 --- a/src/BootstrapBlazor/Utils/CacheManager.cs +++ b/src/BootstrapBlazor/Utils/CacheManager.cs @@ -3,7 +3,6 @@ // Website: https://www.blazor.zone or https://argozhang.github.io/ using BootstrapBlazor.Localization.Json; -using Microsoft.AspNetCore.Components; using Microsoft.Extensions.Caching.Memory; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; @@ -325,8 +324,8 @@ namespace BootstrapBlazor.Components var cacheKey = $"Lambda-{nameof(CreateConverterInvoker)}-{type.FullName}"; return CacheManager.GetOrCreate(cacheKey, entry => { - var method = typeof(Utility) - .GetMethod(nameof(ConvertToString), BindingFlags.NonPublic | BindingFlags.Static)! + var method = typeof(CacheManager) + .GetMethod(nameof(CacheManager.ConvertToString), BindingFlags.NonPublic | BindingFlags.Static)! .MakeGenericMethod(type); var para_exp = Expression.Parameter(typeof(object)); @@ -336,11 +335,12 @@ namespace BootstrapBlazor.Components entry.SetDynamicAssemblyPolicy(type); return Expression.Lambda>>(body, para_exp).Compile(); - static IEnumerable ConvertToString(List source) => source is List list - ? list.Select(i => i.Value) - : source.Select(i => i?.ToString()); }); } + + private static IEnumerable ConvertToString(List source) => source is List list + ? list.Select(i => i.Value) + : source.Select(i => i?.ToString()); #endregion #region Format -- Gitee From 0b08edf95d1ae0452c61029a33c8c4c61c073263 Mon Sep 17 00:00:00 2001 From: Argo-Tianyi Date: Tue, 2 Nov 2021 19:14:25 +0800 Subject: [PATCH 2/5] =?UTF-8?q?feat:=20=E5=A2=9E=E5=8A=A0=E6=97=A5?= =?UTF-8?q?=E5=BF=97=E6=A8=A1=E5=9D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/BootstrapBlazor.Server/Startup.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/BootstrapBlazor.Server/Startup.cs b/src/BootstrapBlazor.Server/Startup.cs index 0b7b67877..b586f3fcc 100644 --- a/src/BootstrapBlazor.Server/Startup.cs +++ b/src/BootstrapBlazor.Server/Startup.cs @@ -54,6 +54,7 @@ namespace BootstrapBlazor.Server { Encoding.RegisterProvider(CodePagesEncodingProvider.Instance); + services.AddLogging(); services.AddCors(); services.AddResponseCompression(); -- Gitee From a032c399ae9ec48650fceae92e758c93042fb44d Mon Sep 17 00:00:00 2001 From: Argo-Tianyi Date: Tue, 2 Nov 2021 20:14:33 +0800 Subject: [PATCH 3/5] =?UTF-8?q?test:=20=E6=9B=B4=E6=96=B0=E5=8D=95?= =?UTF-8?q?=E5=85=83=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/BootstrapBlazor/Utils/CacheManager.cs | 4 ++-- test/UnitTest/Performance/ReflectionTest.cs | 17 ++++++++--------- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/src/BootstrapBlazor/Utils/CacheManager.cs b/src/BootstrapBlazor/Utils/CacheManager.cs index 6cce70459..c406aaf5a 100644 --- a/src/BootstrapBlazor/Utils/CacheManager.cs +++ b/src/BootstrapBlazor/Utils/CacheManager.cs @@ -35,8 +35,8 @@ namespace BootstrapBlazor.Components //$"Placeholder-{modelType.Name}-{fieldName}"; //$"GetProperty-{modelType.Name}-{fieldName}"; - //$"Lambda-{nameof(LambdaExtensions.GetPropertyValueLambda)}-{typeof(TModel).Name}-{fieldName}"; - //$"Lambda-{nameof(LambdaExtensions.SetPropertyValueLambda)}-{typeof(TModel).Name}-{fieldName}"; + //("Lambda-Get", model, fieldName); + //("Lambda-Set", model, fieldName, typeof(TValue)); //$"Lambda-{nameof(LambdaExtensions.GetSortLambda)}-{typeof(T).Name}"; //$"Lambda-{nameof(CreateConverterInvoker)}-{type.Name}"; diff --git a/test/UnitTest/Performance/ReflectionTest.cs b/test/UnitTest/Performance/ReflectionTest.cs index 002d94f88..39aee8899 100644 --- a/test/UnitTest/Performance/ReflectionTest.cs +++ b/test/UnitTest/Performance/ReflectionTest.cs @@ -2,12 +2,14 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Website: https://www.blazor.zone or https://argozhang.github.io/ +using BootstrapBlazor.Components; using System; using System.Diagnostics; using System.Linq; using System.Linq.Expressions; using Xunit; using Xunit.Abstractions; +using static System.Net.Mime.MediaTypeNames; namespace UnitTest.Performance { @@ -108,14 +110,11 @@ namespace UnitTest.Performance sw.Stop(); Logger.WriteLine($"Reflection: {sw.Elapsed}"); - var target = Expression.Parameter(typeof(Dummy)); - Expression expression = Expression.Call(target, mi); - var func = Expression.Lambda>(expression, target).Compile(); - + var invoker = LambdaExtensions.GetPropertyValueLambda(s1, "Name").Compile(); sw = Stopwatch.StartNew(); for (var i = 0; i < count; i++) { - func.Invoke(s1); + invoker.Invoke(s1); } sw.Stop(); Logger.WriteLine($"Expression: {sw.Elapsed}"); @@ -127,14 +126,14 @@ namespace UnitTest.Performance { var test = new Dummy { Name = "Test" }; var count = 10000000; - var obj = LambdaExtensions.GetPropertyValue(test, "Name"); + var invoker = LambdaExtensions.GetPropertyValueLambda(test, "Name").Compile(); var stopWatch = Stopwatch.StartNew(); for (int i = 0; i < count; i++) { - LambdaExtensions.GetPropertyValue(test, "Name"); + invoker(test); } stopWatch.Stop(); - Logger.WriteLine($"Expression: {stopWatch.ElapsedMilliseconds}"); + Logger.WriteLine($"Expression: {stopWatch.Elapsed}"); var objectType = test.GetType(); var method = objectType.GetProperty("Name")?.GetGetMethod(false); @@ -145,7 +144,7 @@ namespace UnitTest.Performance proxy(test); } stopWatch.Stop(); - Logger.WriteLine($"Delegate: {stopWatch.ElapsedMilliseconds}"); + Logger.WriteLine($"Delegate: {stopWatch.Elapsed}"); } private class Dummy -- Gitee From 4ccab19f9c7bfcdf4ca31bc6226988474e264cd5 Mon Sep 17 00:00:00 2001 From: Argo-Tianyi Date: Tue, 2 Nov 2021 20:37:47 +0800 Subject: [PATCH 4/5] =?UTF-8?q?doc:=20=E7=A7=BB=E9=99=A4=E6=B3=A8=E9=87=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/BootstrapBlazor/Utils/CacheManager.cs | 7 ------- 1 file changed, 7 deletions(-) diff --git a/src/BootstrapBlazor/Utils/CacheManager.cs b/src/BootstrapBlazor/Utils/CacheManager.cs index c406aaf5a..05248a3ea 100644 --- a/src/BootstrapBlazor/Utils/CacheManager.cs +++ b/src/BootstrapBlazor/Utils/CacheManager.cs @@ -251,13 +251,6 @@ namespace BootstrapBlazor.Components } #region Lambda Property - /// - /// - /// - /// - /// - /// - /// internal static bool TryGetProperty(Type modelType, string fieldName, [NotNullWhen(true)] out PropertyInfo? propertyInfo) { var cacheKey = $"GetProperty-{modelType.FullName}-{fieldName}"; -- Gitee From 30b06aabca2a4cdeafec9bbb8f4884e98a26383d Mon Sep 17 00:00:00 2001 From: Argo-Tianyi Date: Tue, 2 Nov 2021 20:38:00 +0800 Subject: [PATCH 5/5] =?UTF-8?q?fix:=20=E6=9B=B4=E6=96=B0=20Key=20=E9=98=B2?= =?UTF-8?q?=E6=AD=A2=E5=86=B2=E7=AA=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/BootstrapBlazor/Utils/CacheManager.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/BootstrapBlazor/Utils/CacheManager.cs b/src/BootstrapBlazor/Utils/CacheManager.cs index 05248a3ea..3abe52bc3 100644 --- a/src/BootstrapBlazor/Utils/CacheManager.cs +++ b/src/BootstrapBlazor/Utils/CacheManager.cs @@ -277,7 +277,7 @@ namespace BootstrapBlazor.Components internal static TResult GetPropertyValue(TModel model, string fieldName) { var type = model is object o ? o.GetType() : typeof(TModel); - var cacheKey = ("Lambda-Get", model, fieldName); + var cacheKey = ("Lambda-Get", type, fieldName, typeof(TResult)); var invoker = CacheManager.GetOrCreate(cacheKey, entry => { entry.SetDynamicAssemblyPolicy(type); @@ -289,7 +289,7 @@ namespace BootstrapBlazor.Components internal static void SetPropertyValue(TModel model, string fieldName, TValue value) { var type = model is object o ? o.GetType() : typeof(TModel); - var cacheKey = ("Lambda-Set", model, fieldName, typeof(TValue)); + var cacheKey = ("Lambda-Set", type, fieldName, typeof(TValue)); var invoker = CacheManager.GetOrCreate(cacheKey, entry => { entry.SetDynamicAssemblyPolicy(type); -- Gitee