CssInCSharp 0.1.0-nightly-240529014856
CssInCSharp
A lib for generating Style Sheets with C#.
Getting started
dotnet add package CssInCSharp
Usage
<div class="basic">
<div class="title">Title</div>
<button class="button">Click</button>
</div>
<style>
@_css
</style>
@code
{
private string _css = string.Empty;
protected override void OnInitialized()
{
_css = new CSSObject
{
[".basic"] = new CSSObject
{
Width = 300,
Height = 300,
Border = "1px solid #DDD",
["& .title"] = new CSSObject
{
LineHeight = 20,
Color = "red"
},
["& .button"] = new CSSObject
{
Width = "100%",
Height = "20px",
TextAlign = "center",
["&:hover"] = new CSSObject
{
Color = "blue"
}
}
}
}.ToString();
}
}
For other examples, you can check out the example code.
Css Compiler
The CssInCSharp is similar to less or sass. You can simply convert you style file into C# class, so that you can make full use of the C# language features to generate style content.
Benchmark
BenchmarkDotNet v0.13.12, Windows 11 (10.0.22631.3593/23H2/2023Update/SunValley3)
AMD Ryzen 7 5700G with Radeon Graphics, 1 CPU, 16 logical and 8 physical cores
.NET SDK 8.0.300
[Host] : .NET 8.0.5 (8.0.524.21615), X64 RyuJIT AVX2
.NET 5.0 : .NET 5.0.17 (5.0.1722.21314), X64 RyuJIT AVX2
.NET 6.0 : .NET 6.0.28 (6.0.2824.12007), X64 RyuJIT AVX2
.NET 7.0 : .NET 7.0.17 (7.0.1724.11508), X64 RyuJIT AVX2
.NET 8.0 : .NET 8.0.5 (8.0.524.21615), X64 RyuJIT AVX2
Method | Job | Runtime | Mean | Error | StdDev | Ratio | RatioSD | Gen0 | Gen1 | Allocated | Alloc Ratio |
---|---|---|---|---|---|---|---|---|---|---|---|
CreateCss | .NET 5.0 | .NET 5.0 | 58.99 μs | 1.179 μs | 2.001 μs | 1.00 | 0.00 | 18.4326 | 0.9766 | 150.64 KB | 1.00 |
CreateCss | .NET 6.0 | .NET 6.0 | 55.16 μs | 1.076 μs | 1.797 μs | 0.94 | 0.04 | 17.6392 | 1.0376 | 144.36 KB | 0.96 |
CreateCss | .NET 7.0 | .NET 7.0 | 50.61 μs | 0.999 μs | 2.062 μs | 0.87 | 0.05 | 17.6392 | 1.0376 | 144.42 KB | 0.96 |
CreateCss | .NET 8.0 | .NET 8.0 | 37.73 μs | 0.748 μs | 1.642 μs | 0.65 | 0.03 | 17.6392 | 0.9155 | 144.3 KB | 0.96 |
Showing the top 20 packages that depend on CssInCSharp.
Packages | Downloads |
---|---|
AntDesign
🌈 A set of enterprise-class UI components based on Ant Design and Blazor.
|
2 |
AntDesign
🌈 A set of enterprise-class UI components based on Ant Design and Blazor WebAssembly.
|
4 |
AntDesign
🌈 A set of enterprise-class UI components based on Ant Design and Blazor WebAssembly.
|
5 |
AntDesign
🌈 A set of enterprise-class UI components based on Ant Design and Blazor WebAssembly.
|
7 |
.NET 5.0
- Microsoft.AspNetCore.Components.Web (>= 5.0.0)
.NET 6.0
- Microsoft.AspNetCore.Components.Web (>= 6.0.0)
.NET 7.0
- Microsoft.AspNetCore.Components.Web (>= 7.0.0)
.NET 8.0
- Microsoft.AspNetCore.Components.Web (>= 8.0.0)
.NET Standard 2.1
- Microsoft.AspNetCore.Components.Web (>= 3.1.0)
Version | Downloads | Last updated |
---|---|---|
0.1.0-nightly-240716071233 | 4 | 11/28/2024 |
0.1.0-nightly-240715081344 | 4 | 12/03/2024 |
0.1.0-nightly-240712075841 | 4 | 12/02/2024 |
0.1.0-nightly-240710022306 | 6 | 11/26/2024 |
0.1.0-nightly-240710013120 | 4 | 12/04/2024 |
0.1.0-nightly-240628091509 | 4 | 12/02/2024 |
0.1.0-nightly-240625033115 | 6 | 11/27/2024 |
0.1.0-nightly-240529041709 | 6 | 12/01/2024 |
0.1.0-nightly-240529014856 | 5 | 11/18/2024 |
0.1.0-nightly-240528100520 | 4 | 12/04/2024 |
0.1.0-nightly-240110064300 | 5 | 11/30/2024 |
0.1.0-nightly-231229073125 | 3 | 12/02/2024 |
0.1.0-nightly-231229024140 | 4 | 12/01/2024 |
0.1.0-nightly-231225064316 | 5 | 11/18/2024 |
0.1.0-nightly-231222093849 | 4 | 11/30/2024 |
0.1.0-nightly-231218032026 | 4 | 11/27/2024 |
0.1.0-nightly-231215093440 | 8 | 12/02/2024 |
0.1.0-nightly-231214104150 | 4 | 12/04/2024 |
0.1.0-nightly-231213123405 | 4 | 11/29/2024 |
0.1.0-nightly-231212143446 | 6 | 11/29/2024 |
0.1.0-nightly-231211073331 | 4 | 12/02/2024 |
0.1.0-nightly-231202142232 | 4 | 12/02/2024 |
0.1.0-nightly-231202062218 | 6 | 11/28/2024 |
0.1.0-nightly-231202054543 | 4 | 11/27/2024 |