Fixes cnext injection on inherited properties.
Created by: roridev
Summary
Allow CommandsNextUtilities.CreateInstance to inject into inherited properties.
Details
Currently cnext doesn't properly handle injection into inherited properties.
This PR fixes it by changing TypeInfo.DeclaredProperties
/ TypeInfo.DeclaredFields
to Type.GetRuntimeProperties
/ Type.GetRuntimeFields
since Type.GetRuntime*
correctly handle inheritance, while TypeInfo.Declared*
doesn't.
Changes proposed
As it currently stands the following field when accessed by a command through its superclass will result on a null
value.
public abstract class CustomCommandModule : BaseCommandModule {
public BotConfig Config;
// Config gets injected and its usable here, but due to the use case its not what you'd want.
}
public class ACommand : CustomCommandModule {
// Here Config is null, because BotConfig Config is inherited rather than declared here.
// With this fix, `Config` becomes usable here.
}
This can be used, for example, passing local custom data to many groups without code duplication.