Plain:
- Convert the byte array to
int (either manually or by creating an array of four bytes, and using BitConverter.ToInt32 ) - Move
int to AfpRecordId - Call
ToString on the result, if necessary (the subject line offers to get a name, but your method signature says only about the value)
For instance:
private static AfpRecordId GetAfpRecordId(byte[] data) { // Alternatively, switch on data.Length and hard-code the conversion // for lengths 1, 2, 3, 4 and throw an exception otherwise... int value = 0; foreach (byte b in data) { value = (value << 8) | b; } return (AfpRecordId) value; }
You can use Enum.IsDefined to check if the data is really a valid identifier.
As far as performance is concerned, make sure that something simple gives you reasonably good performance before looking for something faster.
source share