You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
publicstaticclassNamedValueCollectionExtensions{publicstaticIEnumerable<KeyValuePair<string,string[]>>AsEnumerable(thisNameValueCollectionthat){returnthat.Cast<string>()// doesn't implement IEnumerable<T>, but does implement IEnumerable.Select((item,index)=>// enable indexing by integer rather than stringnewKeyValuePair<string,string[]>(item,that.GetValues(index)));// if you use the indexer or GetValue it flattens multiple values for a key, Joining them with a ',' which we don't want}publicstaticIEnumerable<KeyValuePair<string,string>>AsKeyValuePairs(thisIEnumerable<KeyValuePair<string,string[]>>that){returnthat.SelectMany( item =>item.Value.Select( value =>newKeyValuePair<string,string>(item.Key,value)));}publicstaticNameValueCollectionToNameValueCollection(thisIEnumerable<KeyValuePair<string,string[]>>that){returnthat.AsKeyValuePairs().ToNameValueCollection();}publicstaticNameValueCollectionToNameValueCollection(thisIEnumerable<KeyValuePair<string,string>>that){varresult=newNameValueCollection();foreach(KeyValuePair<string,string>iteminthat)result.Add(item.Key,item.Value);returnresult;}}