private void ReadIfPropertySetter(string l) { string p = "^\\# @(.+?) (.*)$"; if (Regex.IsMatch(l, p)) { Match m = new Regex(p, RegexOptions.IgnoreCase | RegexOptions.Singleline) .Matches(l)[0]; string name = m.Groups[1].Value; string val = (m.Groups.Count > 2)? m.Groups[2].Value.Trim() : null; if (val == null) { return; } var prop = this.GetType() .GetProperty(AISStringUtil.KebabToPascal(name)); if (null != prop) { prop.SetValue(this, val); } } }
public int Exec(string[] args) { int result = 0; svc.LoadOrCreateConfig(); svc.RestoreOrCreateDB(); if (args.Length > 0) { MethodInfo method = ifs.GetType() .GetMethod(AISStringUtil.KebabToPascal(args[0])); if (null != method) { try { result = (int)method.Invoke(ifs, new Object[] { args }); } catch (Exception e) { Console.WriteLine(e); } } else { Console.WriteLine("ERROR : Command not found!"); ifs.Help(args); } } else { ifs.Help(args); } svc.DumpDB(); return(result); }
public string GetDescriptor(bool withUsage) { string properties = "###" + AIS.NEWLINE + this.GetType() .GetProperties() .Where(p => null != Attribute.GetCustomAttribute(p, typeof(EditableProperty))) .Aggregate("", (m, e) => m + String.Format("# @{0} {1}{2}", AISStringUtil.PascalToKebab(e.Name), (string)e.GetValue(this), AIS.NEWLINE)) + "###" + AIS.NEWLINE; string usage = String.Format( "### Task descriptor format{0}" + "### #<id> <status> <name>{0}" + "### {0}" + "### <description>{0}" + "### <description>{0}", AIS.NEWLINE); return(String.Format( "#{1} {2} {3}{0}" + "{0}" + "{6}" + "{4}{0}" + "{5}", AIS.NEWLINE, Id, Task.StatusCodeToName(Status), Name, Desc, (withUsage)? usage : "", properties)); }