We're trying to trim the number of assemblies we load during startup, and one of the easiest to cut is the Microsoft.VisualBasic assembly. There are alot of things in it that were easy enough to replace, like Left(), but I'm struggling to find a good way to replace vbLf and Chr(). vbCrLf was easy enough to replace with Environment.NewLine, but we have a few spots where we generate content for a Unix-based system that is expecting line feeds only.
Public Const vbLf As String = ChrW(10)
Public Const vbLf As String = Convert.ToChar(10)
Chr
is a fairly complicated method (looking at it in Reflector).
At its base, it uses Convert.ToChar()
, but it does a lot more with checking and different behavior for different ranges of characters.
I need to first point out that there is likely no good reason for this at all. All built-in .Net Assemblies, including Microsoft.VisualBasic.dll, are always available to all .Net programs and using or not using any of these assemblies in your program has zero impact on your program's memory footprint. You can even use Microsoft.VisualBasic.dll from C# programs with no issues. The only case where you might possibly run into a problem is with the mono implementation of the library. So unless you're thinking about porting to mono at some point you're probably spinning wheels.
That said:
Chr():
Function Chr(Byval CharCode As Integer) as Char
Return Convert.ToChar(CharCode)
End Function
vbLf
Const vbLf As Char = Chr(10) ''// of course calling your own Chr implementation
This assumes ASCII, but if you have code that's expecting single line feeds this is a pretty safe bet.
Assuming you're using VB.NET, removing explicit calls to Microsoft.VisualBasic classes won't remove the reference to the assembly. The VB.NET compiler utilizes some functionslink text in there on your behalf. You can compile with the /vbruntime- switch, but I wouldn't recommend it for any non-trivial app.