Salve gibra, sto testando il tuo sistema in C# ma ho dei problemi che proprio non capisco.
Premessa, la mia DLL non contiene form, è una DLL con semplici metodi.
Ho creato una soluzione con tre progetti, TestModulare che sarebbe il lanciatore, Attributi che è come il tuo ProgramsAttribute e infine Plugin che è come il tuo Form1.
In sostanza alla chiamata chiave Attribute[] atr = (Attribute[])t.GetCustomAttributes(typeof(Attributi), true); (l'equivalente del tuo Dim atr() As Attribute = t.GetCustomAttributes(GetType(ProgramsAttribute), True)) quando nel ciclo sta analizzando Plugin.dll non produce un array di attributi...
Posto il codice così puoi controllare.
TestModulare:
codice:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;
using AttributiGroup;
using System.Collections;
namespace TestModulare
{
class Test
{
private ArrayList al=new ArrayList();
static void Main(string[] args)
{
Test test = new Test();
}
public Test()
{
string sDir = @"D:\TEMP\plugin";
foreach (string s in System.IO.Directory.GetFiles(sDir))
CaricaAssembly(s);
}
private void CaricaAssembly(string pAssemblyName)
{
if (System.IO.File.Exists(pAssemblyName))
{
try
{
Assembly asmb = Assembly.LoadFrom(pAssemblyName);
foreach (Type t in asmb.GetTypes())
{
Console.WriteLine("Namespace" + t.Namespace + " Name: " + t.Name + " GetName: " + asmb.GetName() + " BaseType: " + t.BaseType.ToString());
Attribute[] atr = (Attribute[])t.GetCustomAttributes(typeof(Attributi), true);
if (atr.Length != 0)
{
Attributi at = (Attributi)atr[0];
al.Add(at);
}
}
}
catch (Exception ex)
{
Console.WriteLine("Impossibile caricare " + pAssemblyName + Environment.NewLine + ex.Message + Environment.NewLine + ex.StackTrace);
}
}
}
}
}
Attributi:
codice:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace AttributiGroup
{
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct, AllowMultiple = true)]
public class Attributi : Attribute
{
private string mGruppo;
private string mModulo;
private string mDescrizione;
public Attributi(string pGruppo, string pModulo, string pDescrizione)
{
Gruppo = pGruppo;
Descrizione = pDescrizione;
Modulo = pModulo;
}
private Attributi() { }
public string Gruppo
{
get { return mGruppo; }
set { mGruppo = value; }
}
public string Modulo
{
get { return mModulo; }
set { mModulo = value; }
}
public string Descrizione
{
get { return mDescrizione; }
set { mDescrizione = value; }
}
}
}
Plugin:
codice:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using AttributiGroup;
namespace Plugins
{
[Attributi("Gruppo1", "Prima Form", "Descrizione Prima Form")]
public class Plugin
{
public Plugin()
{
Console.WriteLine("Si dai");
}
public Plugin(string Str)
{
Console.WriteLine(Str);
}
}
}