自定义config文件
来源:互联网 发布:mysql 导出文件格式 编辑:程序博客网 时间:2024/06/15 19:56
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Serialization;
using System.Text;
using System.IO;
using System.Xml;
namespace FutureDBDecompositionTools.Config
{
[Serializable]
public class Setting
{
static readonly string xmlFileName = AppDomain.CurrentDomain.BaseDirectory + "DecompositionSetting.xml";
static private Setting setting ;
public static Setting SettingInstance
{
get {
if (setting == null)
{
GetSettingFromXmlFile();
if (setting == null)
{
setting = new Setting();
}
}
return setting;
}
set {
setting = value;
}
}
private static void GetSettingFromXmlFile()
{
FileInfo file = new FileInfo(xmlFileName);
if (File.Exists(file.ToString()))
{
string xml = File.ReadAllText(file.FullName);
if ((xml!=null) && (xml != string.Empty))
{
setting = Logic.SimpleSerializer.Deserialize(typeof(Setting), xml) as
Setting;
}
}
}
public void SaveSettingToXmlFile()
{
string xml = Logic.SimpleSerializer.Serialize<Setting>(setting);
FileInfo file = new FileInfo(xmlFileName);
if (File.Exists(file.ToString()))
{
file.Delete();
}
File.WriteAllText(AppDomain.CurrentDomain.BaseDirectory + "DecompositionSetting.xml", xml);
}
private Setting() { }
private string matters_Offline;
[XmlElement("Matters_Offline")]
public string Matters_Offline
{
get
{
return matters_Offline;
}
set
{
matters_Offline = value;
}
}
string orderDatas_Offline;
[XmlElement("OrderDatas_Offline")]
public string OrderDatas_Offline
{
get
{
return orderDatas_Offline;
}
set
{
orderDatas_Offline = value;
}
}
string distributes_Offline;
[XmlElement("Distributes_Offline")]
public string Distributes_Offline
{
get
{
return distributes_Offline;
}
set
{
distributes_Offline = value;
}
}
string jobs_Offline;
[XmlElement("Jobs_Offline")]
public string Jobs_Offline
{
get
{
return jobs_Offline;
}
set
{
jobs_Offline = value;
}
}
string parentDatas_Offline;
[XmlElement("ParentDatas_Offline")]
public string ParentDatas_Offline
{
get
{
return parentDatas_Offline;
}
set
{
parentDatas_Offline = value;
}
}
string childDatas_Offline;
[XmlElement("ChildDatas_Offline")]
public string ChildDatas_Offline
{
get
{
return childDatas_Offline;
}
set
{
childDatas_Offline = value;
}
}
string futureManagement_Offline;
[XmlElement("FutureManagement_Offline")]
public string FutureManagement_Offline
{
get
{
return futureManagement_Offline;
}
set
{
futureManagement_Offline = value;
}
}
string decompositionOrders_Offline;
[XmlElement("DecompositionOrders_Offline")]
public string DecompositionOrders_Offline
{
get
{
return decompositionOrders_Offline;
}
set
{
decompositionOrders_Offline = value;
}
}
string offline;
[XmlElement("Offline")]
[System.Configuration.DefaultSettingValueAttribute("False")]
public string Offline
{
get
{
return offline;
}
set
{
offline = value;
}
}
string dBAddress_Online;
[XmlElement("DBAddress_Online")]
public string DBAddress_Online
{
get
{
return dBAddress_Online;
}
set
{
dBAddress_Online = value;
}
}
string ddAddress_Offline;
[XmlElement("DBAddress_Offline")]
[System.Configuration.DefaultSettingValueAttribute("")]
public string DBAddress_Offline
{
get
{
return ddAddress_Offline;
}
set
{
ddAddress_Offline = value;
}
}
string accounts_Offline;
[XmlElement("Accounts_Offline")]
public string Accounts_Offline
{
get
{
return accounts_Offline;
}
set
{
accounts_Offline = value;
}
}
string dBAddress_Decomposition;
[XmlElement("DBAddress_Decomposition")]
public string DBAddress_Decomposition
{
get
{
return dBAddress_Decomposition;
}
set
{
dBAddress_Decomposition = value;
}
}
string decompositionOrders_Online;
[XmlElement("DecompositionOrders_Online")]
public string DecompositionOrders_Online
{
get
{
return decompositionOrders_Online;
}
set
{
decompositionOrders_Online = value;
}
}
public string this[string propertyName]
{
get
{
return (GetProperty(propertyName));
}
set
{
SetProperty(propertyName,value);
}
}
void SetProperty(string propertyName,string Value)
{
switch (propertyName)
{
case "Matters_Offline":
setting.Matters_Offline = Value;
break;
case "OrderDatas_Offline":
setting.OrderDatas_Offline = Value;
break;
case "Distributes_Offline":
setting.Distributes_Offline = Value;
break;
case "Jobs_Offline":
setting.Jobs_Offline = Value;
break;
case "ParentDatas_Offline":
setting.ParentDatas_Offline = Value;
break;
case "ChildDatas_Offline":
setting.ChildDatas_Offline = Value;
break;
case "FutureManagement_Offline":
setting.FutureManagement_Offline = Value;
break;
case "DecompositionOrders_Offline":
setting.DecompositionOrders_Offline = Value;
break;
case "Offline":
setting.Offline = Value;
break;
case "DBAddress_Online":
setting.DBAddress_Online = Value;
break;
case "DBAddress_Offline":
setting.DBAddress_Offline = Value;
break;
case "Accounts_Offline":
setting.Accounts_Offline = Value;
break;
case "DBAddress_Decomposition":
setting.DBAddress_Decomposition = Value;
break;
case "DecompositionOrders_Online":
setting.DecompositionOrders_Online = Value;
break;
default:
break;
}
}
string GetProperty(string propertyName)
{
string Value = string.Empty;
switch (propertyName)
{
case "Matters_Offline":
Value = setting.Matters_Offline;
break;
case "OrderDatas_Offline":
Value = setting.OrderDatas_Offline;
break;
case "Distributes_Offline":
Value = setting.Distributes_Offline;
break;
case "Jobs_Offline":
Value = setting.Jobs_Offline;
break;
case "ParentDatas_Offline":
Value = setting.ParentDatas_Offline;
break;
case "ChildDatas_Offline":
Value = setting.ChildDatas_Offline;
break;
case "FutureManagement_Offline":
Value = setting.FutureManagement_Offline;
break;
case "DecompositionOrders_Offline":
Value = setting.DecompositionOrders_Offline;
break;
case "Offline":
Value = setting.Offline;
break;
case "DBAddress_Online":
Value = setting.DBAddress_Online;
break;
case "DBAddress_Offline":
Value = setting.DBAddress_Offline;
break;
case "Accounts_Offline":
Value = setting.Accounts_Offline;
break;
case "DBAddress_Decomposition":
Value = setting.DBAddress_Decomposition;
break;
case "DecompositionOrders_Online":
Value = setting.DecompositionOrders_Online;
break;
default:
break;
}
return Value;
}
}
}
- config文件自定义节点
- 自定义config文件
- 读取自定义的config文件
- .NET读取自定义config文件的案例
- 如何在.config文件自定义配置节
- 在.Config文件中自定义配置节
- ASP.NET读取自定义的config文件
- 自定义app.config文件的结点
- .Net 自定义读取自定Config文件
- web.config文件自定义配置节的使用方法
- web.config文件自定义配置节的使用方法
- web.config文件自定义配置节的使用方法
- web.config文件自定义配置节的使用方法
- web.config文件自定义配置节的使用方法
- web.config文件自定义配置节的使用方法 (转)
- 在C#类库中使用App.config文件自定义配置
- CI3框架初识-自动加载之自定义config文件
- 如何在web.config 或者 app.config 文件中配置自定义节点
- HandleResourceChange中的事件处理
- java作业01
- 当你输入一个网址的时候,实际会发生什么?(很好的一篇文章)
- 解释冷备份和热备份的不同点以及各自的优点
- 自定义事件
- 自定义config文件
- 开通了CSDN博客了
- 无法删除Adobe Reader 9.X程序安装目录的解决办法
- 定义不一定在相应的cpp里
- 文件系统
- 加 inline
- s3c2410矩阵键盘驱动
- 在存储过程中运用事务
- 清除栈错误: User 42 panic