More fun with CLR

Started by stanl, February 17, 2019, 05:33:13 AM

Previous topic - Next topic

stanl

The code below is not earth-shattering but it is interesting to see how easily WB and the CLR can get-along. This is not to underestimate the power of WB to do most anything, but I am looking at building a couple of UDF's that return specific .NET types, conversions, or processes related to encoding and culture. Also a good way to refresh with how classes can be addressed in .NET


Code (WINBATCH) Select


;Winbatch 2018B - CLR method to convert Date to DTMF
;=====================================================================
ObjectClrOption("useany","System.Management")
oM = ObjectClrNew( "System.Management.ManagementDateTimeConverter")
d=ObjectType("DATE",TimeYmdHms())
wmi=oM.ToDmtfDateTime(d)
d=TimeFormat(d,"MM/dd/yyyy hh:mm:ss t")


Message("Convert Date To DTMF",d:@LF:wmi)
oDate=0
Exit



stanl

which brings up this point...


this code
Code (WINBATCH) Select


ObjectClrOption("useany","System.Collections")
ObjectClrOption("useany","System.Threading")
ObjectClrOption("useany","System.Globalization")
oCal = ObjectClrNew("System.Globalization.Calendar")
oCulture = ObjectClrNew("System.Globalization.CultureInfo")

;TFormat = oCulture.CurrentUICulture
Exit



fails for CultureInfo [I put Calendar in just to show a class that didn't error.... ] Trying to get to CultureInfor in WB was meant to replicate the PS one liner



[System.Globalization.CultureInfo]::CurrentUICulture.DateTimeFormat


NOT a WB issue, just more a learning curve... so modify to


oCulture = ObjectClrNew("System.Globalization.CultureInfo","es-ES")


and Voila!