Exemplo n.º 1
0
        /// <summary>
        /// Gets this setting's value as a string.
        /// </summary>
        /// <returns>Returns this setting's value as a string.</returns>
        public string GetValueAsString()
        {
            object? value = GetValue();

            if (value == null)
                return string.Empty;
            else if (value is byte[] byteArray)
                return ArrayToString.Encode(byteArray.Select(b => b.ToString()).ToArray());
            else if (value is string[] stringArray)
                return ArrayToString.Encode(stringArray);
            else
                return value?.ToString() ?? string.Empty;
        }
Exemplo n.º 2
0
 /// <summary>
 /// Sets this setting's value from a string.
 /// </summary>
 /// <param name="value">A string that represents the value this setting should be set to.</param>
 public void SetValueFromString(string value)
 {
     if (value != null)
     {
         try
         {
             if (Type == typeof(byte[]))
                 SetValue(ArrayToString.Decode(value).Select(s => byte.Parse(s)).ToArray());
             else if (Type == typeof(string[]))
                 SetValue(ArrayToString.Decode(value));
             else
                 SetValue(value);
         }
         catch (Exception) { Debug.Assert(false); }
     }
 }