12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- using System;
- using System.Collections.Generic;
- using System.Text;
- using Utilities;
- namespace ISCSI
- {
- public class KeyValuePairUtils
- {
- public static KeyValuePairList<string, string> GetKeyValuePairList(string nullDelimitedString)
- {
- KeyValuePairList<string, string> result = new KeyValuePairList<string, string>();
- string[] entries = nullDelimitedString.Split('\0');
- foreach (string entry in entries)
- {
- string[] pair = entry.Split('=');
- if (pair.Length >= 2)
- {
- string key = pair[0];
- string value = pair[1];
- result.Add(key, value);
- }
- }
- return result;
- }
- public static string GetNullDelimitedKeyValuePair(KeyValuePairList<string, string> list)
- {
- StringBuilder builder = new StringBuilder();
- foreach (KeyValuePair<string, string> pair in list)
- {
- builder.AppendFormat("{0}={1}\0", pair.Key, pair.Value);
- }
- return builder.ToString();
- }
- public static string ToString(KeyValuePairList<string, string> list)
- {
- StringBuilder builder = new StringBuilder();
- for (int index = 0; index < list.Count; index++)
- {
- if (index > 0)
- {
- builder.Append(", ");
- }
- builder.AppendFormat("{0}={1}", list[index].Key, list[index].Value);
- }
- return builder.ToString();
- }
- }
- }
|