FiftyOne.Foundation.Mobile.Detection.Provider.MatchForHeaders C# (CSharp) Method

MatchForHeaders() private method

For each of the important HTTP headers provides a mapping to a match result.
private MatchForHeaders ( Match match, NameValueCollection headers, IEnumerable importantHeaders ) : MatchState>.Dictionary
match System.Text.RegularExpressions.Match /// A match object created by a previous match, or via the /// method. ///
headers System.Collections.Specialized.NameValueCollection The HTTP headers available for matching
importantHeaders IEnumerable HTTP header names important to the match process
return MatchState>.Dictionary
        private Dictionary<string, MatchState> MatchForHeaders(Match match, NameValueCollection headers, IEnumerable<string> importantHeaders)
        {
            // Relates HTTP header names to match resutls.
            var matches = new Dictionary<string, MatchState>();

            // Iterates through the important header names.
            var iterator = importantHeaders.GetEnumerator();

            // Make the first match used the match passed
            // into the method. Subsequent matches will
            // use a new instance.
            while(iterator.MoveNext())
            {
                matches.Add(iterator.Current, new MatchState(match) { TargetUserAgent = headers[iterator.Current] });
            }

            // Using each of the match instances pass the
            // value to the match method and set the results.
            // Done in parallel to improve performance if
            // multi threading available.
            Parallel.ForEach(matches, m =>
            {
                Match(headers[m.Key], m.Value);
            });
            return matches;
        }