// The extra settings are assumed to be "old style", so we apply the semi-colon hack to them. public static string CombineSettings(string[] settings, string[] extraSettings = null) { if (Utils.Size(extraSettings) == 0) { return(CmdParser.CombineSettings(settings)); } if (Utils.Size(settings) == 0) { return(CmdParser.CombineSettings(SplitOnSemis(extraSettings))); } return(CmdParser.CombineSettings(settings) + " " + CmdParser.CombineSettings(SplitOnSemis(extraSettings))); }
/// <summary> /// Create an instance of the indicated component with the given extra parameters. /// </summary> public static TRes CreateInstance <TRes, TSig>(IHostEnvironment env, SubComponent comp, params object[] extra) where TRes : class { string options = CmdParser.CombineSettings(comp.Settings); TRes result; if (TryCreateInstance <TRes, TSig>(env, out result, comp.Kind, options, extra)) { return(result); } throw Contracts.Except("Unknown loadable class: {0}", comp.Kind).MarkSensitive(MessageSensitivity.None); }
public override string ToString() { if (IsEmpty) { return("{}"); } if (_settings.Length == 0) { return(_kind); } string str = CmdParser.CombineSettings(_settings); StringBuilder sb = new StringBuilder(); CmdQuoter.QuoteValue(str, sb, true); return(_kind + sb.ToString()); }
public void ArgumentParseTest() { var env = new TlcEnvironment(seed: 42); var innerArg1 = new SimpleArg() { required = -2, text1 = "}", text2 = "{", text3 = " ", text4 = "\n", }; var innerArg2 = new SimpleArg() { required = -2, text1 = "{!@# $%^}&*{()}", text2 = "=", text3 = "\t", text4 = @"\\", }; var innerArg3 = new SimpleArg() { required = -2, text1 = "\r\n", text2 = "\"", text3 = "\" \" ", text4 = "{/a=2 /b=3 /c=4}", sub1 = new SubComponent("S1", innerArg1.ToString(env)), sub2 = new SubComponent("S2", innerArg2.ToString(env)), }; var outerArg1 = new SimpleArg() { required = -2, once = 2, text2 = "Testing", text3 = "a=7", sub1 = new SubComponent("S1", innerArg1.ToString(env)), sub2 = new SubComponent("S2", innerArg2.ToString(env)), sub3 = new SubComponent("S3", innerArg3.ToString(env)), }; var testArg = new SimpleArg(); CmdParser.ParseArguments(env, outerArg1.ToString(env), testArg); Assert.Equal(innerArg1, testArg); CmdParser.ParseArguments(env, outerArg1.sub1.SubComponentSettings, testArg = new SimpleArg()); Assert.Equal(innerArg1, testArg); CmdParser.ParseArguments(env, outerArg1.sub1.Settings[0], testArg = new SimpleArg()); Assert.Equal(innerArg1, testArg); CmdParser.ParseArguments(env, CmdParser.CombineSettings(outerArg1.sub1.Settings), testArg = new SimpleArg()); Assert.Equal(innerArg1, testArg); CmdParser.ParseArguments(env, outerArg1.sub2.SubComponentSettings, testArg = new SimpleArg()); Assert.Equal(innerArg2, testArg); CmdParser.ParseArguments(env, outerArg1.sub3.SubComponentSettings, testArg = new SimpleArg()); Assert.Equal(innerArg3, testArg); }