Skip to content
QQ edited this page Sep 30, 2022 · 23 revisions

Welcome to the QSoft.Registry wiki!

Introduction

  • Support Queryable function
  • Auto control Registry resource no control resource create and dispose
  • Support Update and Remove RegistryKey

Quick Start

//define want to get data
public class InstalledApp
{
    public string DisplayName { set; get; }
    [RegPropertyName(Name = "DisplayVersion")]
    public Version Version { set; get; }
    public int? EstimatedSize { set; get; }
}

//create convert
public class Version2String : RegQueryConvert<Version>
{
    public override string ConvertTo(Version src)
    {
        return src.ToString();
    }

    public override Version ConvertBack(string dst)
    {
        Version version;
        Version.TryParse(dst, out version);
        return version;
    }
}

//create registrykey query
var regt1 = new RegQuery<InstalledApp>()
      .useSetting(x =>
      {
          x.Hive = RegistryHive.LocalMachine;
          x.SubKey = @"SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall";
          x.View = RegistryView.Registry64;
      })
      .useConverts(x=>
      {
            x.Add(new Version2String());
      });

//get dispalyname contains Windows
var where = regt.Where(x => x.DisplayName.Contains("Windows"));

//filter version
var where_version = regt.Where(x => x.Version > new Version(1, 1, 1, 1));

Attributes

this is ORM for ReigistryKey, if you want to resuse exist class to query add attribute is good choice

RegPropertyName

Use attribute change property

public class InstalledApp
{
    public string DisplayName { set; get; }
    [RegPropertyName(Name = "DisplayVersion")]
    public Version Version { set; get; }
    public int? EstimatedSize { set; get; }
}
//Version change to DisplayVersion

RegIgnore

Use attribute ignore exist property

public class InstalledApp
{
    public string DisplayName { set; get; }
    public Version Version { set; get; }
    [RegIgnore]
    public int? EstimatedSize { set; get; }
}

RegSubKeyName

Use attribute read write key name

public class InstalledApp
{
    [RegSubKeyName]
    public string Key{ set; get; }
    public string DisplayName { set; get; }
    public Version Version { set; get; }
    public int? EstimatedSize { set; get; }
}

The attribute is bit complicated
recommand use attribute of property is string type
Least prone to casting mistakes

Insert data mode must be assigned value to Key
beside type is string and no assign value , Key can auto generate guid

Clone this wiki locally