示例#1
0
        static void FromInterface()
        {
            var type = typeof(IExport);

            Assembly assembly = Assembly.LoadFile(@"C:\Users\folmos\Documents\Visual Studio 2017\Projects\ConsoleApp\CSVExport\bin\Debug\netcoreapp2.1\CSVExport.dll");
            var      founded  = assembly.GetTypes().FirstOrDefault(p => type.IsAssignableFrom(p));

            object       exportInstance = Activator.CreateInstance(founded);
            PropertyInfo prop           = founded.GetProperty("Author");

            prop.SetValue(exportInstance, "Manuel", null);



            // O también podemos crearlo pasandole parámetros
            object exportInstance2 = Activator.CreateInstance(founded, new object[] { "Juan" });

            IExport csvExport = exportInstance as IExport;

            // Lo mostramos
            Console.WriteLine(exportInstance.ToString());
            Console.WriteLine(exportInstance2.ToString());

            csvExport.CreateFile("csv_file");
        }