-
Автор темы
- #1
C#:
using Microsoft.Win32;
using System.Dynamic;
using System.Runtime.Versioning;
namespace RegDynamic;
[SupportedOSPlatform("windows")]
public class RegistryDynamic : DynamicObject
{
private readonly RegistryKey _registryKey;
public RegistryDynamic(RegistryKey registryKey)
{
_registryKey = registryKey;
}
public override bool TryGetMember(GetMemberBinder binder, out object? result)
{
result = _registryKey.GetValue(binder?.Name, null);
return result != null;
}
public override bool TrySetMember(SetMemberBinder binder, object? value)
{
_registryKey.SetValue(binder?.Name, value!);
return true;
}
}
[SupportedOSPlatform("windows")]
class Program
{
static void Main(string[] args)
{
using var key = Registry.CurrentUser.OpenSubKey(@"SOFTWARE\Qt\Qt Apps");
dynamic registry = new RegistryDynamic(key!);
Console.WriteLine(registry.uuid); // Получение значения.
registry.uuid = "my value"; // Изменение значения
}
}