Visual C++ .NET/Reflection/Assembly — различия между версиями
Admin (обсуждение | вклад) м (1 версия) |
|
(нет различий)
|
Версия 15:31, 26 мая 2010
Get type from Assembly
#include "stdafx.h"
using namespace System;
using namespace System::Reflection;
ref class Reflector
{
public:
void TestDynamicCall(String^ greeting)
{
Console::WriteLine(greeting);
}
};
void LoadAndReflect(String^ assemblyFileName, String^ typeName,String^ methodName, array<Object^>^ parameterList)
{
Assembly^ assembly = Assembly::LoadFrom(assemblyFileName);
Type^ t= assembly->GetType(typeName);
MethodInfo^ method = t->GetMethod(methodName);
Object^ obj = Activator::CreateInstance(t);
method->Invoke(obj, parameterList);
}
int main()
{
array<Object^>^ params = gcnew array<Object^> { "Hello!" };
LoadAndReflect("reflection2.exe", "Reflector", "TestDynamicCall", params);
}
Load Assembly from exe file
#include "stdafx.h"
using namespace System;
using namespace System::Reflection;
ref class Reflector
{
public:
void TestDynamicCall(String^ greeting)
{
Console::WriteLine(greeting);
}
};
void LoadAndReflect(String^ assemblyFileName, String^ typeName,String^ methodName, array<Object^>^ parameterList)
{
Assembly^ assembly = Assembly::LoadFrom(assemblyFileName);
Type^ t= assembly->GetType(typeName);
MethodInfo^ method = t->GetMethod(methodName);
Object^ obj = Activator::CreateInstance(t);
method->Invoke(obj, parameterList);
}
int main()
{
array<Object^>^ params = gcnew array<Object^> { "Hello!" };
LoadAndReflect("reflection2.exe", "Reflector", "TestDynamicCall", params);
}