Skip to content

Commit

Permalink
fix serialize error when CSSObject is null (#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
yoli799480165 authored Dec 18, 2023
1 parent 7db164a commit 46e047e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
11 changes: 8 additions & 3 deletions src/Extensions/CSSInterpolationExtension.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;

namespace CssInCSharp
{
Expand All @@ -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<CSSObject>();
}
return new CSSObject[] { value.AsT0 };
}
else if (value.IsT1)
{
Expand All @@ -21,7 +26,7 @@ public static CSSObject[] ToCssArray(this CSSInterpolation value)
}
else
{
return new CSSObject[] { };
return Array.Empty<CSSObject>();
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Styles/Style.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down

0 comments on commit 46e047e

Please sign in to comment.