Can I generate code from a list in the clipboard?

If i have a list in a clip board like  Name Address Age.  Can I loop through the list and generate code? For example could I create properties
public string Name {get; set};
public string Address {get;set};
public int Age {get;set};

Do templatess have the option to loop through the clipboard?

3 comments
Comment actions Permalink

Templates and macros don't currently have that ability. You could write a macro plugin that iterated through the clipboard and created the code you wanted, but it would need to do all the formatting and code gen itself, rather than use text in the live template file itself. So your macro would have to create "public string XXXX { get; set;} public string YYYY { get; set; }", etc.

0
Comment actions Permalink
With using a plugin can I still get the template to stop at places like the datatype where the user fills out for each item in the list? And I generate the rest of the code in my plugin.
0
Comment actions Permalink

No, that's the functionality that the templates system gives you, allowing you to tab between various hotspots and perform some action at that point, like editing some text, or selecting an item from a list. Since the templates system doesn't give you a way of looping, you either have to do all of that work in your own macro, which means no jumping between hotspots, or invoke one template multiple times. This macro could create a single property, with one hotspot to edit the type of the property, and another bound to a custom macro that displays the contents of the clipboard in a drop down list. You'd have to expand the macro multiple times, but you'd at least have more control over what was generated. The macro interface already allows you to display a drop down list, simply by returning a list of strings from the IMacro.GetLookupItems method.

However, thinking about it, a better solution might be to create a Generator item (http://confluence.jetbrains.net/display/ReSharper/4.03+Generator+Items+%28R7%29). This is slightly more complex, but allows you to display a UI that you can populate (from your clipboard list) and edit to provide types for the properties. This can be made available to the Generate menu (alt+insert), or you can also write a macro that derives from GeneratorMacro, such as AspMasterpageContentGeneratorMacro, and you can then use this macro in a template. The normal text in the template is output to the file, then your generator macro would be invoked and create the text for all of the properties.

0

Please sign in to leave a comment.