mirror of
https://github.com/fadden/6502bench.git
synced 2025-03-04 06:29:56 +00:00
Add VisParamDescr default value type check
The VisParamDescrs specify a type and a default value. If the value has the wrong type, things would blow up in the editor. We now check the type at plugin load time, and refuse to load the plugin at all if an entry has a bad type.
This commit is contained in:
parent
b5deea713f
commit
a0735826fb
@ -259,6 +259,10 @@ namespace PluginCommon {
|
||||
/// </summary>
|
||||
public VisParamDescr(string uiLabel, string name, Type csType, object min, object max,
|
||||
SpecialMode special, object defVal) {
|
||||
if (defVal.GetType() != csType) {
|
||||
throw new ArgumentException("Mismatch between type and default value in \"" +
|
||||
name + "\"");
|
||||
}
|
||||
UiLabel = uiLabel;
|
||||
Name = name;
|
||||
CsType = csType;
|
||||
|
@ -86,9 +86,10 @@ namespace PluginCommon {
|
||||
/// <param name="dllPath">Full path to compiled assembly.</param>
|
||||
/// <param name="scriptIdent">Identifier to use in e.g. GetPlugin().</param>
|
||||
/// <returns>Reference to plugin instance.</returns>
|
||||
public IPlugin LoadPlugin(string dllPath, string scriptIdent) {
|
||||
public IPlugin LoadPlugin(string dllPath, string scriptIdent, out string failMsg) {
|
||||
if (mActivePlugins.TryGetValue(dllPath, out IPlugin ip)) {
|
||||
Debug.WriteLine("PM: returning cached plugin for " + dllPath);
|
||||
failMsg = string.Empty;
|
||||
return ip;
|
||||
}
|
||||
|
||||
@ -100,9 +101,22 @@ namespace PluginCommon {
|
||||
type.GetInterfaces().Contains(typeof(IPlugin))) {
|
||||
|
||||
ConstructorInfo ctor = type.GetConstructor(Type.EmptyTypes);
|
||||
IPlugin iplugin = (IPlugin)ctor.Invoke(null);
|
||||
IPlugin iplugin;
|
||||
try {
|
||||
iplugin = (IPlugin)ctor.Invoke(null);
|
||||
} catch (Exception ex) {
|
||||
if (ex.InnerException != null) {
|
||||
failMsg = ex.InnerException.Message;
|
||||
} else {
|
||||
failMsg = ex.Message;
|
||||
}
|
||||
Debug.WriteLine("LoadPlugin: failed to load '" + scriptIdent + "': "
|
||||
+ failMsg);
|
||||
return null;
|
||||
}
|
||||
Debug.WriteLine("PM created instance: " + iplugin);
|
||||
mActivePlugins.Add(scriptIdent, iplugin);
|
||||
failMsg = string.Empty;
|
||||
return iplugin;
|
||||
}
|
||||
}
|
||||
|
@ -118,7 +118,11 @@ namespace SourceGen.Sandbox {
|
||||
report = new FileLoadReport(dllPath); // empty report
|
||||
return true;
|
||||
} else {
|
||||
IPlugin plugin = DomainMgr.PluginMgr.LoadPlugin(dllPath, scriptIdent);
|
||||
IPlugin plugin = DomainMgr.PluginMgr.LoadPlugin(dllPath, scriptIdent,
|
||||
out string failMsg);
|
||||
if (plugin == null) {
|
||||
report.Add(FileLoadItem.Type.Error, "Failed loading plugin: " + failMsg);
|
||||
}
|
||||
return plugin != null;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user