Last post Dec 29, 2014 10:16 AM by jjmonty
Dec 29, 2014 09:52 AM|jjmonty|LINK
I am trying to convert some vb code to c# but I am stumped. In the following vb code there are no compilation problems because of the way vb is so forgiving about Types.
Dim t As Type, AGNSec As Object
t = Type.GetTypeFromProgID("AGNSecurity.Security")
AGNSec = Activator.CreateInstance(t)
Dim blnValid As Boolean
blnValid = AGNSec.VerifyLogin([params omitted])
AGNSec = Nothing
When I convert this code to C# however, I get a compilation error at the AGNSec.VerifyLogin() line.
Type t = null;
object AGNSec = null;
t = Type.GetTypeFromProgID("AGNSecurity.Security");
AGNSec = Activator.CreateInstance(t);
bool blnValid = false;
//errors here in c#:
blnValid = AGNSec.VerifyLogin([params omitted]);
AGNSec = null;
Is there a way of coding this in C# so that it does not error?
Dec 29, 2014 10:05 AM|David Anton|LINK
Use the 'dynamic' keyword in C#:
dynamic AGNSec = null;
Dec 29, 2014 10:16 AM|jjmonty|LINK
God bless you my friend. That worked!