CSharpUtils.Http.HttpHeader.ParseValue C# (CSharp) Метод

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

public ParseValue ( String FirstKeyName = "Type" ) : String>.Dictionary
FirstKeyName String
Результат String>.Dictionary
		public Dictionary<String, String> ParseValue(String FirstKeyName = "Type")
		{
			var Values = new Dictionary<String, String>();
			var TwoParts=  Value.Split(new char[] { ';' }, 2);
			Values[FirstKeyName] = TwoParts[0];
			//Console.WriteLine(TwoParts[0]);
			if (TwoParts.Length == 2)
			{
				var ParseLeft = new Regex("\\s*(\\w+)=(\"|)([^\"]*)\\2(;|$)", RegexOptions.Compiled);
				foreach (Match Match in ParseLeft.Matches(TwoParts[1]))
				{
					string MatchKey = Match.Groups[1].Value;
					string MatchValue = Match.Groups[3].Value;
					Values[MatchKey.ToLower()] = MatchValue;
					//Console.WriteLine(Match.Groups[1]);
				}
			}

			return Values;
		}
	}

Usage Example

Пример #1
0
        public void TestMethod1()
        {
            HttpHeader ContentType = new HttpHeader("Content-Type", "multipart/form-data; boundary=----WebKitFormBoundaryIMw3ByBOPx38V6Bd");
            var ContentTypeParts = ContentType.ParseValue("type");
            CollectionAssert.AreEqual(new Dictionary<string, string>() {
                { "type", "multipart/form-data" },
                { "boundary", "----WebKitFormBoundaryIMw3ByBOPx38V6Bd" },
            }, ContentTypeParts);

            ContentType = new HttpHeader("Content-Type", "multipart/form-data; boundary=\"----WebKitFormBoundaryIMw3ByBOPx38V6Bd\"");
            ContentTypeParts = ContentType.ParseValue("type");
            CollectionAssert.AreEqual(new Dictionary<string, string>() {
                { "type", "multipart/form-data" },
                { "boundary", "----WebKitFormBoundaryIMw3ByBOPx38V6Bd" },
            }, ContentTypeParts);
        }
All Usage Examples Of CSharpUtils.Http.HttpHeader::ParseValue