this post was submitted on 25 Mar 2024
538 points (98.6% liked)

Programmer Humor

19589 readers
775 users here now

Welcome to Programmer Humor!

This is a place where you can post jokes, memes, humor, etc. related to programming!

For sharing awful code theres also Programming Horror.

Rules

founded 1 year ago
MODERATORS
 
you are viewing a single comment's thread
view the rest of the comments
[–] RonSijm@programming.dev 4 points 7 months ago

You'd probably use a different approach for that. Like you'd make your program dynamically load all the .dlls in a "plugins" folder -

Then you'd provide some plugin interface for the users to create plugins, for example:

public interface IImageEditorPlugin
{
    public void BeforeImageEdit(int[,] imageData);
    public void AfterImageEdit(int[,] imageData);
}

And then you can load plugin classes from all the dlls with dependency injection, and execute them though something like this:

public class ImageEditor(IEnumerable<IImageEditorPlugin> plugins)
{
    public void EditImage(int[,] imageData)
    {
        foreach (var imageEditorPlugin in plugins)
        {
            imageEditorPlugin.BeforeImageEdit(imageData);
            // Do internal image edit function
            imageEditorPlugin.AfterImageEdit(imageData);
        }
    }
}

This is a very simple example obviously, normally you'd send more meta-data to the plugins, or have multiple different interfaces depending on the kinda plugin it is, or have some methods to ask plugins when they're suitable to be used. But this way a user can provide compiled versions of their plugins (in the same language as the core application) - instead of having to provide something like lua scripts