Visual C++ .NET/Reflection/Assembly — различия между версиями

Материал из .Net Framework эксперт
Перейти к: навигация, поиск
м (1 версия)
 
(нет различий)

Текущая версия на 12:05, 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);
}