Tuesday, 15 April 2014

.net - Indexed generic (multi-type, single value) multidimensional array in c# -


Task :
Read the trace data from the binary file, where Arrays, The amount and quantity of datatype is defined in the beginning of the file (header).

Conditions :

  • Datatype may be different for each array, but there is only one type of array in it.
  • Each array has the same length, but the amount of arrays can be different.
  • Datatype is defined as a number
  • Information for code implementation -> 4 bytes of length in each datatype file

Intent :
A multi-dimensional me

status :
From my research I can completely construct the following code (Do not know that there are better ways!? Maybe with arrays?). (The best result of research :)

  Private authentic class tracedata {} Private class tracedata & lt; T & gt; : Tracedata {public T [] data; Public Tracedata (UInt32 Length) {Data = New T [Length]; } Public T This [int index] {found {return data [index]; } Set {data [index] = value; }}} Private class marks {public list & lt; Tracedata & gt; Information; Public trail (tracehider header, byte [] file, int offset) {data = new list & lt; Tracedata & gt; (); (Int i = 0; i & lt; header.dataMount; i ++) {tracedata tmp; Switch (Header.datetype [i]) {Case 2: TMP = New Tracedata & lt; SByte & gt; (Header.Data Lang); break; Case 3: TMP = New Tracedata & lt; Int16 & gt; (Header.Data Lang); break; // ... default: tmp = new tracedata & lt; Int32 & gt; (Header.DataLength); break; } DataAdd (TMP); } {Switch (Header. DataType [J]) {Case 2: Data [ATI = 0; I & lt; Header. Data length; I ++) {For (Junk; J & LT; Header Data Data; J ++) J] [i] = (SBit) File [Offset + I * Header. Data item * 4 + J * 4 + 3]; break; Case 3: Data [J] [I] = Bit sign. TOUINT 16 (File, Offset + I * Header DataImount * 4 + J * 4 + 2); break; // ... Default: Data [J] [I] = Bit sign. TOUINT 32 (file, offset + I * header data item * 4 + J * 4 + 0); break; }}}}  

Problem :
With that code, I can not index any element of traceata type.

Hope you can help THX

I think its The issue is to use the data-array of tracedata in general, but it does not have the same knowledge of the types of abstract-base traceadata type objects that do not work like these calls:

  data ] [I] = (sbit) file [offset + i * header. Data mount * 4 + j * 4 + 3];  

Because data [j] is of type tracedata. In any case you have to know the general logic of the type used in that specific example. You can cast (example for SBIT):

  tracedata & lt; SByte & gt; SBETTraceData = (TraceData, LBT; SBET & gt;) Data [J]; SBETTressData [I] = (SBIT) file [Offset + I * header. DataImount * 4 + G * 4 + 3];  

No comments:

Post a Comment