diff --git a/src/BootstrapBlazor.Server/Components/Components/ThemeChooser.razor.cs b/src/BootstrapBlazor.Server/Components/Components/ThemeChooser.razor.cs index b2c402f3fb4..f0ea4045a8b 100644 --- a/src/BootstrapBlazor.Server/Components/Components/ThemeChooser.razor.cs +++ b/src/BootstrapBlazor.Server/Components/Components/ThemeChooser.razor.cs @@ -42,7 +42,7 @@ private void OnClickTheme(SelectedItem item) { _currentTheme.Clear(); WebsiteOption.CurrentValue.CurrentTheme = item.Value; - var theme = WebsiteOption.CurrentValue.Themes.Find(i => i.Key == item.Value); + var theme = WebsiteOption.CurrentValue.Themes.FirstOrDefault(i => i.Key == item.Value); if (theme is { Files: not null }) { _currentTheme.AddRange(theme.Files); diff --git a/src/BootstrapBlazor.Server/Data/WebsiteOptions.cs b/src/BootstrapBlazor.Server/Data/WebsiteOptions.cs index c1c36ab6512..bf3fbb00f18 100644 --- a/src/BootstrapBlazor.Server/Data/WebsiteOptions.cs +++ b/src/BootstrapBlazor.Server/Data/WebsiteOptions.cs @@ -3,10 +3,12 @@ // See the LICENSE file in the project root for more information. // Maintainer: Argo Zhang(argo@live.ca) Website: https://www.blazor.zone +using System.Collections.Frozen; + namespace BootstrapBlazor.Server.Data; /// -/// +/// WebsiteOptions 网站配置类 /// public class WebsiteOptions { @@ -102,12 +104,12 @@ public class WebsiteOptions /// /// 获得/设置 资源配置集合 /// - public Dictionary SourceCodes { get; private set; } + public FrozenDictionary SourceCodes { get; private set; } /// /// 获得/设置 资源配置集合 /// - public Dictionary Videos { get; private set; } + public FrozenDictionary Videos { get; private set; } /// /// 获得/设置 当前主题 @@ -127,13 +129,13 @@ public class WebsiteOptions /// /// 获得/设置 当前网站友联集合 /// - public Dictionary Links { get; set; } + public FrozenDictionary Links { get; set; } /// /// 获得/设置 网站主题配置集合 /// [NotNull] - public List? Themes { get; set; } + public HashSet? Themes { get; set; } /// /// 构造函数 @@ -141,9 +143,9 @@ public class WebsiteOptions public WebsiteOptions() { var config = GetConfiguration("docs.json"); - SourceCodes = config.GetSection("src").GetChildren().Select(c => new KeyValuePair(c.Key, c.Value)).ToDictionary(item => item.Key, item => item.Value); - Videos = config.GetSection("video").GetChildren().Select(c => new KeyValuePair(c.Key, c.Value)).ToDictionary(item => item.Key, item => item.Value); - Links = config.GetSection("link").GetChildren().Select(c => new KeyValuePair(c.Key, c.Value)).ToDictionary(item => item.Key, item => item.Value); + SourceCodes = config.GetSection("src").GetChildren().Select(c => new KeyValuePair(c.Key, c.Value)).ToFrozenDictionary(item => item.Key, item => item.Value); + Videos = config.GetSection("video").GetChildren().Select(c => new KeyValuePair(c.Key, c.Value)).ToFrozenDictionary(item => item.Key, item => item.Value); + Links = config.GetSection("link").GetChildren().Select(c => new KeyValuePair(c.Key, c.Value)).ToFrozenDictionary(item => item.Key, item => item.Value); #if DEBUG IsDevelopment = true; diff --git a/src/BootstrapBlazor.Server/Services/CodeSnippetService.cs b/src/BootstrapBlazor.Server/Services/CodeSnippetService.cs index 23753976abb..d563d9577b6 100644 --- a/src/BootstrapBlazor.Server/Services/CodeSnippetService.cs +++ b/src/BootstrapBlazor.Server/Services/CodeSnippetService.cs @@ -4,6 +4,7 @@ // Maintainer: Argo Zhang(argo@live.ca) Website: https://www.blazor.zone using Microsoft.Extensions.Options; +using System.Collections.Frozen; namespace BootstrapBlazor.Server.Services; @@ -15,7 +16,7 @@ class CodeSnippetService private string SourceCodePath { get; set; } - private Dictionary SourceCodes { get; set; } + private FrozenDictionary SourceCodes { get; set; } private bool IsDevelopment { get; } @@ -62,7 +63,7 @@ public async Task GetCodeAsync(string codeFile) // codeFile = ajax.razor.cs var segs = codeFile.Split('.'); var key = segs[0]; - var typeName = SourceCodes.TryGetValue(key, out var value) ? value : string.Empty; + var typeName = SourceCodes.TryGetValue(key.ToLowerInvariant(), out var value) ? value : string.Empty; if (!string.IsNullOrEmpty(typeName)) { var fileName = codeFile.Replace(key, typeName);