Type check wont work properly
-
Alright, im working on a Plugin script in my application. Every plugin got saved in a seperated Dll with a main class: public ref class Plugin : public PluginInterface::IPlugin IPlugin is a abstract class with some basic info like Name, Date, Descryption and a few virtual methods, Initialize and so on. Now my load function:
void cPlugins::AddPlugin(System::String ^FileName) { Assembly^ PluginAssembly = Assembly::LoadFrom(FileName); for each (Type^ PluginType in PluginAssembly->GetTypes()){ if (PluginType->IsPublic){ if (!PluginType->IsAbstract){ Types::AvailablePlugin^ NewPlugin = gcnew Types::AvailablePlugin(); NewPlugin->Instance = dynamic_cast(Activator::CreateInstance(PluginAssembly->GetType(PluginType->ToString()))); if ((NewPlugin != nullptr)&&(NewPlugin->Instance!=nullptr)){ NewPlugin->AssemblyPath = FileName; NewPlugin->Instance->Host = this; NewPlugin->Instance->Initialize(); if (!this->AvailPlugins) this->AvailPlugins = gcnew Types::AvailablePlugins(); this->AvailPlugins->Add(NewPlugin); } } } } }
or at least, code above is something like that. i tried to many different things. The definition of AvailablePlugin is like this,public ref class AvailablePlugin { public: IPlugin^ Instance; String^ AssemblyPath; };
Now, for some or other reason, He wont give me a valid class. << Means, that the when i do a typecheck, he just says its a total different type. dynamic_cast(Activator::CreateInstance(***)) wont agree with it. How can i make this work? can anyone help? Thanks already -
Alright, im working on a Plugin script in my application. Every plugin got saved in a seperated Dll with a main class: public ref class Plugin : public PluginInterface::IPlugin IPlugin is a abstract class with some basic info like Name, Date, Descryption and a few virtual methods, Initialize and so on. Now my load function:
void cPlugins::AddPlugin(System::String ^FileName) { Assembly^ PluginAssembly = Assembly::LoadFrom(FileName); for each (Type^ PluginType in PluginAssembly->GetTypes()){ if (PluginType->IsPublic){ if (!PluginType->IsAbstract){ Types::AvailablePlugin^ NewPlugin = gcnew Types::AvailablePlugin(); NewPlugin->Instance = dynamic_cast(Activator::CreateInstance(PluginAssembly->GetType(PluginType->ToString()))); if ((NewPlugin != nullptr)&&(NewPlugin->Instance!=nullptr)){ NewPlugin->AssemblyPath = FileName; NewPlugin->Instance->Host = this; NewPlugin->Instance->Initialize(); if (!this->AvailPlugins) this->AvailPlugins = gcnew Types::AvailablePlugins(); this->AvailPlugins->Add(NewPlugin); } } } } }
or at least, code above is something like that. i tried to many different things. The definition of AvailablePlugin is like this,public ref class AvailablePlugin { public: IPlugin^ Instance; String^ AssemblyPath; };
Now, for some or other reason, He wont give me a valid class. << Means, that the when i do a typecheck, he just says its a total different type. dynamic_cast(Activator::CreateInstance(***)) wont agree with it. How can i make this work? can anyone help? Thanks alreadyIs this line correct? NewPlugin->Instance = dynamic_cast(Activator::CreateInstance(PluginAssembly->GetType(PluginType->ToString()))); I can't see the type your are casting to? Probably a typo in your post. Wasn't it dynamic_cast < type-id > ( expression ) I guess you are using , don't you?
-
Is this line correct? NewPlugin->Instance = dynamic_cast(Activator::CreateInstance(PluginAssembly->GetType(PluginType->ToString()))); I can't see the type your are casting to? Probably a typo in your post. Wasn't it dynamic_cast < type-id > ( expression ) I guess you are using , don't you?