Author Topic: More fun with CLR  (Read 97 times)

stanl

  • Pundit
  • *****
  • Posts: 875
More fun with CLR
« on: February 17, 2019, 05:33:13 am »
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

;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

  • Pundit
  • *****
  • Posts: 875
Re: More fun with CLR
« Reply #1 on: February 17, 2019, 11:08:55 am »
which brings up this point...


this code
Code: Winbatch

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!