Type Converter "how-to" or sample available?

Posts   
 
    
Adam
User
Posts: 25
Joined: 03-Jun-2005
# Posted on: 02-May-2006 18:51:01   

I just upgraded to 1.0.2005.1 and I'm looking forward to creating type converter classes using VS.Net 2003. I read the documentation and can't find anything related to this topic. There is a topic on creating type conversions using the designer, but the "Converter to use" drop down on the "New Type Conversion Input" dialog box seems to be empty. I assume this drop-down gets populated with type conversions we (customers) create, but I have no idea what interface to use, what to name the type conversion assembly, etc.

Does anyone have an example of a type conversion project/ class that they would be willing to share? If I am not looking in the right place for documentation, please let me know.

Any information on this topic would be much appreciated. Thanks!

bclubb
User
Posts: 934
Joined: 12-Feb-2004
# Posted on: 03-May-2006 03:02:45   

There is a sample in the SDK download. You can access that here http://www.llblgen.com/pages/secure/extras.aspx. You can access the typeconverters project in \Sourcecode\TypeConverters. Good Luck, let us know if you have any questions.

Adam
User
Posts: 25
Joined: 03-Jun-2005
# Posted on: 03-May-2006 17:34:34   

Thank you so much!! The SDK documentation was extremely helpful and the code was very straight-forward.

One last question (hopefully): In the CanConvertTo() and CanConvertFrom() methods, is there a way that I can get information about the underlying database data types? For example, if a SQL Server column is of type of numeric(11,2), is there a way to get that information using the converter classes? I know I can specify length, precision and scale in the designer as a "filter", but it would be great to be able to obtain this information in the type converter classes.

Thanks again.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39590
Joined: 17-Aug-2003
# Posted on: 03-May-2006 18:09:25   

Why would you want to use that info? The purpose of the converter is that it simply gets a value, and converts it. It doesn't know field data nor gets that data, so I'm afraid that info isn't available inside a typeconverter.

If you're going to use custom types in a typeconverter, it's recommended to place these type definitions in a different assembly, as that assembly has to be present in the TypeConverters folder in LLBLGen Pro's root folder when you load a project.

Frans Bouma | Lead developer LLBLGen Pro
Adam
User
Posts: 25
Joined: 03-Jun-2005
# Posted on: 03-May-2006 19:01:07   

Why would you want to use that info?

Well, I was hoping I wouldn't have to create a different type converter for every variation of the numeric data type in our database. After querying the system tables in our database I found that there are 17 distinct variations of the numeric data type (meaning different lengths, precision and scale). Some of these variations map to different .NET data types, depending on the precision and scale.

I'm going to play with using a single type converter (using the SDK code) and then use the designer to add new type conversion definitions. Maybe each type conversion definition can use the same type converter, but each can apply it's own filter based on the native data type, precision, scale, etc.

Thanks again for adding the type converter feature!

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39590
Joined: 17-Aug-2003
# Posted on: 04-May-2006 10:32:20   

Ah I see, though it's not that complicated simple_smile .

say you have a type A which is the .NET type of a DB value. you also have a destination type B which is the type you want that value of type A to have.

So if you get a value of type A, you convert it to value B. Though at the same time, you can convert back a value of type B to a value of type A.

Typically, you use a type converter which can deal with one type B and various types A. Like the shipped example converter which converts various numeric values (the types A) to a bool (type B). When the bool value has to be converted back to a type A, you'll get the type to convert to (the type A) in the ConvertTo method. So all info required is available, and you can probably use just 1 type converter for all your numeric variants simple_smile

Frans Bouma | Lead developer LLBLGen Pro
Metin
User
Posts: 1
Joined: 01-Nov-2006
# Posted on: 10-Mar-2009 10:26:57   

Hi,

I am having the same problem with the type converter functionality. The link that you guys provided is not working anymore. Would it be possible to provide me the same project of type converter so that I can work on the solution?

Thanks

Metin

MTrinder
User
Posts: 1461
Joined: 08-Oct-2008
# Posted on: 10-Mar-2009 20:48:44   

The SDK download is in the Extras section under here

Note, you need to be logged into the main website with your usernumber and password for the above link to work. This is different from you forum username/password.

Matt