ObjectClrType

Associate a Framework based type name with a value, or to up-cast or down-cast Framework based object references.

Syntax:

ObjectClrType ( typename, value-reference  )

Parameters

(s) typename: The name of a Framework based class, structure or enumeration. The name must be fully qualified by including the dot (.) separated namespace prefixed to the type's immediate name.  The namespace name and immediate name must also be separated by a dot character.

(s/i/f/v) value-reference: simple string, integer, float, variant or a reference to a Framework based object.  

Returns:

(r) special WIL variant containing a reference to an Unknown interface.

 

Use this function to either associate a Framework based type name with a value, or to up-cast or down-cast Framework based object references.  

If the second parameter is a simple string, integer, float, or variant that is NOT a reference to a Framework based object, the returned reference can ONLY be used as a parameter to a Framework based object method call, as the right-hand side of a Framework based object property assignment or a constructor argument in a call to ObjectClrNew.  In other words, the returned reference does not have user callable methods, properties or fields.  

On the other hand, if the second parameter is a reference to a Framework based object and the first parameter is the typename of a base or derived type of that object then the returned reference can be used to access the members of either the base or derived type of the input object.

If the second parameter does NOT contain a Framework based object reference, the assembly implementing typename must be loaded BEFORE the return reference is used as a method parameter, property value or constructor argument. If the second parameter contains a Framework based object reference, the assembly implementing typename must be loaded BEFORE this function is called.

Type Notes

WIL Type

Variant Type

FCL Type

Notes

String

VT_BSTR

System.String

WinBatch automagically converts WIL Strings to BSTRs and converts BSTRs to FCL 'System.String' objects.

Integer

VT_I4

System.Int32

WinBatch automagically converts WIL Integers to I4s and converts I4s to FCL 'System.Int32' objects.  

objYear = ObjectClrNew( 'System.Int32', ItemExtract(1, TimeYmdhms(),":") )

or

vYear = ObjectType("I4", ItemExtract(1,TimeYmdhms(),":"))

or

nYear =  ItemExtract(1,TimeYmdhms(),":") + 0

 

(No WIL BOOL Type)

VT_BOOL

System.Boolean

In the case of the BOOL assignment, the ObjectType function is necessary because WinBatch doesn't have a basic WIL Boolean type that it knows how to convert to a variant BOOL. The ObjectClrType function is not necessary because WinBatch will convert a variant of type BOOL to a FCL 'System.Boolean' type.

Example:
ObjectClrOption("useany", "System")
ObjectClrOption("useany", "System.Net")
Uri = "https://www.winbatch.com/about.html" ; Your URL here.
objUri = ObjectClrNew('System.Uri', Uri)
Encoding = ObjectClrNew( 'System.Text.Encoding' )
WebRequest = ObjectClrNew('System.Net.WebRequest')
objSvcManager = ObjectClrNew('System.Net.ServicePointManager')
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Assuming your site uses TLS 1.2 which is the integer value 3072:
;; https://docs.microsoft.com/en-us/dotnet/api/system.net.securityprotocoltype?view=netframework-4.7.2
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Since SecurityProtocol is expecting an enumeration value,
;; use ObjectTypeGet to give the integer value an enumeration
;; type the property expects.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
objSvcManager.SecurityProtocol = ObjectClrType("System.Net.SecurityProtocolType",3072)
objSvcPoint = objSvcManager.FindServicePoint(objUri)
WebRequest = WebRequest.Create(Uri)
WebRequest.Timeout = WebRequest.Timeout * 6
WebResponse = WebRequest.GetResponse()
ResponseStream = WebResponse.GetResponseStream
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Pipes the stream to a higher level stream reader with
;; the required code point encoding.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
StreamReader = ObjectClrNew("System.IO.StreamReader", ResponseStream, Encoding.UTF8)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Dispaly the site's source.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Message("Site HTML", StreamReader.ReadToEnd())
ResponseStream.Close()
StreamReader.Close()
Exit
See Also:

ObjectClrNew, ObjectClrOption, ObjectType, ObjectTypeGet