C# 重写GetSetting SaveSetting
[csharp]using Microsoft.Win32;
using System;
using System.Collections;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Security;
using System.Security.Permissions;
using System.Text;
using System.Threading;
using System.Windows.Forms;
/* 2012.6.21
* 注册表读写配置类 V1.1
* By:Transmart www.zzzyk.com
* 我们提供软件外包服务,专注于工控组态软硬件开发,涉足网路、数据库、系统编程
* 欢迎大家来信交流
* 转载时请保留这段声明,谢谢
*/
namespace Main
{
public class Class_Setting
{
static string myAppName=null ;
private static bool IsNothing(object Expression)
{
return (Expression == null);
}
private static string FormRegKey(string sApp, string sSect)
{
if (IsNothing(sApp) || (sApp.Length == 0))
{
return @"Software\Transmart";
}
if (IsNothing(sSect) || (sSect.Length == 0))
{
return (@"Software\Transmart\" + sApp);
}
return (@"Software\Transmart\" + sApp + @"\" + sSect);
}
private static void CheckPathTransmart(string s)
{
if ((s == null) || (s.Length == 0))
{
throw new ArgumentException("参数路径为空!");
}
}
/// <summary>
/// 初始化程序名,使用时请先初始化程序名
/// </summary>
/// <param name="Appname"></param>
public static void IniSetting(string Appname)
{
myAppName = Appname;
}
public static void SaveSetting(string Section, string Key, string Setting)
{
SaveSetting(myAppName, Section, Key, Setting);
}
public static void SaveSetting(string AppName, string Section, string Key, string Setting)
{
CheckPathTransmart(AppName);
CheckPathTransmart(Section);
CheckPathTransmart(Key);
string subkey = FormRegKey(AppName, Section);
RegistryKey key = Registry.LocalMachine.CreateSubKey(subkey);
if (key == null)
{
throw new ArgumentException("无法创建配置!");
}
try
{
key.SetValue(Key, Setting);
}
catch (Exception exception)
{
throw exception;
}
finally
{
key.Close();
}
}
public static string GetSetting( string Section, string Key, string Default = "")
{
return GetSetting(myAppName, Section, Key, Default);
}
public static string GetSetting(string AppName, string Section, string Key, string Default = "")
{
object obj2;
RegistryKey key = null;
CheckPathTransmart(AppName);
CheckPathTransmart(Section);
CheckPathTransmart(Key);
if (Default == null)
{
&n
补充:软件开发 , C# ,