예제 #1
0
        private static unsafe string GetStringUsingCreateStringFromEncoding(
            String_CreateStringFromEncoding createStringFromEncoding,
            byte *bytes,
            int byteCount,
            Encoding encoding)
        {
            // String.CreateStringFromEncoding is an internal method that does not validate
            // arguments, but this implementation can leak publicly (by design) via
            // MetadataStringDecoder.GetString. Therefore, we implement the same validation
            // that Encoding.GetString would do if it were available directly.

            Debug.Assert(encoding != null); // validated by MetadataStringDecoder constructor.

            if (bytes == null)
            {
                throw new ArgumentNullException("bytes");
            }

            if (byteCount < 0)
            {
                throw new ArgumentOutOfRangeException("byteCount");
            }

            return(createStringFromEncoding(bytes, byteCount, encoding));
        }
예제 #2
0
        private static unsafe string GetStringUsingCreateStringFromEncoding(
            String_CreateStringFromEncoding createStringFromEncoding,
            byte* bytes,
            int byteCount,
            Encoding encoding)
        {
            // String.CreateStringFromEncoding is an internal method that does not validate
            // arguments, but this implementation can leak publicly (by design) via
            // MetadataStringDecoder.GetString. Therefore, we implement the same validation
            // that Encoding.GetString would do if it were available directly.

            Debug.Assert(encoding != null); // validated by MetadataStringDecoder constructor.

            if (bytes == null)
            {
                throw new ArgumentNullException(nameof(bytes));
            }

            if (byteCount < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(byteCount));
            }

            return createStringFromEncoding(bytes, byteCount, encoding);
        }