Skip to content

Commit

Permalink
Merge pull request #336 from ignatandrei/335-httpsgithubcomanderssonp…
Browse files Browse the repository at this point in the history
…eterdolly

335 httpsgithubcomanderssonpeterdolly
  • Loading branch information
ignatandrei authored Dec 14, 2024
2 parents bed9bcd + f16f6bb commit f42fff8
Show file tree
Hide file tree
Showing 56 changed files with 968 additions and 390 deletions.
115 changes: 65 additions & 50 deletions README.md

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion v2/Generator/all.csv
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ Nr,Key,Source,Category
113,sourcedepend, https://github.com/crwsolutions/sourcedepend,Constructor
114,corecraft, https://github.com/AlexNav73/CoreCraft,FilesToCode
115,UnionsGenerator, https://github.com/PaulBraetz/RhoMicro.CodeAnalysis/,FunctionalProgramming
116,CopyTo, https://github.com/PaulBraetz/RhoMicro.CodeAnalysis,EnhancementClass
116,CopyTo, https://github.com/PaulBraetz/RhoMicro.CodeAnalysis,Clone
117,PlantUmlClassDiagramGenerator, https://github.com/pierre3/PlantUmlClassDiagramGenerator/,EnhancementProject
118,RSCG_Wait, https://github.com/ignatandrei/RSCG_WaitAndOptions,EnhancementProject
119,AutoGen, https://github.com/Antelcat/AutoGen,Mapper
Expand Down Expand Up @@ -173,3 +173,4 @@ Nr,Key,Source,Category
172,GoLive.Generator.BlazorInterop, https://github.com/surgicalcoder/BlazorInteropGenerator,Blazor
173,Microsoft.Windows.CsWin32, https://github.com/microsoft/CsWin32,WinAPI
174,Dapper.AOT, https://github.com/DapperLib/DapperAOT,Database
175,Dolly, https://github.com/AnderssonPeter/Dolly,Clone
1 change: 1 addition & 0 deletions v2/GeneratorData/Category.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,6 @@ public enum Category
Mediator=26,
SignalR=27,
WinAPI = 28,
Clone=29,
}

8 changes: 7 additions & 1 deletion v2/RSCGExamplesData/GeneratorDataRec.json
Original file line number Diff line number Diff line change
Expand Up @@ -691,7 +691,7 @@
},
{
"ID": "CopyTo",
"Category": 5,
"Category": 29,
"dtStart": "2024-02-19T00:00:00",
"show": true
},
Expand Down Expand Up @@ -1047,5 +1047,11 @@
"Category": 14,
"dtStart": "2024-12-02T00:00:00",
"show": true
},
{
"ID":"Dolly",
"Category": 29,
"dtStart": "2024-12-03T00:00:00",
"show": true
}
]
7 changes: 1 addition & 6 deletions v2/RSCGExamplesData/NoExample.json
Original file line number Diff line number Diff line change
Expand Up @@ -844,11 +844,6 @@
"ID":182,
"name":"https://github.com/AlexNav73/CoreCraft",
"why":"later"
},
{
"ID":183,
"name":"https://github.com/AnderssonPeter/Dolly",
"why":"later"
},
}

]
74 changes: 74 additions & 0 deletions v2/book/examples/Dolly.html
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>

6 changes: 5 additions & 1 deletion v2/book/list.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
</head>
<body>
<h1>
This is the list of 174 RSCG with examples =>
This is the list of 175 RSCG with examples =>
</h1>

<table >
Expand Down Expand Up @@ -722,6 +722,10 @@ <h1>
<td>174</td>
<td><a href="examples/Dapper.AOT.html">Dapper.AOT</a></td>
</tr>
<tr>
<td>175</td>
<td><a href="examples/Dolly.html">Dolly</a></td>
</tr>
</table>


Expand Down
1 change: 1 addition & 0 deletions v2/book/pandocHTML.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ input-files:
- examples/GoLive.Generator.BlazorInterop.html
- examples/Microsoft.Windows.CsWin32.html
- examples/Dapper.AOT.html
- examples/Dolly.html

# or you may use input-file: with a single value
# defaults:
Expand Down
22 changes: 22 additions & 0 deletions v2/rscg_examples/Dolly/description.json
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":""
}
}
1 change: 1 addition & 0 deletions v2/rscg_examples/Dolly/nuget.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Clone .net objects using source generation
86 changes: 86 additions & 0 deletions v2/rscg_examples/Dolly/readme.txt
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 |
54 changes: 54 additions & 0 deletions v2/rscg_examples/Dolly/src/.tours/Dolly.tour
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"

}
25 changes: 25 additions & 0 deletions v2/rscg_examples/Dolly/src/CloneData.sln
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
20 changes: 20 additions & 0 deletions v2/rscg_examples/Dolly/src/CloneData/CloneData.csproj
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>
13 changes: 13 additions & 0 deletions v2/rscg_examples/Dolly/src/CloneData/Person.cs
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; } = [];
}
Loading

0 comments on commit f42fff8

Please sign in to comment.