Recommended Practices and Pitfalls - coloursofnoise/Resources GitHub Wiki
These are some code features and techniques that may seem useful for code mods, but that can cause various issues if used (usually related to cross-platform compatibility).
The readonly
modifier can be added to struct
definitions to mark them as immutable.
This crashes on MacOS for unknown reasons.
Marking individual members of a struct
as readonly
is fine however.
This is a hacky way to call a "base base method", for use in override
methods where skipping the direct base.
method call is desired. (f.e. when inheriting from a vanilla class).
This crashes on MacOS for unknown reasons.
The recommended practice is to make use of the MonoModLinkTo
attribute as shown here
The dynamic
type can be used to bypass static type checking, which is useful for accessing private types and members.
This crashes on unix because it is not supported by mono
Use DynamicData
or Reflection instead.
DynamicData
on struct
with getters
Creating a DynamicData
instance with a struct containing getters/properties will throw a System.InvalidProgramException
on mono, this might be a MonoMod bug.
Before it gets fixed, you need to use reflections to access the members.
Just Don't Use Them™
The tuple deconstruction syntax (int a, int b) = (1, 2);
, including when used to deconstruct tuples of values in loops, crashes on mono.
Instead, retrieve the tuple's members individually.