Beispiel #1
0
 public static void WriteRegistryValue <T>(RegistryKey key, string name, T value)
 {
     if (value != null)
     {
         key.SetValue(name, InvariantConverter.ToString(value));
     }
     else
     {
         key.SetValue(name, "");
     }
 }
Beispiel #2
0
 public static T ReadRegistryValue <T>(RegistryKey key, string name, T defaultValue)
 {
     try
     {
         string strValue = (string)key.GetValue(name, InvariantConverter.ToString(defaultValue));
         return(InvariantConverter.FromString <T>(strValue));
     }
     catch
     {
         return(defaultValue);
     }
 }
Beispiel #3
0
 public static T DeserializeValueFromRegistry <T>(RegistryKey key, string name, T defaultValue)
 {
     try
     {
         string strValue = (string)key.GetValue(name, InvariantConverter.ToString(defaultValue));
         return(DeserializeValue <T>(strValue));
     }
     catch
     {
         return(defaultValue);
     }
 }
Beispiel #4
0
 public static void WriteRegistryList <T>(RegistryKey key, string baseName, IEnumerable <T> list)
 {
     if (list != null)
     {
         int index = 1;
         foreach (T item in list)
         {
             Utils.WriteRegistryValue(key, baseName + index.ToString(), InvariantConverter.ToString(item));
             ++index;
         }
     }
 }
Beispiel #5
0
 public static IEnumerable <T> ReadRegistryList <T>(RegistryKey key, string baseName)
 {
     for (int index = 1; ; ++index)
     {
         object value = key.GetValue(baseName + index.ToString());
         if (value != null)
         {
             yield return(InvariantConverter.FromString <T>(value.ToString()));
         }
         else
         {
             break;
         }
     }
 }
 /// <summary>
 /// Converts a value to string using <ref>InvariantConverter</ref>
 /// </summary>
 /// <param name="value">The value to convert.</param>
 /// <returns>The invariant string representation of the value.</returns>
 public static string ToInvString <T>(this T value)
 {
     return(InvariantConverter.ToString(value));
 }