BPW developer
BPW developer

Reputation: 21

How to load stored DATA in a DLL dynamically

C# : Hey i'm making an engine as an addon for a flight simulator my engine needs some data to do its work and those data i want to store them away from people text editors so i want just to make a DLL in my DLL classes with some datas like strings lists ints .... and lot of datas now i want my enegine to load those data dynamically, that means i won't be including those DLLs before the compile cus i want my engine to load many DLLs using the Foreach. i took a look at assembly load and system.reflection, but i can't get my code to work and load the variables and methods

note: all DLLs i want to load has same vars names and methods names but the data stored is diffrent hope you help me with this thnx in advance :D

Upvotes: 0

Views: 327

Answers (1)

Ryan Schlueter
Ryan Schlueter

Reputation: 2221

This is just a quick proof of concept let me know if need more to get you started. For our production use of this we had each library share a common interface for the classes we wanted to pull.

My Library

namespace Library
{
  public class MyVariables
    {
        public string TestProp { get => "Result"; }
    }
}

Calling Code

 Assembly assembly = Assembly.LoadFrom("Path");
 var results = assembly.GetTypes();
 Type type = assembly.GetType("Library.MyVariables");
 dynamic instanceOfMyType = Activator.CreateInstance(type);
 Console.Write(instanceOfMyType.TestProp);

Upvotes: 1

Related Questions