internal static void DeserializeGenericProfile(string propertyNames, string propertyValues, IKeyValueBunch target) { // Input format: // PROPERTY_NAME:S:START_INDEX:PROP_VALUE_LENGTH // if ((propertyNames != null && propertyValues != null) && target != null) { // try { // string[] names = propertyNames.Split(':'); // divide names length by 4 parts int count = names.Length / 4; // iterate through for (int i = 0; i < count; i++) { // get property name string keyName = names[i * 4]; // string keyValue = String.Empty; // calculate property value start index int startIndex = Int32.Parse(names[(i * 4) + 2], CultureInfo.InvariantCulture); // calculate property value length int length = Int32.Parse(names[(i * 4) + 3], CultureInfo.InvariantCulture); // ensure check property value not empty if (length != -1) { keyValue = propertyValues.Substring(startIndex, length); } // target[keyName] = keyValue; } } catch { } } }
internal static void SerializeGenericProfile(ref string propertyNames, ref string propertyValues, IKeyValueBunch source) { // names StringBuilder namesBuilder = new StringBuilder(); // string values StringBuilder valsBuilder = new StringBuilder(); // string[] allKeys = source.GetAllKeys(); // foreach (string keyName in allKeys) { // int length = 0, position = 0; // get serialized property value string keyValue = source[keyName]; // if (String.IsNullOrEmpty(keyValue)) { length = -1; } else { // length = keyValue.Length; // position = valsBuilder.Length; // valsBuilder.Append(keyValue); } // namesBuilder.Append(keyName + ":S:" + position.ToString(CultureInfo.InvariantCulture) + ":" + length.ToString(CultureInfo.InvariantCulture) + ":"); } // propertyNames = namesBuilder.ToString(); // propertyValues = valsBuilder.ToString(); }