Problem:
How to do Casting in Net Express .NET?
In C# for example you can do -
string x = (string)object;
Resolution:
The example program below shows casting in COBOL in .NET:
(this is a demo of how to access an XML Config files)
$set sourceformat"variable"
program-id. ConfigReader.
environment division.
configuration section.
repository.
class cAppSettingsReader as "System.Configuration.AppSettingsReader"
class cString as "System.String"
class cInvalidOperationException as "System.InvalidOperationException"
.
data division.
working-storage section.
01 myReader object reference cAppSettingsReader.
01 setting1 pic x(30).
01 setting2 pic x(30).
01 ws-invalidop object reference cInvalidOperationException.
procedure division.
display "About to Read App Settings...."
invoke cAppSettingsReader::"New" returning myReader
set setting1 to myReader::"GetValue"("MFTEST1",type of cString) as cString *> "as" used to cast object as a string type
display "MFTEST1=" setting1
set setting2 to myReader::"GetValue"("MFTEST2",type of cString) as cString
display "MFTEST2=" setting2
*
***** Use try catch block to detect when a setting is not found.
*
try
set setting2 to myReader::"GetValue"("MFxxTEST2x",type of cString) as cString
catch ws-invalidop
display ws-invalidop::"Message"
end-try
stop run.



