Visual Studio Macro – copy from old code
I have a class ( not under my control) and I want to make a shallow copy of his properties.
I was tired to wrote this
newObject.Prop1= this.Prop1; newObject.Prop2= this.Prop2; ...
And I have not want to use reflection or expression trees ( http://hydrating.codeplex.com/)
So I have made a fast Visual Studio Macro
Public Module TextRelated Public Sub CopyOld() Dim t As TextSelection = DTE.ActiveDocument.Selection Dim text As String = t.Text Dim str As String = "newObject." + text + " = this." + text + ";" 'http://svenmaes.blogspot.com/2007/03/access-clipboard-from-visual-studio.html modClipboard.ClipboardText = str End Sub End Module
So the work was only to
1. wrote the property
2. click a button
The only part that was difficult was how to put into the clipboard -see the http://svenmaes.blogspot.com/2007/03/access-clipboard-from-visual-studio.html
Simple, but efficient – Enjoy!
Leave a Reply