Casting .NET objects in X++

To cast any .NET object it is necessary to first assign the value you need to cast to an instance of CLRObject and then you can assing the instance of CLR object into an instance you need, like assinging System.Net.WebRequest instance into System.Net.HttpWebRequest in following code sample.

 static void Job_1(Args _args)
{
    System.Net.HttpWebRequest     httpRequest  = null;
    System.Net.HttpWebResponse    httpResponse = null;
    System.Net.CookieCollection   cookies      = null;
    CLRObject                     clro         = null;
    ;

    new InteropPermission(InteropKind::ClrInterop).assert();

    clro = System.Net.WebRequest::Create("https://www.url.com/authenticate");
    httpRequest = clro;
    httpResponse = httpRequest.GetResponse();
    cookies = httpResponse.get_Cookies();

    clro = System.Net.WebRequest::Create("https://www.url.com/");
    httpRequest = clro;
    httpRequest.set_Cookies(cookies);
    httpResponse = httpRequest.GetResponse();
}
    

Martin F