From 8de900ea1a4e82ca81d6adc5a32fec906bdd8329 Mon Sep 17 00:00:00 2001 From: zhaowenkai <799480165@qq.com> Date: Mon, 18 Dec 2023 11:01:11 +0800 Subject: [PATCH] fix serialize error when CSSObject is null --- src/Extensions/CSSInterpolationExtension.cs | 11 ++++++++--- src/Styles/Style.cs | 2 +- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/Extensions/CSSInterpolationExtension.cs b/src/Extensions/CSSInterpolationExtension.cs index 64a2ae2..930ac19 100644 --- a/src/Extensions/CSSInterpolationExtension.cs +++ b/src/Extensions/CSSInterpolationExtension.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; namespace CssInCSharp { @@ -8,7 +9,11 @@ public static CSSObject[] ToCssArray(this CSSInterpolation value) { if (value.IsT0) { - return new[] { value.AsT0 }; + if (value.AsT0 == null) + { + return Array.Empty(); + } + return new CSSObject[] { value.AsT0 }; } else if (value.IsT1) { @@ -21,7 +26,7 @@ public static CSSObject[] ToCssArray(this CSSInterpolation value) } else { - return new CSSObject[] { }; + return Array.Empty(); } } } diff --git a/src/Styles/Style.cs b/src/Styles/Style.cs index 740ff40..a705588 100644 --- a/src/Styles/Style.cs +++ b/src/Styles/Style.cs @@ -30,7 +30,7 @@ protected override void BuildRenderTree(RenderTreeBuilder builder) var sb = new StringBuilder(); foreach (var css in csses) { - sb.Append(css.SerializeCss(HashId)); + sb.Append(css?.SerializeCss(HashId)); } return new StyleCache.Item {