Pierre Greborio.NET

Talking about .NET world

Strongly Typed Collection Generator for Visual Studio .NET 2003 upgrate

I upgrated to Visual Studio .NET 2003 my Add-In for generating stronly typed collections both in C# and VB.NET (download).

Comparing to the past version (for Visual Studio .NET) I fixed a bug (now it works fine for VB.NET too) and changed the way of using it. Now you have a new "Tools" menu item called STC Generator which will invoke the configuration dialog box. Selecting the project and then the class you can generate the strongly typed collection for that class in the project's language (C# and VB.NET actually)



This add-in lack in documentation and I hope to provide it ASAP.

DISCLAIMER:
The sample is provided as is. Be sure that it is actually only a sample and does not in any sense conform to any coding guidelines and has not been proven to be a stable product! The code has not been reviewed by third parties or even been refactored for optimization - be sure that it is still much improvable.
The author cannot be made responsible for any damage or inconveniencies but is willed to accept any questions and comments to this sample.

Comments

Pierre Greborio said:

Yes, the old version doesn't work with VS.NET 2003 because the registry keys are different.

Moreover, the past version had a bug for VB.NET that has been fixed here.
CodeSmith is more complete than mine but more tight coupled to database schema (I didn't tested it). STC Generator is tied on OO classes only (simpler).

I hope to complete it with other features such as sorting and DataBinding events.

Thanks.
# July 14, 2003 5:23 AM

Morten Abrahamsen said:

Nice tool!

An Add with an array of items would be nice though :)

Morty
# August 21, 2003 11:27 AM

Denny Figuerres said:

Cool! well almost...

I do mostly VB.NET and there are some bugs.

Hope I can muddle my way thru the C# to find and fix them...
# August 27, 2003 2:17 PM

Denny Figuerres said:

If anyone reads this....


OK I have most of the bugs fixed but can't fins out one thing:

how do I write the class declaration in the CodeDOM to get
class abx
Implements Ifoo

in place of
class abc
Inherits Ifoo

??

I found th CodeDOM calls to do this with members ( methods, properties )

but not the one for the class!!!!!
# August 27, 2003 11:03 PM

Pierre Greborio said:

There are some problems with VB.NET since the code provider works in a little different manner. But, I'll try to fix them asap.

For the interface (IFoo), I don't understand where you want inherit from it. It is your collection ?
# August 28, 2003 3:43 AM

Denny Figuerres said:

My DSL that connects my server at work is down as of last night so I may have a problem sending you some code today, if you can wait 1 day I should be back online and be able to email you the changes to the code I did.

the interface name was just an example....

it's the inner class that impliments the enumerator that is the problem.

for mthe most part here is a summary of my mods.

first I created a private class member
Language _lang;

and when you call the class with the lang param I init the class local.

this way later I can add some
if ( _Lang == Language.VB )
{}
type's of conditionals to add or swap as needed.
for the comment blocks:
created a private helper
string VBComment()
that uses the above test to return "''" if VB or "" if not

this is used in the comment() func's to cause the summary / param / return comments to be
'''
in plave of
'

the build namespace can have an empty param in the constaructor, that works for vb
so I have the var = new .... in an if block

so now that just leave the enumerator to fix.

next post for the rest....
# August 28, 2003 7:22 AM

Denny Figuerres said:

Ok so then the first fixes in the enumerator...

you have some code that generates a test for
_index == -1 for C#
for vb it's generating
_index Is -1 which is a compile error

so I modified your code to have a ?:
_lang == Language.VB ? EqualityValue : .....

so that when VB it emits an "=" in place of the "Is"

then for each of the methods we are implementing I add a CodeMember.ImplementationTypes
with the name of the interface we are implimenting

this emits
foo() .... Implements Ienumerator.foo

ok alsmost home by now....

what remains:

1) get the class to emit the same type of declaration
class whatever : Implements IEnumerator

(or is this IEnumerable ?? it's 7:30am here :-) )

2) the part where we have the generic and type'ed versions of "CUrrent"

are a bit of a problem

we should have one marked private with the Implements ....
the other marked public without it and named Current

but the private one wants to use the function name in building the Implients IEnumer.Current
but we need the function to be more like
Enumerator_Current
but if you just set the function name then the code chnages and....

Ok, now to see what's up with the office DSL and see if I can just email you the code snips I used.....
# August 28, 2003 7:35 AM

Tim Haughton said:

Nice utility.

A couple of points/comments:

The collection should implement a strongly typed ToArray() method.

The 'Current' property on the enumerator should throw an InvalidOperationException not an IndexOutofRangeException when it is called improperly.

Thanks again.

# March 18, 2004 10:52 AM

TrackBack said:

# April 24, 2004 5:13 AM

propriet? a design-time | hilpers said:

Pingback from  propriet? a design-time | hilpers

# January 23, 2009 12:41 AM