Skip to content

Commit 72a802d

Browse files
committed
Update nuget readme
1 parent 43c0ea0 commit 72a802d

File tree

2 files changed

+118
-2
lines changed

2 files changed

+118
-2
lines changed

README_nuget.md

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
# FastGenericNew [![Tests](https://github.com/Nyerst/FastGenericNew/actions/workflows/tests.yml/badge.svg)](https://github.com/Nyerst/FastGenericNew/actions/workflows/tests.yml) [![](https://img.shields.io/nuget/vpre/FastGenericNew)](https://www.nuget.org/packages/FastGenericNew/) [![](https://img.shields.io/nuget/vpre/FastGenericNew.SourceGenerator?label=SourceGenerator)](https://www.nuget.org/packages/FastGenericNew.SourceGenerator/)
2+
3+
The ultimate fast and powerful alternative to `Activator.CreateInstance<T>` / `new T()`
4+
5+
## ✨ Features
6+
7+
- ✔️ **The best** `CreateInstance` ever
8+
- Up to 50x faster than `Activator.CreateInstance<T>`
9+
- Generic Parameters Support
10+
- Zero boxing/unboxing
11+
- TryGetValue-like TryFastNew API
12+
- Link Mode `PublishTrimmed` Support
13+
- Non-Public Constructor Support
14+
- No Generic Constraints
15+
- Compatible with .NET Standard 2.0
16+
- Multiple backend implementations
17+
- Heavily tested on Win/Mac/Linux
18+
19+
- 🪛 **Modern** Compiler Integration
20+
- Source Generator v2 (Incremental Generator)
21+
- Highly Configurable ([Props](https://github.com/Nyrest/FastGenericNew/wiki/SourceGenerator-Options))
22+
- Multi-threaded Generation
23+
24+
- 🔥 **Latest** C#/.NET Features Support
25+
- [C# 8 Nullable](https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/builtin-types/nullable-reference-types) Support
26+
- [C# 10 Parameterless struct constructors](https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/proposals/csharp-10.0/parameterless-struct-constructors) Support (Both invokes or not)
27+
- WebAssembly Support
28+
29+
## 🔧 Installation
30+
31+
> You should only use one of them
32+
33+
### Pre-Compiled Version
34+
35+
```powershell
36+
dotnet add package FastGenericNew --version 3.3.0
37+
```
38+
39+
```xml
40+
<ItemGroup>
41+
<PackageReference Include="FastGenericNew" Version="3.3.0" />
42+
</ItemGroup>
43+
```
44+
45+
### SourceGenerator Version
46+
47+
```powershell
48+
dotnet add package FastGenericNew.SourceGenerator --version 3.3.0
49+
```
50+
51+
```xml
52+
<ItemGroup>
53+
<PackageReference Include="FastGenericNew.SourceGenerator" Version="3.3.0" />
54+
</ItemGroup>
55+
```
56+
#### SourceGeneratorV2 requires
57+
> ***.NET Standard 2.0*** or above
58+
> ***C# 8.0*** or above
59+
> ***Roslyn 4.0.1*** or above
60+
> ***Modern IDE*** *(Optional)* [VS2022, Rider, VSCode]
61+
62+
## 📖 Examples
63+
64+
```cs
65+
using FastGenericNew;
66+
67+
// Simply replace 'Activator' to 'FastNew'
68+
var obj = FastNew.CreateInstance<T>();
69+
70+
// With parameter(s)
71+
var obj2 = FastNew.CreateInstance<T, string>("text");
72+
var obj3 = FastNew.CreateInstance<T, string, int>("text", 0);
73+
74+
// Try pattern
75+
// NOTE: The try pattern will only check if the constructor can be called.
76+
// It will not catch or handle any exceptions thrown in the constructor.
77+
if (FastNew.TryCreateInstance<T, string>("arg0", out T result));
78+
{
79+
// ...
80+
}
81+
```
82+
83+
### Notes
84+
85+
> **With .NET Framework**, `Activator.CreateInstance<T>()` invokes the parameterless constructor of **ValueType** if
86+
> the constraint is `where T : new()` but appears to **ignore the parameterless constructor if the constraint is `where T : struct`**.
87+
> **But `FastNew.CreateInstance<T>()` will always invoke the parameterless constructor if it's available.**
88+
>
89+
> If you don't want to invoke the parameterless constructor of **ValueType**,
90+
> consider using `FastNew.NewOrDefault<T>()` which **will never invoke the parameterless constructor of `ValueType`**
91+
92+
## 🚀 Benchmark
93+
94+
### **Environment**
95+
96+
``` ini
97+
BenchmarkDotNet=v0.13.1, OS=Windows 10.0.22000
98+
AMD Ryzen 9 3900X, 1 CPU, 24 logical and 12 physical cores
99+
.NET SDK=6.0.200-preview.22055.15
100+
[Host] : .NET 6.0.2 (6.0.222.6406), X64 RyuJIT
101+
.NET 5.0 : .NET 5.0.14 (5.0.1422.5710), X64 RyuJIT
102+
.NET 6.0 : .NET 6.0.2 (6.0.222.6406), X64 RyuJIT
103+
.NET Framework 4.8 : .NET Framework 4.8 (4.8.4470.0), X64 RyuJIT
104+
```
105+
106+
### Reference Types
107+
108+
[![Benchmark Result of Reference Types](https://raw.githubusercontent.com/Nyrest/FastGenericNew/main/Assets/Benchmark_ReferenceType.png)](https://github.com/Nyrest/FastGenericNew/blob/main/FastGenericNew.Benchmarks/Benchmarks/ReferenceTypeBenchmark.cs)
109+
110+
### Value Types
111+
112+
[![Benchmark Result of Value Types](https://raw.githubusercontent.com/Nyrest/FastGenericNew/main/Assets/Benchmark_ValueType.png)](https://github.com/Nyrest/FastGenericNew/blob/main/FastGenericNew.Benchmarks/Benchmarks/ValueTypeBenchmark.cs)
113+
114+
## 📜 License
115+
116+
FastGenericNew is licensed under the [MIT](LICENSE) license.

src/FastGenericNew.Shared.props

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<!-- Nuget Logo -->
1010
<None Include="..\..\Assets\Logo.png" Pack="true" PackagePath="\" />
1111
<!-- Nuget Readme -->
12-
<None Include="..\..\README.md" Pack="true" PackagePath="\" />
12+
<None Include="..\..\README_nuget.md" Pack="true" PackagePath="\" />
1313
</ItemGroup>
1414

1515
<!-- Nuget Package Properties -->
@@ -33,7 +33,7 @@ C# 10 Parameterless struct constructors Support (Both invokes or not)
3333
<RepositoryType>git</RepositoryType>
3434
<PackageProjectUrl>https://github.com/Nyrest/FastGenericNew</PackageProjectUrl>
3535
<PackageTags>Performance, Fast, Generic, New, Expression, Optimization, CreateInstance, Activator, DynamicMethod, $(PackageTagsPostfix)</PackageTags>
36-
<PackageReadmeFile>README.md</PackageReadmeFile>
36+
<PackageReadmeFile>README_nuget.md</PackageReadmeFile>
3737
<PackageIcon>Logo.png</PackageIcon>
3838
<IsPackable>true</IsPackable>
3939
</PropertyGroup>

0 commit comments

Comments
 (0)