-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #336 from ignatandrei/335-httpsgithubcomanderssonp…
…eterdolly 335 httpsgithubcomanderssonpeterdolly
- Loading branch information
Showing
56 changed files
with
968 additions
and
390 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,5 +31,6 @@ public enum Category | |
Mediator=26, | ||
SignalR=27, | ||
WinAPI = 28, | ||
Clone=29, | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
|
||
<h1>RSCG nr 175 : Dolly</h1> | ||
|
||
<h2>Info</h2> | ||
Nuget : <a href="https://www.nuget.org/packages/Dolly/" target="_blank">https://www.nuget.org/packages/Dolly/</a> | ||
|
||
<p>You can find more details at : <a href="https://github.com/AnderssonPeter/Dolly" target="_blank"> https://github.com/AnderssonPeter/Dolly</a></p> | ||
|
||
<p>Author :Peter Andersson</p> | ||
|
||
<p>Source : <a href="https://github.com/AnderssonPeter/Dolly" target="_blank">https://github.com/AnderssonPeter/Dolly</a> </p> | ||
|
||
<h2>About</h2> | ||
|
||
Clone objects with ease. | ||
|
||
<h2> | ||
How to use | ||
</h2> | ||
<h3> | ||
Add reference to the <a href="https://www.nuget.org/packages/Dolly/" target="_blank">Dolly</a> in the csproj | ||
</h3> | ||
<img src="images/Dolly/CloneData.csproj.png" width="580" height="580" /> | ||
|
||
<h3>This was for me the <b>starting</b> code</h3> | ||
|
||
<br /> | ||
I have <b>coded</b> the file Program.cs | ||
<br /> | ||
<img src="images/Dolly/csFiles/Program.cs.png" width="580" height="580" /> | ||
<hr /> | ||
|
||
<br /> | ||
I have <b>coded</b> the file Person.cs | ||
<br /> | ||
<img src="images/Dolly/csFiles/Person.cs.png" width="580" height="580" /> | ||
<hr /> | ||
<h3>And here are the <i>generated</i> files</h3> | ||
|
||
<br /> | ||
The file <i>generated</i> is ClonableAttribute.g.cs | ||
<br /> | ||
<img src="images/Dolly/generated/ClonableAttribute.g.cs.png" width="580" height="580" /> | ||
|
||
<br /> | ||
The file <i>generated</i> is CloneIgnoreAttribute.g.cs | ||
<br /> | ||
<img src="images/Dolly/generated/CloneIgnoreAttribute.g.cs.png" width="580" height="580" /> | ||
|
||
<br /> | ||
The file <i>generated</i> is IClonable.g.cs | ||
<br /> | ||
<img src="images/Dolly/generated/IClonable.g.cs.png" width="580" height="580" /> | ||
|
||
<br /> | ||
The file <i>generated</i> is Person.g.cs | ||
<br /> | ||
<img src="images/Dolly/generated/Person.g.cs.png" width="580" height="580" /> | ||
|
||
<p> | ||
You can download the code and this page as pdf from | ||
<a target="_blank" href='https://ignatandrei.github.io/RSCG_Examples/v2/docs/Dolly'> | ||
https://ignatandrei.github.io/RSCG_Examples/v2/docs/Dolly | ||
</a> | ||
</p> | ||
|
||
|
||
<p> | ||
You can see the whole list at | ||
<a target="_blank" href='https://ignatandrei.github.io/RSCG_Examples/v2/docs/List-of-RSCG'> | ||
https://ignatandrei.github.io/RSCG_Examples/v2/docs/List-of-RSCG | ||
</a> | ||
</p> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
{ | ||
"generator":{ | ||
"name":"Dolly", | ||
"nuget":[ | ||
"https://www.nuget.org/packages/Dolly/" | ||
], | ||
"link":"https://github.com/AnderssonPeter/Dolly", | ||
"author":"Peter Andersson", | ||
"source":"https://github.com/AnderssonPeter/Dolly" | ||
}, | ||
"data":{ | ||
"goodFor":["Clone objects with ease."], | ||
"csprojDemo":"CloneData.csproj", | ||
"csFiles":["Program.cs","Person.cs"], | ||
"excludeDirectoryGenerated":[""], | ||
"includeAdditionalFiles":[""] | ||
}, | ||
"links":{ | ||
"blog":"", | ||
"video":"" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Clone .net objects using source generation |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
<p align="center"> | ||
<a href="https://github.com/AnderssonPeter/Dolly"> | ||
Dolly | ||
</a> | ||
|
||
<h3 align="center">Dolly</h3> | ||
|
||
<p align="center"> | ||
Clone .net objects using source generation | ||
<br /> | ||
<br /> | ||
· | ||
<a href="https://github.com/AnderssonPeter/Dolly/issues">Report Bug</a> | ||
· | ||
<a href="https://github.com/AnderssonPeter/Dolly/issues">Request Feature</a> | ||
· | ||
</p> | ||
</p> | ||
<br /> | ||
|
||
[![NuGet version](https://badge.fury.io/nu/Dolly.svg)](https://www.nuget.org/packages/Dolly) | ||
[![Nuget](https://img.shields.io/nuget/dt/Dolly)](https://www.nuget.org/packages/Dolly) | ||
[![GitHub license](https://img.shields.io/badge/license-Apache%202-blue.svg)](https://raw.githubusercontent.com/AnderssonPeter/Dolly/main/LICENSE) | ||
|
||
[![unit tests](https://img.shields.io/github/actions/workflow/status/AnderssonPeter/Dolly/test.yml?branch=main&style=flat-square&label=unit%20tests)](https://github.com/AnderssonPeter/Dolly/actions/workflows/test.yml) | ||
[![Testspace tests](https://img.shields.io/testspace/tests/AnderssonPeter/AnderssonPeter:Dolly/main?style=flat-square)](https://anderssonpeter.testspace.com/spaces/293120/result_sets) | ||
[![Coverage Status](https://img.shields.io/coveralls/github/AnderssonPeter/Dolly?style=flat-square)](https://coveralls.io/github/AnderssonPeter/Dolly) | ||
|
||
## Table of Contents | ||
* [About the Project](#about-the-project) | ||
* [Getting Started](#getting-started) | ||
* [Example](#example) | ||
* [Benchmarks](#Benchmarks) | ||
|
||
## About The Project | ||
Generate c# code to clone objects on the fly. | ||
|
||
## Getting Started | ||
* Add the `Dolly` nuget and add `[Clonable]` attribute to a class and ensure that the class is marked as `partial`. | ||
* Add `[CloneIgnore]` to any property or field that you don't want to include in the clone. | ||
* Call `DeepClone()` or `ShallowClone()` on the object. | ||
|
||
### Example | ||
```C# | ||
[Clonable] | ||
public partial class SimpleClass | ||
{ | ||
public string First { get; set; } | ||
public int Second { get; set; } | ||
[CloneIgnore] | ||
public float DontClone { get; set; } | ||
} | ||
``` | ||
Should generate | ||
```C# | ||
partial class SimpleClass : IClonable<SimpleClass> | ||
{ | ||
|
||
object ICloneable.Clone() => this.DeepClone(); | ||
|
||
public SimpleClass DeepClone() => | ||
new SimpleClass() | ||
{ | ||
First = First, | ||
Second = Second | ||
}; | ||
|
||
public SimpleClass ShallowClone() => | ||
new SimpleClass() | ||
{ | ||
First = First, | ||
Second = Second | ||
}; | ||
} | ||
``` | ||
|
||
## Benchmarks | ||
|
||
| Method | Mean | Error | StdDev | Ratio | RatioSD | Gen0 | Gen1 | Allocated | | ||
|---------------- |------------:|----------:|----------:|-------:|--------:|-------:|-------:|----------:| | ||
| Dolly | 124.5 ns | 1.59 ns | 1.49 ns | 1.00 | 0.02 | 0.0362 | - | 608 B | | ||
| DeepCloner | 457.7 ns | 7.01 ns | 6.56 ns | 3.68 | 0.07 | 0.0830 | - | 1392 B | | ||
| CloneExtensions | 566.2 ns | 9.61 ns | 8.52 ns | 4.55 | 0.08 | 0.0896 | - | 1504 B | | ||
| NClone | 4,308.0 ns | 62.01 ns | 58.01 ns | 34.61 | 0.61 | 0.5112 | 0.0076 | 8584 B | | ||
| FastCloner | 15,310.6 ns | 221.85 ns | 207.52 ns | 123.00 | 2.16 | 0.3967 | - | 6800 B | | ||
| AnyClone | 19,011.9 ns | 354.27 ns | 347.94 ns | 152.74 | 3.25 | 2.4414 | - | 41256 B | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
|
||
{ | ||
"$schema": "https://aka.ms/codetour-schema", | ||
"title": "Dolly", | ||
"steps": | ||
[ | ||
{ | ||
"file": "CloneData/CloneData.csproj", | ||
"description": "First, we add Nuget [Dolly](https://www.nuget.org/packages/Dolly/) in csproj ", | ||
"pattern": "Dolly" | ||
} | ||
|
||
,{ | ||
"file": "CloneData/Person.cs", | ||
"description": "File Person.cs ", | ||
"pattern": "this is the code" | ||
} | ||
|
||
,{ | ||
"file": "CloneData/Program.cs", | ||
"description": "File Program.cs \r\n>> dotnet run --project CloneData/CloneData.csproj ", | ||
"pattern": "this is the code" | ||
} | ||
|
||
|
||
,{ | ||
"file": "CloneData/obj/GX/Dolly/Dolly.DollyGenerator/Person.g.cs", | ||
"description": "Generated File 4 from 4 : Person.g.cs ", | ||
"line": 1 | ||
} | ||
|
||
,{ | ||
"file": "CloneData/obj/GX/Dolly/Dolly.DollyGenerator/IClonable.g.cs", | ||
"description": "Generated File 3 from 4 : IClonable.g.cs ", | ||
"line": 1 | ||
} | ||
|
||
,{ | ||
"file": "CloneData/obj/GX/Dolly/Dolly.DollyGenerator/CloneIgnoreAttribute.g.cs", | ||
"description": "Generated File 2 from 4 : CloneIgnoreAttribute.g.cs ", | ||
"line": 1 | ||
} | ||
|
||
,{ | ||
"file": "CloneData/obj/GX/Dolly/Dolly.DollyGenerator/ClonableAttribute.g.cs", | ||
"description": "Generated File 1 from 4 : ClonableAttribute.g.cs ", | ||
"line": 1 | ||
} | ||
|
||
], | ||
|
||
"ref": "main" | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio Version 17 | ||
VisualStudioVersion = 17.13.35507.96 d17.13 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CloneData", "CloneData\CloneData.csproj", "{CA3E929D-2578-48A5-B098-13A7B4D81D03}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{CA3E929D-2578-48A5-B098-13A7B4D81D03}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{CA3E929D-2578-48A5-B098-13A7B4D81D03}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{CA3E929D-2578-48A5-B098-13A7B4D81D03}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{CA3E929D-2578-48A5-B098-13A7B4D81D03}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(ExtensibilityGlobals) = postSolution | ||
SolutionGuid = {324EECCB-2C9E-452F-84B0-CCCD40DAA208} | ||
EndGlobalSection | ||
EndGlobal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net9.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Dolly" Version="0.0.7"> | ||
<PrivateAssets>all</PrivateAssets> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
</PackageReference> | ||
</ItemGroup> | ||
<PropertyGroup> | ||
<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles> | ||
<CompilerGeneratedFilesOutputPath>$(BaseIntermediateOutputPath)\GX</CompilerGeneratedFilesOutputPath> | ||
</PropertyGroup> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
| ||
namespace CloneData; | ||
[Dolly.Clonable] | ||
public partial class Person | ||
{ | ||
public string FirstName { get; set; } = ""; | ||
public string LastName { get; set; } = ""; | ||
[Dolly.CloneIgnore] | ||
public int Age { get; set; } | ||
public string Name() => $"{FirstName} {LastName}"; | ||
|
||
public Person[] Childs { get; set; } = []; | ||
} |
Oops, something went wrong.