/// <summary> /// Applies arguments to a <see cref="ParameterizedConfig"/>. This <see cref="ParameterizedConfig"/> is expected to have come from a <see cref="ConfigReference"/>. This same <see cref="ConfigReference"/> is expected to be the source of <paramref name="args"/>. /// </summary> /// <param name="config"></param> /// <param name="args"></param> /// <param name="parentChoiceName">If non-null, this will traverse into a parameter with this name (which is presumably a Choice) and access the choice's directs to apply the args.</param> public static void ApplyArguments(this ParameterizedConfig config, ArgumentMap args, string parentChoiceName = null) { object[] keys = args.keySet().toArray(); foreach (object key in keys) { if (key is string strKey) { //object impl = ReflectionHelper.Get(config, "implementation"); // TODO: Is this OK to use? if (parentChoiceName != null) { if (config.getParameter(parentChoiceName) is Parameter.Choice choice) { foreach (Parameter.Direct choiceDirect in choice.directs) { if (choiceDirect.name == strKey) { WrappedDirect.SetDataOn(config, choiceDirect.paths, args.get(key)); } } } } else { Parameter param = config.getParameter(strKey); if (param is Parameter.Direct direct) { WrappedDirect.SetDataOn(config, direct.paths, args.get(key)); } } } } }
/// <summary> /// Creates a new <see cref="ConfigReference"/> pointing to the given <see cref="ParameterizedConfig"/> and automatically populates the <see cref="ConfigReference"/>'s arguments with the data defined by the <see cref="ParameterizedConfig"/>. /// </summary> /// <param name="cfg"></param> /// <returns></returns> public static ConfigReference MakeConfigReferenceTo(ParameterizedConfig cfg) { ArgumentMap args = new ArgumentMap(); foreach (Parameter param in cfg.parameters) { if (param is Parameter.Direct direct) { WrappedDirect wDir = new WrappedDirect(cfg, direct); args.put(param.name, wDir.GetValue()); } } return(NewConfigReference(cfg.getName(), args)); }