Denaes Posted July 27, 2006 Posted July 27, 2006 I'm looking to write a macro that I can fully customize with knowledge of a class. For example, I'll be using a typed dataset Person which has say 3 tables on it. I want to be able to run the macro in the Person Partial Class and have it create an instance of a table adapter, my custom Fill, Refresh & Persist methods as well as transaction logic if there are 2+ tables. So basically I could work everything out given that I know how many tables there are and what their names are. An advanced version might take the relationships into account. This is the best article I've found for macros: http://msdn.microsoft.com/msdnmag/issues/05/07/XMLComments/ so far. It helps with the code writing, but not how to access or pass a class into macro. There isn't a whole lot out there and a lot of it is rather specific, so any articles that access a class would be great. Quote
Denaes Posted July 28, 2006 Author Posted July 28, 2006 I found something here: http://www.15seconds.com/issue/051123.htm Under Using Macros to Generate Data Access Code it goes onto do nearly what I'm talking about. Almost. It looks like this code here: For Each typ As Type In targetAssembly.GetTypes() If typ.FullName Like "*" & ItemName & "TableAdapters." & _ "*TableAdapter" Then TableName = typ.Name.Substring(0, _ typ.Name.LastIndexOf("TableAdapter")) line = "Dim ta" & TableName & " As " & ItemName & _ "TableAdapters." & typ.Name DTE.ActiveDocument.Selection.NewLine() DTE.ActiveDocument.Selection.Text = line taList &= "ta" & TableName & "," UpdateType = typ.GetMethod("Delete") If UpdateType IsNot Nothing Then UpdateList &= "ta" & TableName & "," End If Next would be nearly what I'm looking for. Though without a chance to test it yet, it looks like it's grabbing all of the TableAdapters in the whole assembly, not in a particular dataset. Which is fine if you want to generate the code for every table adapter all at once. Since I'm looking for all the adapters in a particular class, I would use the DTE.ActiveDocument to parse out the name of the class and use reflection to find all the tables in the class (which IMO would be easier than trying to find the TableAdapters with a partial namespace match of the classname) I'll post more here as I get it, that way if anyone does a search it'll be here :D Quote
Denaes Posted August 1, 2006 Author Posted August 1, 2006 Actually that code above did return only the table adapters that were part of that dataset. I created a TableInfo class & TableCollection, and for each TableAdapter I created a new TableInfo which had properties for getting the TableName, TA Name, TA Namespace and a few other choice methods that made things easier. With collection in hand, I wrote the class and cycled through the collection at key locations. Macro done, should be working but I need to test it with multiple and single tables. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.