示例#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, "");
     }
 }
示例#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);
     }
 }
示例#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);
     }
 }
示例#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;
         }
     }
 }
示例#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;
         }
     }
 }
示例#6
0
 /// <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));
 }