Page 1 of 1

Get Plugin from custom form

PostPosted: Fri Mar 11, 2022 1:32 pm
by SBarnes
Is there a way to get the plugin object that a custom form is residing in?

Re: Get Plugin from custom form

PostPosted: Fri Mar 11, 2022 1:48 pm
by Mike.Sheen
You can get the name of the plugin with Assembly.GetExecutingAssembly and then match the assembly name with the plugin name in Manager.PluginCollection - the item in Manager.PluginCollection is the plugin.

Re: Get Plugin from custom form  Topic is solved

PostPosted: Fri Mar 11, 2022 2:00 pm
by SBarnes
Thanks, based on that suggestion this should do it as a function in the form

Code: Select all
      private JiwaFinancials.Jiwa.JiwaApplication.Plugin.Plugin GetPlugin()
      {
         List<JiwaFinancials.Jiwa.JiwaApplication.Plugin.Plugin> plugins = this.Manager.PluginCollection.Cast<JiwaFinancials.Jiwa.JiwaApplication.Plugin.Plugin>().ToList();
         return plugins.FirstOrDefault( p => p.Name == System.Reflection.Assembly.GetExecutingAssembly().GetName().FullName );
         
      }

Re: Get Plugin from custom form

PostPosted: Thu Mar 07, 2024 3:53 pm
by Mike.Sheen
SBarnes wrote:Thanks, based on that suggestion this should do it as a function in the form

Code: Select all
      private JiwaFinancials.Jiwa.JiwaApplication.Plugin.Plugin GetPlugin()
      {
         List<JiwaFinancials.Jiwa.JiwaApplication.Plugin.Plugin> plugins = this.Manager.PluginCollection.Cast<JiwaFinancials.Jiwa.JiwaApplication.Plugin.Plugin>().ToList();
         return plugins.FirstOrDefault( p => p.Name == System.Reflection.Assembly.GetExecutingAssembly().GetName().FullName );
         
      }


That doesn't work because you're comparing the Assembly FullName with the Plugin Name - the FullName includes the SNK and version - you just want Name.

Code: Select all
private JiwaFinancials.Jiwa.JiwaApplication.Plugin.Plugin GetPlugin()
{
   List<JiwaFinancials.Jiwa.JiwaApplication.Plugin.Plugin> plugins = this.Manager.PluginCollection.Cast<JiwaFinancials.Jiwa.JiwaApplication.Plugin.Plugin>().ToList();
   return plugins.FirstOrDefault(p => p.Name == System.Reflection.Assembly.GetExecutingAssembly().GetName().Name);
}