Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading