chanan / BlazorStrap

Bootstrap 4 Components for Blazor Framework
https://blazorstrap.io
The Unlicense
910 stars 156 forks source link

BlazorStrap.CurrentTheme<Theme>() throws error (bootstrap not found because enum is Bootstrap #576

Closed Miatrix closed 1 year ago

Miatrix commented 1 year ago

Version 5.1.100

It looks like:

public T CurrentTheme() where T : Enum => (T) Enum.Parse(typeof (T), this._currentTheme);

should be changed to ignore case: public T CurrentTheme() where T : Enum => (T) Enum.Parse(typeof (T), this._currentTheme, true);

Here is how I'm calling it. @using Theme = BlazorStrap.V5.Theme .... if (Enum.TryParse(Settings.Theme, out var userTheme) && BlazorStrap.CurrentTheme() != userTheme) { .... }

Here is the error: blazor.webassembly.js:1 crit: Microsoft.AspNetCore.Components.WebAssembly.Rendering.WebAssemblyRenderer[100] Unhandled exception rendering component: Requested value 'bootstrap' was not found. System.ArgumentException: Requested value 'bootstrap' was not found. at System.Enum.TryParseByName[Int32](RuntimeType enumType, ReadOnlySpan1 value, Boolean ignoreCase, Boolean throwOnFailure, Int32& result) at System.Enum.TryParseByValueOrName[Int32](RuntimeType enumType, ReadOnlySpan1 value, Boolean ignoreCase, Boolean throwOnFailure, Int32& result) at System.Enum.TryParse(Type enumType, ReadOnlySpan`1 value, Boolean ignoreCase, Boolean throwOnFailure, Object& result) at System.Enum.Parse(Type enumType, String value, Boolean ignoreCase) at System.Enum.Parse(Type enumType, String value) at BlazorStrap.Service.BlazorStrapCore.CurrentTheme

jbomhold3 commented 1 year ago

What are you trying to do here?

Miatrix commented 1 year ago

I allow the user to pick what theme they want to display so I use something like this:

if (!string.IsNullOrWhiteSpace(Settings.Theme) && Enum.TryParse<BlazorStrap.V5.Theme>(Settings.Theme, out var userTheme) && BlazorStrap.CurrentTheme<BlazorStrap.V5.Theme>() != userTheme) await BlazorStrap.SetBootstrapCss(Settings.Theme, "5.1.3");

This worked fine in 5.0.106 but with 5.1.100 and the V5 package it gives the error due to bootstrap being lower case and the rest of the enums are Title Case. Should just be as easy as turning on the ignoreCase flag to prevent the error

jbomhold3 commented 1 year ago

Changed in 5.1.101

Miatrix commented 1 year ago

Confirmed fixed in 5.1.101 thanks