|
I'm working on a guidance package for a DSL, and one of the recipies concerns code generation.
I have associated the recipie with the appropriate ProjectItems and
everything is working perfectly. I can get the ProjectItem, load the
referenced file as a DSL model and continue into the code generation.
Then it strikes me that most often the user is going to have the file
open already, so I can avoid the overhead of loading the model by
simply finding a reference to the open file and using that as the
source for the code gen.
So I have the code below (the Execute method of an Action). It locates
the correct open document, but I cannot cast it to the correct type.
The type of the object I get is System.__ComObject, and there is no
obvious way to marshall that into a ModelingDocData.
Can you give me any pointers on how to get a reference to the document as the type I need?
Thanks,
Brian.
public override void Execute()
{
DTE vs = GetService<DTE>(true);
IAssetReferenceService referenceService =
GetService<IAssetReferenceService>(true);
object item = DteHelper.GetTarget(vs);
ProjectItem projectItem = item as ProjectItem;
foreach (Document doc in vs.Documents)
{
if (doc.ProjectItem.Equals(item))
{
MessageBox.Show("Found open document " + doc.Path, "Code Generation",
MessageBoxButtons.OK, MessageBoxIcon.Information);
Microsoft.VisualStudio.EnterpriseTools.Shell.ModelingDocData docData =
doc as Microsoft.VisualStudio.EnterpriseTools.Shell.ModelingDocData;
if (docData != null)
{
MessageBox.Show("Document is ModelingDocData " +
docData.RootElement.MetaClass.Name, "Code Generation",
MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
{
MessageBox.Show("Document type " + doc.GetType().AssemblyQualifiedName,
"Code Generation", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
}
if (projectItem == null)
throw new InvalidOperationException("There is no valid model from which
to generate code.");
MessageBox.Show("Generating code for " + projectItem.Name, "Code
Generation",
MessageBoxButtons.OK, MessageBoxIcon.Information);
}
| | Brian OByrne Friday, March 31, 2006 6:23 PM | This question is related to the DSL tools and not specifically to GAT. You should try asking in their forum instead: http://forums.microsoft.com/msdn/showforum.aspx?forumid=61&siteid=1
Thanks!
| | kzu Sunday, April 02, 2006 6:29 PM | And by the way, as you acknowledge yourself, this is a DTE question, so you should also try the VS extensibility forum: http://forums.microsoft.com/MSDN/ShowForum.aspx?ForumID=57&SiteID=1
Thanks
| | kzu Monday, April 03, 2006 6:30 PM | This question is related to the DSL tools and not specifically to GAT. You should try asking in their forum instead: http://forums.microsoft.com/msdn/showforum.aspx?forumid=61&siteid=1
Thanks!
| | kzu Sunday, April 02, 2006 6:29 PM | No, this problem is related to the types returned from the DTE objects.
I might accept that it is related to VS SDK more than to GAT, but it is not a DSL question.
| | Brian OByrne Monday, April 03, 2006 8:26 AM | More over, it's not a VSSDK but an VS extensibility (DTE/addins) question, as you're accessing the document from the DTE solution object.
The reason I pointed you to the DSL forum, is that you're talking specifically about getting the modelling document, and they may have a preferred way for you to do that, which may or may not involve the DTE (i.e. there are VSIP interfaces to get to the same information, i.e. IVsMonitorSelection and IVsWindowFrame, using __VSFPROPID.VSFPROPID_DocView).
| | kzu Monday, April 03, 2006 6:29 PM | And by the way, as you acknowledge yourself, this is a DTE question, so you should also try the VS extensibility forum: http://forums.microsoft.com/MSDN/ShowForum.aspx?ForumID=57&SiteID=1
Thanks
| | kzu Monday, April 03, 2006 6:30 PM |
|