Dynamic ctype?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am attempting to write a 'factory' function to use in a generated data
access layer to accept a sqldbtype and convert it to the appropriate
system.type.

I have attempted to use ctype (value, typename)
where value is the sqlreader field object and typename is a variable
containing the required type as a system.type and I'm getting nowhere.

Any ideas appreciated.

Thanks in anticipation,

Mike
 
Why not create a 'hard coded' list for the purposes of this type conversion.
I use Codesmith to produce my data access layer and when building the .NET
classes, I use a function (that is a standard part of one of the CodeSmith
templates) to produce compatible type definitions. The function is relatively
small and I have had no problems with it at all. If you are interested, I
could provide you with the type mappings I use.

Regards,

-Eric
 
But what would that function return?
You would have to declare the return type as whatever the lower common
denominator is - and that would defeat the purpose of the function. Even if
you CType it inside, if the return type is the ancestor class, then anything
calling the function thinks it is getting an ancestor class. So calling the
function was just a waste of time, really.

If this is not what you are trying to do, then I think the Case statement is
your only solution. But that shouldn't be a problem, since you presumably
want to do something with the object afterwards - but you would have to
already know what type it is during coding to be able to call anything
specific to the type anyway. So it really shouldn't be a problem.
 
Back
Top