@@ -41,58 +41,64 @@ Add `<DeepCopy/>` to [FodyWeavers.xml](https://github.com/Fody/Home/blob/master/
4141``` csharp
4242public static class MyStaticClass
4343{
44- [DeepCopyExtension ]
45- public static SomeObject DeepCopy (SomeObject source ) => source ;
44+ [DeepCopyExtension ]
45+ public static SomeObject DeepCopy (SomeObject source ) => source ;
4646}
4747
4848public class SomeObject
4949{
50- public int Integer { get ; set ; }
51- public SomeEnum Enum { get ; set ; }
52- public DateTime DateTime { get ; set ; }
53- public string String { get ; set ; }
54- public IList <SomeObject > List { get ; set ; }
55- public IDictionary <SomeKey , SomeObject > Dictionary { get ; set ; }
50+ public int Integer { get ; set ; }
51+ public SomeEnum Enum { get ; set ; }
52+ public DateTime DateTime { get ; set ; }
53+ public string String { get ; set ; }
54+ public IList <SomeObject > List { get ; set ; }
55+ public IDictionary <SomeKey , SomeObject > Dictionary { get ; set ; }
5656}
5757```
5858
5959#### What gets compiled
6060``` csharp
6161public static class MyStaticClass
6262{
63- public static SomeObject DeepCopy (SomeObject source )
64- {
65- return source != null ? new SomeObject (source ) : (SomeObject ) null ;
66- }
63+ public static SomeObject DeepCopy (SomeObject source )
64+ {
65+ return source != null ? new SomeObject (source ) : (SomeObject ) null ;
66+ }
6767}
6868
6969public class SomeObject
7070{
71- public SomeObject () { }
72-
73- public SomeObject (SomeObject obj )
74- {
75- this .Integer = obj .Integer ;
76- this .Enum = obj .Enum ;
77- this .DateTime = obj .DateTime ;
78- this .String = obj .String != null ? string .Copy (obj .String ) : (string ) null ;
79- if (obj .List != null ) {
80- this .List = (IList <SomeObject >) new System .Collections .Generic .List <SomeObject >();
81- for (int index = 0 ; index < obj .List .Count ; ++ index )
82- this .List .Add (obj .List [index ] != null ? new SomeObject (obj0 .List [index ]) : (SomeObject ) null );
83- }
84- if (obj .Dictionary != null ) {
85- this .Dictionary = (IDictionary <SomeKey , SomeObject >) new System .Collections .Generic .Dictionary <SomeKey , SomeObject >();
86- foreach (KeyValuePair < SomeKey , SomeObject > keyValuePair in (IEnumerable <KeyValuePair <SomeKey , SomeObject >>) obj .Dictionary )
87- this .Dictionary [new SomeKey (keyValuePair .Key )] = keyValuePair .Value != null ? new SomeObject (keyValuePair .Value ) : (SomeObject ) null ;
88- }
71+ public SomeObject () { }
72+
73+ public SomeObject (SomeObject obj )
74+ {
75+ this .Integer = obj .Integer ;
76+ this .Enum = obj .Enum ;
77+ this .DateTime = obj .DateTime ;
78+ this .String = obj .String != null ? string .Copy (obj .String ) : (string ) null ;
79+ if (obj .List != null ) {
80+ var list = new System .Collections .Generic .List <int >();
81+ foreach (var num in obj .List )
82+ list .Add (num );
83+ this .List = list ;
84+ }
85+ if (obj .Dictionary != null ) {
86+ var dictionary = new System .Collections .Generic .Dictionary <SomeKey , SomeObject >();
87+ foreach (var keyValuePair in obj0 .Dictionary )
88+ {
89+ SomeObject someObject = ClassWithDeepCopyExtension .CopySomeObject (keyValuePair .Value );
90+ dictionary [keyValuePair .Key ] = someObject ;
91+ }
92+ this .Dictionary = dictionary ;
8993 }
94+ }
9095
91- public int Integer { get ; set ; }
92- public SomeEnum Enum { get ; set ; }
93- public DateTime DateTime { get ; set ; }
94- public string String { get ; set ; }
95- public IList <SomeObject > List { get ; set ; }
96+ public int Integer { get ; set ; }
97+ public SomeEnum Enum { get ; set ; }
98+ public DateTime DateTime { get ; set ; }
99+ public string String { get ; set ; }
100+ public IList <SomeObject > List { get ; set ; }
101+ public IDictionary <SomeKey , SomeObject > Dictionary { get ; set ; }
96102}
97103```
98104
0 commit comments