BitMiracle.LibTiff.Classic.FieldValue.ToUShortArray C# (CSharp) Method

ToUShortArray() private method

private ToUShortArray ( ) : ushort[]
return ushort[]
        public ushort[] ToUShortArray()
        {
            if (m_value == null)
                return null;

            Type t = m_value.GetType();
            if (t.IsArray)
            {
                if (m_value is ushort[])
                    return m_value as ushort[];
                else if (m_value is byte[])
                {
                    byte[] temp = m_value as byte[];
                    if (temp.Length % sizeof(ushort) != 0)
                        return null;

                    int totalUShorts = temp.Length / sizeof(ushort);
                    ushort[] result = new ushort[totalUShorts];

                    int byteOffset = 0;
                    for (int i = 0; i < totalUShorts; i++)
                    {
                        ushort s = BitConverter.ToUInt16(temp, byteOffset);
                        result[i] = s;
                        byteOffset += sizeof(ushort);
                    }

                    return result;
                }
                else if (m_value is short[])
                {
                    short[] temp = m_value as short[];
                    ushort[] result = new ushort[temp.Length];
                    for (int i = 0; i < temp.Length; i++)
                        result[i] = (ushort)temp[i];

                    return result;
                }
                else if (m_value is int[])
                {
                    int[] temp = m_value as int[];
                    ushort[] result = new ushort[temp.Length];
                    for (int i = 0; i < temp.Length; i++)
                        result[i] = (ushort)temp[i];

                    return result;
                }
                else if (m_value is uint[])
                {
                    uint[] temp = m_value as uint[];
                    ushort[] result = new ushort[temp.Length];
                    for (int i = 0; i < temp.Length; i++)
                        result[i] = (ushort)temp[i];

                    return result;
                }
            }

            return null;
        }