static int ApplyRefArrayOptions <T>(ref T[] arg1, ref T[] outArray, int outLenArray, RefArrayOptions options) { int res = SUCCESS; switch (options) { case RefArrayOptions.Resize: if (arg1 == null || arg1.Length != outLenArray) { outArray = new T[outLenArray]; } else { outArray = arg1; } break; case RefArrayOptions.Flexible: if (arg1 == null || arg1.Length < outLenArray) { outArray = new T[outLenArray]; } else { outArray = arg1; } break; case RefArrayOptions.Fix: if (arg1 == null || arg1.Length < outLenArray) { res = ERROR; } break; } return(res); }
public unsafe static int ToStringArray(this byte[] bytes, int offset, ref string[] arg1, out int outLenArray, RefArrayOptions options = RefArrayOptions.Resize) { outLenArray = 0; int lenArray; int realSize = sizeof(char); int res = CheckToArray(bytes, offset, out lenArray, realSize, CHAR_SIZE, INT_SIZE); if (res != SUCCESS) { return(res); } offset += INT_SIZE; int lenBytes = INT_SIZE; string[] array = null; res = ApplyRefArrayOptions(ref arg1, ref array, lenArray, options); if (res != SUCCESS) { return(res); } outLenArray = lenArray; if (lenArray > 0) { for (int i = 0; i < lenArray; i++) { res = bytes.ToString(offset, out array[i]); if (res == ERROR) { return(ERROR); } offset += res; lenBytes += res; } } if (res != ERROR) { arg1 = array; } return(res != ERROR ? lenBytes : res); }