Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/297.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 基于设置为注册表的设置值_C#_Visual Studio 2010 - Fatal编程技术网

C# 基于设置为注册表的设置值

C# 基于设置为注册表的设置值,c#,visual-studio-2010,C#,Visual Studio 2010,我的情况/问题的目标是将getValue的值设置为注册表中的目标。我不太熟悉get/sets,所以任何帮助都会很棒。如果你还需要我帮忙,请告诉我 namespace RegistrySetter { public class Ironman : CodeActivity { public InArgument<string> keypath { get; set; } public OutArgument<string> TextOut { get; s

我的情况/问题的目标是将getValue的值设置为注册表中的目标。我不太熟悉get/sets,所以任何帮助都会很棒。如果你还需要我帮忙,请告诉我

namespace RegistrySetter
{

public class Ironman : CodeActivity
{
    public InArgument<string> keypath { get; set; }
    public OutArgument<string> TextOut { get; set; }


    protected override void Execute(CodeActivityContext context)
    {
        string KeyPath = this.keypath.Get(context);

        context.SetValue<string>(this.TextOut, KeyPath);
    }

}

}
命名空间注册表设置程序
{
公开课铁人:CodeActivity
{
公共InArgument密钥路径{get;set;}
公共输出参数TextOut{get;set;}
受保护的覆盖无效执行(CodeActivityContext上下文)
{
字符串KeyPath=this.KeyPath.Get(上下文);
context.SetValue(this.TextOut,KeyPath);
}
}
}

要获取注册表值,您可能需要使用
registry.GetValue
。您只需要使用上下文来设置输出参数

例如:

using System;
using System.Activities;
using Microsoft.Win32;
using System.IO;

public class GetRegistryValue : CodeActivity
{
    [RequiredArgument]
    public InArgument<string> KeyPath { get; set; }
    public OutArgument<string> TextOut { get; set; }

    protected override void Execute(CodeActivityContext context)
    {
        string keyPath = this.KeyPath.Get(context);
        string keyName = Path.GetDirectoryName(keyPath);
        string valueName = Path.GetFileName(keyPath);
        object value = Registry.GetValue(keyName, valueName, "");
        context.SetValue(this.TextOut, value.ToString());
    }
}
使用系统;
使用系统活动;
使用Microsoft.Win32;
使用System.IO;
公共类GetRegistryValue:CodeActivity
{
[必需参数]
公共InArgument密钥路径{get;set;}
公共输出参数TextOut{get;set;}
受保护的覆盖无效执行(CodeActivityContext上下文)
{
字符串keyPath=this.keyPath.Get(上下文);
字符串keyName=Path.GetDirectoryName(keyPath);
字符串valueName=Path.GetFileName(keyPath);
对象值=Registry.GetValue(keyName,valueName,“”);
context.SetValue(this.TextOut,value.ToString());
}
}
这里的KeyPath类似于:
HKEY\u CURRENT\u USER\Software\7-Zip\Path
其中
Path
实际上是值名,
HKEY\u CURRENT\u USER\Software\7-Zip
是键名。
如果要设置注册表值,请查看
registry.SetValue

一个提示,不要将类命名为与命名空间相同的名称,例如
Ironman
我很难理解您真正要求的内容,但属性实际上非常简单。。。要从中获取值,只需执行
string KeyPath=this.KeyPath
。。。要设置属性,您只需执行
this.TextOut=“output,yo!”
…当使用Registry.SetValue时,我正在努力弄清楚这里的value参数的对象是什么
string keyPath=this.keyPath.set(context,?)@Brandon我不明白这个问题。任何setter方法的“value”参数都是要放入某个存储位置的值。而且,大多数情况下setter方法不会返回任何东西。当我认为创建注册表项需要setter方法时。这不对吗?我可以在getter中执行此操作吗?@Brandon您想向注册表写入值还是从注册表读取值?如果您想写一个值,那么
TextOut
的作用是什么?我想用一个活动(我假设的Get方法)读取一个值。我希望能够写入的另一个活动(我假设的Set方法)。