I recently took over a 170k line VB.net project and was instructed to bring it into C#. Not having the time for a full rewrite, I tested several conversion tools. I ended up using Tangible's Instant C#, which in all actuality did an incredible job. After a few hours of error fixes, it compiles and (mostly) works correctly.
With C# having no equivalent to VB's Val
, the converter created a SimulateVal
helper class with methods such as the following:
public static double Val(string expression)
{
if (expression == null)
return 0;
//try the entire string, then progressively smaller
//substrings to simulate the behavior of VB's 'Val',
//which ignores trailing characters after a recognizable value:
for (var size = expression.Length; size > 0; size--)
{
double testDouble;
if (double.TryParse(expression.Substring(0, size), out testDouble))
return testDouble;
}
//no value is recognized, so return 0:
return 0;
}
Val
was used throughout the VB program. Thus, these helper methods get called a number of times.
In searching for more information and other options, I've found this discussion, which features a response from Tangible showing this helper class. However, I've been unable to find much further discussion.
Will it be sufficient to leave this helper class in place and simply use the helper class? Would it be better to search for an alternative way of handling this in C#, or is this a light enough solution to leave in place?