Microsoft.VisualBasic.DateAndTime a C #

I have a set of vb.net classes and functions that heavily rely on the

DateAndTime 

disponible en el

Microsoft.VisualBasic 

espacio de nombres

Anyone knows if exists a "conversion table" for properties or methods somewhere (it seems SO doesn't)?

I would definitely like to avoid the need to reference VisualBasic.dll or start a trial and error process of figuring out the conversions if these are already done somewhere.

¡Gracias!

preguntado el 08 de noviembre de 11 a las 13:11

Why the reluctance to add a reference to Microsoft.VisualBasic.dll? It's a normal .NET assembly. -

well, long story short, is to "not encourage" the use of legacy code. The reason why we have methods that use DateAndTime is because of an old VB6 application that has been translated to vb.net. If legacy code was written properly (i.e. not a spaghetti fiesta) it would be another story. I agree, a reference would solve the problem. -

1 Respuestas

I don't know of any such conversion table.

The process of working out the equivalents shouldn't be too onerous, as you can decompile the DateAndTime class with Reflector or ILSpy.

Most are very straightforward (Date/Time arithmetic etc), and for the rest, most of the complexity is only needed to achieve backward compatibility for VB6.

Por ejemplo: DateSerial(int year, int month, int day) treats negative years as relative to the current date, and uses a calendar to convert 2-digit years to 4-digit years. If your app isn't making use of this, you can replace by a DateTime constructor.

respondido 08 nov., 11:17

Joe's suggestion is great. Just use Reflector to grab the functions from DateAndTime and implement them in your own static class (if they are inside a Module) - Jeremy

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.