Make internal classes accessible to all external assemblies

I’m implementing a modding interface for a game written in .net using Harmony. The original game code consists of mostly classes without specific access modifiers, which unfortunately defaults them to internal and makes modding kind of a pain. I have access to the original source code, so I can modify it however I want.

I’m aware of Friend Assemblies and the ignoreaccesschecksto modifier, but these options don’t really lend themselves well to a modding interface.

I believe the correct way to do this is to manually change all the classes to public. Is there a better way to do this/is this a bad idea?

>Solution :

Changing all the classes to public is one way to make the code more moddable by external assemblies. This will allow external assemblies to access the internal classes and methods, making it easier to create mods.

However, this approach has a couple of downsides:

  1. It will make the code less secure and less maintainable, since any external assembly will be able to access the internal classes and methods.
  2. It may also break the original game code if the internal classes and methods were not designed to be used by external assemblies.

An alternative approach would be to use an Interface-based design pattern, where you expose the necessary methods and properties through interfaces, and the internal classes implement those interfaces. This will give you more control over what is exposed to external assemblies, and it will make the code more maintainable and secure.

You can also create a wrapper class that contains all the methods that needs to be accessed by the mod and expose it as a public class. This will also give you more control over what is exposed to external assemblies, and it will make the code more maintainable and secure.

Leave a Reply