Example #1
0
        private static int GetStringByteLength(IntPtr p, Encoding encoding)
        {
            Type type = encoding.GetType();
            int  num  = -1;

            if (typeof(UTF8Encoding).IsAssignableFrom(type) || typeof(UTF7Encoding).IsAssignableFrom(type) || typeof(UnixEncoding).IsAssignableFrom(type) || typeof(ASCIIEncoding).IsAssignableFrom(type))
            {
                num = (void *)(checked ((int)Stdlib.strlen(p)));
            }
            else
            {
                num = (!typeof(UnicodeEncoding).IsAssignableFrom(type) ? UnixMarshal.GetRandomBufferLength(p, encoding.GetMaxByteCount(1)) : UnixMarshal.GetInt16BufferLength(p));
            }
            if (num == -1)
            {
                throw new NotSupportedException("Unable to determine native string buffer length");
            }
            return(num);
        }