ConfigurationPattern V1.1.1 版本发布--该版本增加自动读写注册表配置的功能
Posted on 2008-05-06 14:52 eaglet 阅读(2545) 评论(3) 编辑 收藏 举报ConfigurationPattern V1.1.1 版本发布
作者:肖波
V1.1.1 版本增加一个配置模式 RegistryKeyPattern,用于帮助调用者自动读写注册表配置。另外该版本将
IConfigurationPattern 接口的parameter 参数类型有String改为Object,以便更加通用。
注册表配置的使用:
using System;
using System.Collections.Generic;
using System.Text;
using ConfigurationPattern;
using ConfigurationPattern.Patterns;
using ConfigurationPattern.Patterns.Registry;
using Microsoft.Win32;
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
namespace CfgSample
{
[ConfigurationPattern(TPattern.REGISTRY, RegistryHive.CurrentUser)]
class MyRegCfg : Configuration
{
String m_Name;
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
[SubKey(@"software\test")]
public String Name
{
get
{
return m_Name;
}
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
set
{
m_Name = value;
}
}
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
int m_Age = 0;
[SubKey(@"software\test", "Age", 18, RegistryValueKind.DWord)]
public int Age
{
get
{
return m_Age;
}
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
set
{
m_Age = value;
}
}
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
byte[] m_Data = null;
[HKey(RegistryHive.CurrentUser)]
[SubKey(@"software\test", "Data")]
public byte[] Data
{
get
{
return m_Data;
}
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
set
{
m_Data = value;
}
}
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
}
}
上述代码是一个注册表配置类的例子
在类级别需要声明ConfigurationPattern属性。
第一个参数指定模式类型为TPattern.REGISTRY即注册表配置模式。
第二个参数指定默认的HKey,可以不指定默认HKey。如果不指定默认HKey,则每个配置字段都必须用HKey 属性指定对应的HKey。
在字段级别需要
需要指定两个属性HKey和Subkey,其中HKey为可选,如果在类级别指定了默认HKey,字段级别的HKey可以不指定,除非该字段要访问
和默认HKey不同的HKey。
Subkey 属性有4个参数
path:指定键所在路径,该参数必须指定
name:指定键名,可选。如果不指定,键名默认和字段名相同
defaultValue:默认值,可选。
valueKind:键的类型,可选。
注册表配置类的调用示例。
见下面代码,调用方法和其他配置类的调用方法相同。
MyRegCfg myRegCfg = new MyRegCfg();
myRegCfg.Open();
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
Console.WriteLine(String.Format("Name:{0} Age:{1}", myRegCfg.Name, myRegCfg.Age));
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
myRegCfg.Age = 37;
myRegCfg.Data = new byte[4];
myRegCfg.Data[0] = 12;
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
myRegCfg.Close();
其他使用方法请参见
一个用C#编写的自动读写配置文件的开源组件
源码位置
ConfigurePattern V1.1.1 源码
V1.1.1 版本增加一个配置模式 RegistryKeyPattern,用于帮助调用者自动读写注册表配置。另外该版本将
IConfigurationPattern 接口的parameter 参数类型有String改为Object,以便更加通用。
注册表配置的使用:
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockEnd.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
上述代码是一个注册表配置类的例子
在类级别需要声明ConfigurationPattern属性。
第一个参数指定模式类型为TPattern.REGISTRY即注册表配置模式。
第二个参数指定默认的HKey,可以不指定默认HKey。如果不指定默认HKey,则每个配置字段都必须用HKey 属性指定对应的HKey。
在字段级别需要
需要指定两个属性HKey和Subkey,其中HKey为可选,如果在类级别指定了默认HKey,字段级别的HKey可以不指定,除非该字段要访问
和默认HKey不同的HKey。
Subkey 属性有4个参数
path:指定键所在路径,该参数必须指定
name:指定键名,可选。如果不指定,键名默认和字段名相同
defaultValue:默认值,可选。
valueKind:键的类型,可选。
注册表配置类的调用示例。
见下面代码,调用方法和其他配置类的调用方法相同。
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
其他使用方法请参见
一个用C#编写的自动读写配置文件的开源组件
源码位置
ConfigurePattern V1.1.1 源码