C # 추가 기능 : 디버깅하는 동안 객체의 런타임 인스턴스에 어떻게 액세스합니까?

StackOverflow https://stackoverflow.com/questions/5493325

문제

디버깅 중에 만 사용할 수있는 C #에 대한 추가 기능을 개발 중입니다.인스턴스화되면 추가 클래스 또는 인터페이스의 모든 인스턴스를 찾아 발견되어 발견 된 데이터에 대한 그래프를 표시해야합니다.

이러한 확장자에서 이러한 개체를 정확히 찾거나 액세스 할 수 있습니까?내 확장명에서 DTE2 응용 프로그램 개체에 액세스 할 수 있지만 VS에서 디버깅중인 실제 코드를 검색하는 방법을 모르겠습니다.나는 어떻게 든 반성을 사용할 수있을 것으로 생각하고 있지만, 나는 어디에서 볼지 모르겠다.

감사합니다.

도움이 되었습니까?

해결책

I've implemented a plugin that searches through dlls in a given directory and finds classes that implement a particular interface. Below is the class I used to do this:

public class PlugInFactory<T>
{
    public T CreatePlugin(string path)
    {
        foreach (string file in Directory.GetFiles(path, "*.dll"))
        {
            foreach (Type assemblyType in Assembly.LoadFrom(file).GetTypes())
            {
                Type interfaceType = assemblyType.GetInterface(typeof(T).FullName);

                if (interfaceType != null)
                {
                    return (T)Activator.CreateInstance(assemblyType);
                }
            }
        }

        return default(T);
    }
}

All you have to do is initialize this class with something like this:

PluginLoader loader = new PlugInFactory<InterfaceToSearchFor>();
InterfaceToSearchFor instanceOfInterface = loader.CreatePlugin(AppDomain.CurrentDomain.BaseDirectory);

다른 팁

This type of operation isn't really possible from a Visual Studio plugin. The object alive when debugging live in the debugee process while your add-in is running in the Visual Studio process. It's not possible to access arbitrary objects across process boundaries in .Net.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top