I am trying use indexer to solve array property in the class. Please let me know how to handle based on below code sample. Index based property should be able to update another property internally.
Legacy Structure:
Record LegacyRec type basicRecord
3 TOTALPAID num(13,2) ;
3 TABLEOC2 char(85) ; // ONE OCCUR OF DATA - Below items are part of TABELOC2
4 DUEDATEX char(10) ;
4 ACCTX char(6) ;
4 TAXX num(9,2) ;
4 PENALTYX num(9,2) ;
4 INTERESTX num(9,2) ;
4 FEESX num(9,2) ;
4 TOTALPAIDX num(13,2) ;
4 SEQNUMX smallint ;
4 BILLNUMX char(8) ;
4 FILEDDATEX char(10) ;
3 TABLEKEY char(12) ; // TABLEKEY
4 TABLEID char(8) ;
4 TABLECODE char(4) ;
3 TABLEALL char(29750) ; // UP TO 400 OCCURS
4 TABLEOC1 char(85) [350] ; // INDEXED REDEFINE OF ABOVE
3 TABLESCREEN char(1275) ; // UP TO 15 OCCURS - It holds the data below array
4 TABLESCR char(61) [15] ; // INDEXED REDEFINE OF ABOVE
5 DUEDATES char(10) ;
5 ACCTS char(6) ;
5 TAXS num(9,2) ;
5 SEQNUMS smallint ;
5 CNT int ;
5 BILLNUMS char(10) ;
5 FILEDDATES char(20) ;
end
Front Code: (Cannot change but I can some additonal function calls in case needed)
decimal x;
string y;
LegacyRec XYZ1 = new LegacyRec();
XYZ1.TABLEOC2 = "ABCDEFGHIJXYZPQR 1234.78 67 4567.89 755553.55 56 63744.6 1RTY ZXCVBNMIOP";
x = XYZ1.PENALTYX;
y = XYZ1.DUEDATEX;
y = XYZ1.FILEDDATEX;
XYZ1.PENALTYX = 111.11M;
XYZ1.SEQNUMX = 34;
XYZ1.FILEDDATEX = "1234567890";
XYZ1.TABLEOC1[2]= "RRRR";
XYZ1.bdate = 10;
XYZ1.iitem[1] = 123;
XYZ1.il6[2] = "RTRRRTY";
for (int i = 1; i < XYZ1.TABLESCR.Count(); i++)
XYZ1.TABLESCR[i] = "";
XYZ1.TABLESCR[6] = "10/10/2010A5670056.89 231000AAA 20200202";
y = XYZ1.TAXS[6] ; //should show 56.89
.NET class //My current Structure Missing Indexer. I have problem setting up array of array property using Indexer.
public class LegacyRec: basicRecord
{
public decimal TOTALPAID { get; set; }
public string TABLEOC2 { get; set; } //Main field
public string DUEDATEX {
get { return getPartialData(TABLEOC2, 1, 10).ToString(); }
set { TABLEOC2 = setPartialData(TABLEOC2, 1, 10, value).ToString(); } } //Sub Fields
public string ACCTX {
get { return getPartialData(TABLEOC2, 11, 6).ToString(); }
set { TABLEOC2 = setPartialData(TABLEOC2, 11, 6, value).ToString(); } } //Sub Fields
public decimal TAXX {
get { try { return decimal.Parse(getPartialData(TABLEOC2, 17, 9).ToString()); } catch { return 0; } }
set { TABLEOC2 = setPartialData(TABLEOC2, 11, 6, value).ToString(); } } //Sub Fields
public decimal PENALTYX {
get { try { return decimal.Parse(getPartialData(TABLEOC2, 26, 9).ToString()); } catch { return 0; } }
set { TABLEOC2 = setPartialData(TABLEOC2, 26, 9, value).ToString(); } } //Sub Fields
public decimal INTERESTX {
get { try { return decimal.Parse(getPartialData(TABLEOC2, 35, 9).ToString()); } catch { return 0; } }
set { TABLEOC2 = setPartialData(TABLEOC2, 35, 9, value).ToString(); } } //Sub Fields
public decimal FEESX {
get { try { return decimal.Parse(getPartialData(TABLEOC2, 44, 9).ToString()); } catch { return 0; } }
set { TABLEOC2 = setPartialData(TABLEOC2, 44, 9, value).ToString(); } } //Sub Fields
public decimal TOTALPAIDX {
get { try { return decimal.Parse(getPartialData(TABLEOC2, 53, 13).ToString()); } catch { return 0; } }
set { TABLEOC2 = setPartialData(TABLEOC2, 53, 13, value).ToString(); } } //Sub Fields
public int SEQNUMX {
get { try { return int.Parse(getPartialData(TABLEOC2, 66, 2).ToString()); } catch { return 0; } }
set { TABLEOC2 = setPartialData(TABLEOC2, 66, 2, value).ToString(); } } //Sub Fields
public string BILLNUMX {
get { return getPartialData(TABLEOC2, 68, 8).ToString(); }
set { TABLEOC2 = setPartialData(TABLEOC2, 68, 8, value).ToString(); } } //Sub Fields
public string FILEDDATEX {
get { return getPartialData(TABLEOC2, 76, 10).ToString(); }
set { TABLEOC2 = setPartialData(TABLEOC2, 76, 10, value).ToString(); } } //Sub Fields
public string TABLEALL { get; set; } // UP TO 400 OCCURS
private string[] _TABLEOC1;
public string this[int index] //not working
{
get { return _TABLEOC1[index]; }
set { _TABLEOC1[index] = value; TABLEALL = setPartialData(_TABLEOC1[index], index*10, 10, value).ToString(); //not working at this time}
}
public string[] TABLEOC1 {
get { return _TABLEOC1; }
set { TABLEALL = setPartialData(TABLEOC1[index], index*, 85, value).ToString(); } } // INDEXED REDEFINE OF ABOVE [350]
private string[] _TABLESCR;
public string[] TABLESCR { get { return _TABLESCR; } set { string s = "123"; } } //Main array with TableScreen
public string[] DUEDATES {
get from TABLESCR[index];
set TABLESCR particular Index; }
public string[] ACCTS {
get from TABLESCR[index];
set TABLESCR particular Index; }
public decimal[] TAXS {
get from TABLESCR[index];
set TABLESCR particular Index;}
public int[] SEQNUMS {
get from TABLESCR[index];
set TABLESCR particular Index;}
public int[] CNT {
get from TABLESCR[index];
set TABLESCR particular Index;}
public string[] BILLNUMS {
get from TABLESCR[index];
set TABLESCR particular Index;}
public string[] FILEDDATES {
get from TABLESCR[index];
set TABLESCR particular Index;}
}
The short answer to your question is that you have to create arrays to do that.
It's complicated because you're trying to do data overlays in a way that C# just doesn't support well. For example, you have:
And
XYZ1.PENALTYX
is one of the numeric fields in that string. You can make it work okay for a single record likeTABLEOC2
, but when you get into arrays it gets rather difficult. C# just doesn't have the concept of overlaying numbers on top of strings. Trying to make it do that will require that you define aTABLESCR
class that is implicitly assignable from string, and also has properties forACCTS
,TAXS
, etc. You could then have an array of thoseTABLESCR
instances and index into that.Your
TABLESCR
class would look something like:It's hard to say if you want a struct or a class there. There are drawbacks to each, but I'd suggest a class. The constructor for your
basicRecord
would probably want to initialize the array with a bunch of empty TABLESCR instances.In your
basicRecord
, you'd have:TABLEALL is pretty easy, just an array of strings:
Then you can reference
TABLESCREEN[1]
andTABLEALL[1]
, etc.Understand, that doesn't exactly duplicate the memory layout that you had, but it duplicates the functionality. You can use custom import and export logic to convert this from and to whatever data storage format you're using.