Exemple #1
0
 public StringWithQualityHeaderValue(System.Net.Http.Headers.StringWithQualityHeaderValue containedObject)
 {
     if ((containedObject == null))
     {
         throw new System.ArgumentNullException("containedObject");
     }
     this.containedObject = containedObject;
 }
Exemple #2
0
        // https://stackoverflow.com/questions/9927871/need-an-example-on-how-to-get-preferred-language-from-accept-language-request-he
        private static void GetHeader(Microsoft.AspNetCore.Http.HttpContext context)
        {
            // RequestHeaders.AcceptLanguage P
            string header = context.Request.Headers["Accept-Language"];
            // string header = "en-ca,en;q=0.8,en-us;q=0.6,de-de;q=0.4,de;q=0.2";

            string def =
                Microsoft.Net.Http.Headers.StringWithQualityHeaderValue.ParseList(header.Split(';')).Sort(
                    delegate(StringWithQualityHeaderValue a, StringWithQualityHeaderValue b)
            {
                return(a.Quality.GetValueOrDefault(1).CompareTo(b.Quality.GetValueOrDefault(1)));
            }
                    )[0].ToString();


            Microsoft.Net.Http.Headers.StringWithQualityHeaderValue defLang =
                Microsoft.Net.Http.Headers.StringWithQualityHeaderValue.ParseList(header.Split(';'))
                .OrderByDescending(x => x.Quality.GetValueOrDefault(1))
                .FirstOrDefault();

            // Microsoft.Net.Http.Headers.StringWithQualityHeaderValue.Parse(new StringSegment(v));



            // Query syntax
            //System.Linq.IOrderedEnumerable<System.Net.Http.Headers.StringWithQualityHeaderValue> languages1 =
            System.Net.Http.Headers.StringWithQualityHeaderValue defaultLanguage =
                (from headerParts in header.Split(',')
                 select System.Net.Http.Headers.StringWithQualityHeaderValue.Parse(headerParts) into acceptLanguages
                 orderby acceptLanguages.Quality.GetValueOrDefault(1) descending
                 select acceptLanguages
                ).FirstOrDefault();

            // Method syntax
            System.Linq.IOrderedEnumerable <System.Net.Http.Headers.StringWithQualityHeaderValue> languages = header.Split(',')
                                                                                                              .Select(System.Net.Http.Headers.StringWithQualityHeaderValue.Parse)
                                                                                                              .OrderByDescending(s => s.Quality.GetValueOrDefault(1));
        }
Exemple #3
0
 public static bool TryParse(string input, out System.Net.Http.Headers.StringWithQualityHeaderValue parsedValue)
 {
     throw null;
 }