Creates a class, structure or enumeration implemented by a managed assembly. The function returns a Framework based type as a COM Automation reference that can be used to access the members of the underlying Framework based type.
ObjectClrNew( typename [, ctorparm,...] )
(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) ctorparm: 0 to 15 constructor parameters to be used when creating a type. Since type constructors can be overloaded, the type and number of these parameters control which constructor will be used to create the type.
(r) object reference.
The assembly implementing the type specified by 'typename' must be loaded into the WinBatch process before this function can be called to create the type. The exceptions to this requirement are types implemented by the "mscorlib" assembly. This assembly is automatically loaded by WinBatch when the CLR is loaded. All other assemblies must be loaded into the WinBatch process using the ObjectClrOption function's Use option.
Members of the returned object reference are called using the same variable-name+dot+member-name syntax used by standard COM Automation object references. However, there are some important differences between regular COM calls and CLR type member calls. The most significant difference is that CLR constructors and type member names can be overloaded. This means that more than one member can have the same name. When more than one member has the same name, WinBatch and the CLR determine which member to call based on the number and type of the parameters passed in the call statement. The combination of member name, parameter types and parameter count is called the member's signature. This means that using the correct type for each parameter is crucial to calling the correct member.
Both member overloading and the fact that WinBatch cannot query the object for type information before making a member call as it does with regular COM Automation references means that the colon (:) type qualifier needs to be used more frequently on CLR object member parameters. Fortunately, WinBatch will take standard variant type names like BSTR, UI8, BOOLEAN, R8, e.g., and convert them to equivalent Framework types automatically. It will also automatically deduce the correct Framework type for variant variables passed as parameters to a member without needing to specify a type with the colon qualifier. When a Framework based type does not have equivalent variant type, the fully qualified Framework based type name can be used with colon type qualifier on a parameter. This is most often necessary when the object member is expecting an up-cast or down-cast of Framework based class, when it is expecting a value from a Framework based enumeration, or when it is expecting an array with elements of a specific Framework based type. In the case of arrays, the type qualifier should be the Framework based type of the elements prefixed to the variable name of a variable that holds either a WIL array or a variant safearray. No array type information ('ARRAY' or 'System.Array') should be included in the type qualifier. When using a Framework type name qualifier with any parameter the type qualifier's assembly must be loaded before the member with the qualified parameter is called.
Another significant difference between standard COM Automation object and Framework based wrapped objects is that unlike standard COM Automation objects, Framework based object member names are case sensitive.
The function allows access to most Framework based types and their members but there are a few limitations and restrictions. The following is a partial list of those limitations and restrictions:
WinBatch relies on the CLR hosting's reflection functionality to instantiate classes. There are a few classes attributed to block instantiation via reflection.
WinBatch does not support 'out' parameters. Method without parameters can still be called but 'out' parameter values are not modified on the method's return.
Class member overloads that rely solely on the return type and name for their signature cannot be used.
Value types (structures) that only provide a multiple parameter constructor(s) cannot be used.
A small number of type member names conflict with WinBatch identifier naming rules and cannot be called directly.
Parameterize properties are not supported.
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; Create a Class implemented by a managed assembly.
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
objDirectory = ObjectClrNew('System.IO.Directory')
path = 'C:\temp'
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; Exist method - Determines whether the given path
; refers to an existing directory on disk
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ret = objDirectory.Exists( path ) If ret Pause( 'Directory Exist?', 'Yes' ) Else Pause( 'Directory Exist?', 'No' ) EndIf
Exit
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ; Create a Structure ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ;System.Int32 objInt = ObjectClrNew( 'System.Int32' ) maxval = objInt.MaxValue minval = objInt.MinValue Pause( 'Int32', 'Maximum value = ':maxval:@lf:'Minimum value = ':minval )
;Structure with a WIL standard type ctor parameter objInt = ObjectClrNew( 'System.Int32', 42 )
;System.Int64 ; Structure with a variant ctor parameter. vI64 = ObjectType( 'I8', '10000000000' ) objInt64 = ObjectClrNew( 'System.Int64', vI64 ) maxval = objInt64.MaxValue minval = objInt64.MinValue Pause( 'Int64', 'Maximum value = ':maxval:@lf:'Minimum value = ':minval ) Exit
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ; Create and Use an Enumeration and Structure ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ bday_month = 4 ; SPECIFY MONTH OF BIRTH bday_day = 19 ; SPECIFY DAY OF BIRTH
; Cast the year string to Type Int32 objYear = ObjectClrNew( 'System.Int32', ItemExtract(1,TimeYmdHms(),":") ) ; or vYear = ObjectType("I4", ItemExtract(1,TimeYmdhms(),":")) ; This creates a WIL variant of a 4-byte signed integer value. ; or nYear = ItemExtract(1,TimeYmdhms(),":") + 0 ; This converts a WIL string to an integer
; DateTime(Int32, Int32, Int32) Structure ; Initializes a new instance of the DateTime structure to the specified year, month, and day. objDT = ObjectClrNew( 'System.DateTime', objYear, bday_month, bday_day ) nDOW = objDT.DayOfWeek
; DayOfWeek Enumeration ; Specifies the day of the week. enumDayofWeek = ObjectClrNew( 'System.DayOfWeek' ) Switch nDOW Case enumDayofWeek.Sunday dayname = 'Sunday' Break Case enumDayofWeek.Monday dayname = 'Monday' Break Case enumDayofWeek.Tuesday dayname = 'Tuesday' Break Case enumDayofWeek.Wednesday dayname = 'Wednesday' Break Case enumDayofWeek.Thursday dayname = 'Thursday' Break Case enumDayofWeek.Friday dayname = 'Friday' Break Case enumDayofWeek.Saturday dayname = 'Saturday' Break Case nDOW dayname = 'Uh oh! You found a new day of the week. What planet are you from?' Break EndSwitch Pause( 'This Year Your Birthday Is On A...', dayname ) Exit