I have a case where I want deep-cloned objects, but not too deep...
One way to do this would be to have a callback on DeepClone that got called at code-gen time with the name and type of the object that's about to have code generated for it. (Or you could include the whole provenance of the type built during the recursion, so it would have a path of names/types.)
If I return false (by looking at the name of the class or field, or custom attrs on the type etc.), then codegen won't build code that clones below that level.
You could also include a second callback -- if that one is present, then it is called at run-time rather than codegen time -- this way deep clone control could also depend on values, through the cloning will be slower. (If deep cloning doesn't use codegen then there is only the 2nd type of callback.)
I have a case where I want deep-cloned objects, but not too deep...
One way to do this would be to have a callback on DeepClone that got called at code-gen time with the name and type of the object that's about to have code generated for it. (Or you could include the whole provenance of the type built during the recursion, so it would have a path of names/types.) If I return false (by looking at the name of the class or field, or custom attrs on the type etc.), then codegen won't build code that clones below that level.
You could also include a second callback -- if that one is present, then it is called at run-time rather than codegen time -- this way deep clone control could also depend on values, through the cloning will be slower. (If deep cloning doesn't use codegen then there is only the 2nd type of callback.)