EvnDTE is cool. Then again, it's not totally cool.
I was mucking around last night on an add-in I wrote a while ago to automate some of the repetitive things that VA.NET and other bits don't handle. In this case I continue to search for something that lets me do something along the lines of specifying I want to, say, add an int field called _example and have it kick out the field declaration and a set a of property accessors in a default format--and I want this to happen exactly they way I'd do it manually, in the right places, no editing required afterward.
In other words, yes I'm being picky, I can do it four other ways and then get it with 2 seconds of editing. Zero seconds of post-declaration editing is what would make me happy, sue me.
So anyway, I was playing with some new code in this mixed bag VS.NET add-in I have and learned a couple things. One, there's not much out there talking about working with EnvDTE for code automation. Two, the VS.NET automation object model doesn't feel like, say, the framework classes themselves--it feels like a thin wrapper around older style COM interfaces, which is presumably what it is. Not a big deal, still works, just don't go writing code against it assuming some of the framework conventions, it's not part of the framework proper and it shows.
Third, and probably most importantly, it runs fairly deep in places but not at the level I wanted to go in terms of working with the FileCodeModel. To wit, you can get down into your class by walking down into CodeClass and you can fire off AddProperty. But that's about it, you don't have any control over what AddProperty specifically does at a low level. In other words, it's pretty trivial to get it to kick out a...
public object Whatever
{
get
{
return null;
}
set
{
}
}
but I couldn't get it any further. Which is fine, but that's not what I want, I want...
public object Whatever
{
get
{
return _whatever;
}
set
{
_whatever = value;
}
}
and I really want the backing member field declared as well (and I want them in their respective and nicely ordered places). As an alternate strategy, I was able to use EnvDTE to figure out what class I was in, find the respective field and accessor TextPoints and basically brute force the right text in--but basically this was all I really found EnvDTE could help me with: what class am I in, where are the right places to jam some text into the editor window.
Not really a complaint, I just always hope for the coolest, like I would be able to get at the CodeClass' CodeDom tree and work with it via EnvDTE. Didn't see the road to that, oh well. I guess if I had a spare 10K in between the couch cushions I could join VSIP and find out if this is a wall that you really do have to go around not over. :)