小编Dje*_*sen的帖子

从命令行使用devenv.exe并打开解决方案

当我按F5时,我已将VSIX-Project配置为运行devenv.exe.这将从Visual Studio打开起始页.为了测试我的扩展,我必须手动打开一个特定的解决方案.

我尝试使用参数'/ Run PathToSolution.sln'运行devenv,这将使用指定的解决方案启动VS,但也运行启动项目.有没有办法运行devenv并打开一个特定的解决方案?

x86 devenv anycpu vsix visual-studio-2017

2
推荐指数
1
解决办法
3603
查看次数

带有ref/Pointer参数的C#反射调用方法

我想用反射调用类的每个方法但我不能用指针调用方法作为参考.通常我只能为我找到的每个指针传递null,一切都会好的.问题是当函数试图访问我传递的指针时.指针将是对内存地址0的引用,这显然是我程序的即时崩溃.所以我需要将指针传递给有效的内存地址,但我不知道如何在运行时创建指针

我的代码的压缩版本:

class Program
{
    static void Main(string[] args)
    {
        var obj = new TestClass();
        var pointerMethod = obj.GetType().GetMethod("Test");
        var referenceMethod = obj.GetType().GetMethod("Test2");

        var pointerParameter = pointerMethod.GetParameters()[0];
        var referenceParameter = referenceMethod.GetParameters()[0];

        //Get the instance of the class that is referred by the pointer/reference
        var pointerInstance = Activator.CreateInstance(pointerParameter.ParameterType.GetElementType());
        var referenceInstance = Activator.CreateInstance(referenceParameter.ParameterType.GetElementType());

        //Call the method and "cast" the char instance into an pointer
        pointerMethod.Invoke(obj, new[] {pointerInstance.GetType().MakePointerType()});
        referenceMethod.Invoke(obj, new[] { referenceInstance.GetType().MakeByRefType() });
     }
}
Run Code Online (Sandbox Code Playgroud)

和TestClass:

public class TestClass
{
        unsafe public void …
Run Code Online (Sandbox Code Playgroud)

c# reflection pointers ref

1
推荐指数
1
解决办法
2414
查看次数

标签 统计

anycpu ×1

c# ×1

devenv ×1

pointers ×1

ref ×1

reflection ×1

visual-studio-2017 ×1

vsix ×1

x86 ×1