Case Study: In this demo scenario, we are going to build Windows Code page using X++ class.
For this project, I have build a generation class which basically returns the list of available codePage.
private void buildCodePage()
{
System.Text.EncodingInfo[] encodingInfoArray;
System.Text.EncodingInfo encodingObject;
RecordInsertList recordInsertList =
new RecordInsertList(tableNum(CodePageTable));
System.Exception ex;
InteropPermission permission =
new InteropPermission(InteropKind::ClrInterop);
;
// Clear always the codePage data is available
delete_from codePage;
try
{
permission.assert();
encodingInfoArray = System.Text.Encoding::GetEncodings();
// BP Deviation Documented.
for (i = 0; i <=
CLRInterop::getAnyTypeForObject(
encodingInfoArray.get_Length()) - 1;
i++ )
{
encodingObject = encodingInfoArray.GetValue(i);
codePage.CodePage = System.Convert::ToString(
encodingObject.get_CodePage());
codePage.DisplayName = System.Convert::ToString(
encodingObject.get_DisplayName());
recordInsertList.add(codePage);
}
ttsbegin;
recordInsertList.insertDatabase();
ttsCommit;
CodeAccessPermission::revertAssert();
}
catch (Exception::CLRError)
{
ex = ClrInterop::getLastException();
if (ex != null)
{
ex = ex.get_InnerException();
if (ex != null)
{
error(ex.ToString());
}
}
}
}
For this project, I have build a generation class which basically returns the list of available codePage.
private void buildCodePage()
{
System.Text.EncodingInfo[] encodingInfoArray;
System.Text.EncodingInfo encodingObject;
RecordInsertList recordInsertList =
new RecordInsertList(tableNum(CodePageTable));
System.Exception ex;
InteropPermission permission =
new InteropPermission(InteropKind::ClrInterop);
;
// Clear always the codePage data is available
delete_from codePage;
try
{
permission.assert();
encodingInfoArray = System.Text.Encoding::GetEncodings();
// BP Deviation Documented.
for (i = 0; i <=
CLRInterop::getAnyTypeForObject(
encodingInfoArray.get_Length()) - 1;
i++ )
{
encodingObject = encodingInfoArray.GetValue(i);
codePage.CodePage = System.Convert::ToString(
encodingObject.get_CodePage());
codePage.DisplayName = System.Convert::ToString(
encodingObject.get_DisplayName());
recordInsertList.add(codePage);
}
ttsbegin;
recordInsertList.insertDatabase();
ttsCommit;
CodeAccessPermission::revertAssert();
}
catch (Exception::CLRError)
{
ex = ClrInterop::getLastException();
if (ex != null)
{
ex = ex.get_InnerException();
if (ex != null)
{
error(ex.ToString());
}
}
}
}