开发者

Is there a code-generation plugin for visual studio which will allow me to select 2 objects and map properties

I'm thinking of something that can let me select two objects of different types and describe mappings between them (maybe visually?) and then allow code generation for operations such as shallow and deep copy, and perhaps show me mismatched properties?

I'm aware of runtime solutions like Automapper, but not of anything that can assist me in code generation. I need to keep up with some large, rapidly evolving classes and mapping to开发者_StackOverflow中文版 and from them.


you can use T4 (Text Template Transformation Toolkit) to write your own Templates for mapping classes.

http://msdn.microsoft.com/en-us/library/bb126445.aspx


I am not aware of any tool but I wrote a macro that helps a lot.

The macro creates an assignment for all public members of a class. Then I use the column editing features to do the rest.

My macro generates a list like

x.Prop1 = 0;
x.Prop2 = "Prop2";
x.Prop3 = 0;

I use column editing to change the right hand side to " y ;"

x.Prop1 = y ;
x.Prop2 = y ;
x.Prop3 = y ;

If the property names in the classes are the same or similar I use column copy to paste them between y and ; otherwise I go to each row, press . and use intellisense.

You can find a lot of resources on macro programming for visual studio here

But column editing will help a lot even without a macro.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜