How is this VB.NET code being evaluated?

I am working on converting code from VB.NET to C #. I found this piece of code that I'm trying to wrap around myself, but I can't figure out how it is evaluated:

If eToken.ToLower = False Then _
    Throw New Exception("An eToken is required for this kind of VPN-Permission.)

      

My problem is comparing a string eToken.ToLower

against a boolean False

.

I tried to use a converter and what I got was this: (which is not a valid expression in C # as you cannot compare string

with bool

):

if (eToken.ToLower() == false) {
    throw new Exception("An eToken is required for this kind of VPN-Permission.");
}

      

+3


source to share


2 answers


I have compiled it and decompiled IL; in C # which:

string eToken = "abc"; // from: Dim eToken As String = "abc" in my code 
if (!Conversions.ToBoolean(eToken.ToLower()))
{
    throw new Exception("An eToken is required for this kind of VPN-Permission.");
}

      



So your answer is: it uses Conversions.ToBoolean

(where Conversions

is Microsoft.VisualBasic.CompilerServices.Conversions

in Microsoft.VisualBasic.dll

)

+4


source


You can make a type that assumes the eToken is "true" / "false":



if (Convert.ToBoolean(eToken.ToLower())==false)
    throw new Exception("An eToken is required for this kind of VPN-Permission.");
}

      

+1


source







All Articles