HasLength() публичный Метод

public HasLength ( ) : bool
Результат bool
Пример #1
0
        public string ReadAsString()
        {
            HttpContent content  = this;
            var         encoding = HttpTextEncodingHelpers.ExtractEncodingOrDefaultHttp(content.ContentType);

            if (content.HasLength())
            {
                var    preamble = encoding.GetPreamble();
                var    bytes    = content.ReadAsByteArray();
                string s;
                if (preamble.SequenceEqual(bytes.Take(preamble.Length)))
                {
                    s = encoding.GetString(bytes, preamble.Length, bytes.Length - preamble.Length);
                }
                else
                {
                    s = encoding.GetString(bytes);
                }
                return(s);
            }

            using (var stream = content.ReadAsStream())
            {
                using (var reader = new StreamReader(stream, encoding))
                {
                    return(reader.ReadToEnd());
                }
            }
        }
Пример #2
0
 public static bool IsNullOrEmpty(HttpContent content)
 {
     if (content == null)
     {
         return(true);
     }
     if (content.content is EmptyContent || (content.HasLength() && content.GetLength() == 0))
     {
         return(true);
     }
     return(false);
 }
 public static bool IsNullOrEmpty(HttpContent content)
 {
     if (content == null)
     {
         return true;
     }
     if (content.content is EmptyContent || (content.HasLength() && content.GetLength() == 0))
     {
         return true;
     }
     return false;
 }