zoukankan      html  css  js  c++  java
  • ConfigurationPattern V1.1.1 版本发布该版本增加自动读写注册表配置的功能


    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;

    namespace CfgSample
    {
        [ConfigurationPattern(TPattern.REGISTRY, RegistryHive.CurrentUser)]
        
    class MyRegCfg : Configuration
        
    {
            String m_Name;

            [SubKey(
    @"software\test")]
            
    public String Name
            
    {
                
    get
                
    {
                    
    return m_Name;
                }


                
    set
                
    {
                    m_Name 
    = value;
                }

            }


            
    int m_Age = 0;
            [SubKey(
    @"software\test""Age"18, RegistryValueKind.DWord)]
            
    public int Age
            
    {
                
    get
                
    {
                    
    return m_Age;
                }


                
    set
                
    {
                    m_Age 
    = value;
                }

            }


            
    byte[] m_Data = null;
            [HKey(RegistryHive.CurrentUser)]
            [SubKey(
    @"software\test""Data")]
            
    public byte[] Data
            
    {
                
    get
                
    {
                    
    return m_Data;
                }


                
    set
                
    {
                    m_Data 
    = value;
                }

            }


        }

    }


    上述代码是一个注册表配置类的例子
    在类级别需要声明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();

                Console.WriteLine(String.Format(
    "Name:{0} Age:{1}", myRegCfg.Name, myRegCfg.Age));

                myRegCfg.Age 
    = 37;
                myRegCfg.Data 
    = new byte[4];
                myRegCfg.Data[
    0= 12;

                myRegCfg.Close();

    其他使用方法请参见
    一个用C#编写的自动读写配置文件的开源组件

    源码位置
    ConfigurePattern V1.1.1 源码

       



  • 相关阅读:
    java第19次
    Unity3D常用的生命周期函数
    Unity3D结合ZXing生成中间带图标的二维码并保存
    Unity查看当前内存使用情况(针对移动端开发)
    Unity 获取鼠标悬停位置下的UI或3D物体对象
    【Unity3D】获取鼠标在三维空间(世界坐标系)的位置
    【Unity3D—C#】按下任意按键,返回按键的名称 以及 KeyCode键码详解
    Unity UGUI获取鼠标在屏幕的准确点击位置
    ML-Agent:通过TF#使用训练完成的模型数据
    对《ml-agent:Win10下环境安装》更新
  • 原文地址:https://www.cnblogs.com/eaglet/p/1185140.html
Copyright © 2011-2022 走看看