@@ -9,43 +9,11 @@ internal static class Extension
99
1010 public static MudTheme DeepClone ( this MudTheme source )
1111 {
12- // TODO: Needs this to be done https://github.com/MudBlazor/MudBlazor/pull/9434
13- //var themeType = typeof(MudTheme);
14- //var serializeStr = JsonSerializer.Serialize(source, themeType, ThemeSerializerContext);
15- //var copyObj = (MudTheme?)JsonSerializer.Deserialize(serializeStr, themeType, ThemeSerializerContext);
12+ var themeType = typeof ( MudTheme ) ;
13+ var serializeStr = JsonSerializer . Serialize ( source , themeType , ThemeSerializerContext ) ;
14+ var copyObj = ( MudTheme ? ) JsonSerializer . Deserialize ( serializeStr , themeType , ThemeSerializerContext ) ;
1615
17- //return copyObj;
18-
19- // Code below is a workaround for the above issue
20-
21- return new MudTheme
22- {
23- PaletteDark = source . PaletteDark . DeepClone ( ) ?? new PaletteDark ( ) ,
24- PaletteLight = source . PaletteLight . DeepClone ( ) ?? new PaletteLight ( ) ,
25- Shadows = DeepCloneTheme ( source . Shadows ) ?? new Shadow ( ) ,
26- LayoutProperties = DeepCloneTheme ( source . LayoutProperties ) ?? new LayoutProperties ( ) ,
27- ZIndex = DeepCloneTheme ( source . ZIndex ) ?? new ZIndex ( ) ,
28- PseudoCss = DeepCloneTheme ( source . PseudoCss ) ?? new PseudoCss ( ) ,
29- // Exception case
30- Typography = new Typography
31- {
32- Default = DeepCloneBaseTypography ( source . Typography . Default ) ,
33- H1 = DeepCloneBaseTypography ( source . Typography . H1 ) ,
34- H2 = DeepCloneBaseTypography ( source . Typography . H2 ) ,
35- H3 = DeepCloneBaseTypography ( source . Typography . H3 ) ,
36- H4 = DeepCloneBaseTypography ( source . Typography . H4 ) ,
37- H5 = DeepCloneBaseTypography ( source . Typography . H5 ) ,
38- H6 = DeepCloneBaseTypography ( source . Typography . H6 ) ,
39- Subtitle1 = DeepCloneBaseTypography ( source . Typography . Subtitle1 ) ,
40- Subtitle2 = DeepCloneBaseTypography ( source . Typography . Subtitle2 ) ,
41- Body1 = DeepCloneBaseTypography ( source . Typography . Body1 ) ,
42- Body2 = DeepCloneBaseTypography ( source . Typography . Body2 ) ,
43- Input = DeepCloneBaseTypography ( source . Typography . Input ) ,
44- Button = DeepCloneBaseTypography ( source . Typography . Button ) ,
45- Caption = DeepCloneBaseTypography ( source . Typography . Caption ) ,
46- Overline = DeepCloneBaseTypography ( source . Typography . Overline )
47- }
48- } ;
16+ return copyObj ?? new MudTheme ( ) ;
4917 }
5018
5119 public static PaletteDark ? DeepClone ( this PaletteDark source ) => DeepClonePalette ( source ) ;
@@ -60,38 +28,4 @@ public static MudTheme DeepClone(this MudTheme source)
6028
6129 return copyObj ;
6230 }
63-
64- private static T ? DeepCloneTheme < T > ( T source ) where T : class
65- {
66- var paletteType = typeof ( T ) ;
67- var serializeStr = JsonSerializer . Serialize ( source , paletteType , ThemeSerializerContext ) ;
68- var copyObj = ( T ? ) JsonSerializer . Deserialize ( serializeStr , paletteType , ThemeSerializerContext ) ;
69-
70- return copyObj ;
71- }
72-
73- private static T DeepCloneBaseTypography < T > ( T baseTypography ) where T : BaseTypography , new ( )
74- {
75- string [ ] fontFamilyCloned = new string [ baseTypography . FontFamily ? . Length ?? 0 ] ;
76- if ( baseTypography . FontFamily is not null )
77- {
78- Array . Copy ( baseTypography . FontFamily , fontFamilyCloned , baseTypography . FontFamily . Length ) ;
79- }
80-
81- var fontWeightCloned = baseTypography . FontWeight ;
82- var fontSizeCloned = baseTypography . FontSize ;
83- var lineHeightCloned = baseTypography . LineHeight ;
84- var letterSpacingCloned = baseTypography . LetterSpacing ;
85- var textTransformCloned = baseTypography . TextTransform ;
86-
87- return new T
88- {
89- FontWeight = fontWeightCloned ,
90- FontFamily = fontFamilyCloned ,
91- FontSize = fontSizeCloned ,
92- LineHeight = lineHeightCloned ,
93- LetterSpacing = letterSpacingCloned ,
94- TextTransform = textTransformCloned ,
95- } ;
96- }
9731}
0 commit comments