/// <summary> /// Add a variable /// </summary> /// <param name="key">key name</param> /// <param name="obj">object value</param> public void AddVariable(string key, PrinterVariable obj) { if (this.Variables.ContainsKey(key)) { this.Variables[key] = obj.Clone() as PrinterVariable; } else { this.Variables.Add(key, obj.Clone() as PrinterVariable); } }
/// <summary> /// Add a variable /// </summary> /// <param name="key">key name</param> /// <param name="obj">object value</param> public void AddVariable(string key, PrinterVariable obj) { if (this.ExistTestVariable(key)) { this.IncludedVariables[key] = obj.Clone() as PrinterVariable; } else { this.IncludedVariables.Add(key, obj.Clone() as PrinterVariable); } }
/// <summary> /// Edit a variable /// </summary> /// <param name="key">key name</param> /// <param name="obj">object value</param> public void EditVariable(string key, PrinterVariable obj) { if (this.ExistTestVariable(key)) { this.IncludedVariables[key] = obj; } else { this.IncludedVariables.Add(key, obj); } }
/// <summary> /// Add a variable /// </summary> /// <param name="key">key name</param> /// <param name="val">string value</param> public void AddVariable(string key, string val) { if (this.Variables.ContainsKey(key)) { this.Variables[key].Value = val; } else { PrinterVariable p = new PrinterVariable(); p.Name = key; p.Value = val; this.Variables.Add(key, p); } }
/// <summary> /// Add a variable /// </summary> /// <param name="key">key name</param> /// <param name="val">string value</param> public void AddVariable(string key, string val) { if (this.ExistTestVariable(key)) { this.IncludedVariables[key].Value = val; } else { PrinterVariable p = new PrinterVariable(); p.Name = key; p.Value = val; this.IncludedVariables.Add(key, p); } }
/// <summary> /// Clone this object /// </summary> /// <returns>new object</returns> public object Clone() { PrinterVariable pv = new PrinterVariable(); pv.Name = this.Name.Clone() as string; if (!String.IsNullOrEmpty(this.Value)) { pv.Value = this.Value.Clone() as string; } pv.Indent = this.Indent; pv.Include = this.Include; foreach (PrinterVariable subpv in this.Values) { pv.IncludedVariables.Add(subpv.Name, subpv.Clone() as PrinterVariable); } return(pv); }
static void Main(string[] args) { try { if (args.Length == 0) { throw new ArgumentException("USAGE : printer file.prt"); } PrinterObject po = null; FileInfo fi = new FileInfo(args[0]); if (fi.Exists) { po = PrinterObject.Load(args[0]); } else { po = PrinterObject.Create(new PrinterVersion(Path.GetDirectoryName(args[0]), Path.GetFileName(args[0]))); po.AddData(@"using System; using System.IO; using System.Runtime.Serialization.Formatters.Binary; namespace "); po.AddData("[Printer]"); po.AddData(@" { class "); po.AddData("[Program]"); po.AddData(@" { static void Main(string[] args) { //"); PrinterVariable pv = new PrinterVariable(); pv.Name = "condition"; pv.Include = true; pv.Indent = true; pv.AddVariable("expression", "true"); pv.AddVariable("then", "code"); pv.AddVariable("else", "code"); pv.Value = "C/if.prt"; po.AddVariable("condition", pv); po.UseVariable("condition"); po.AddData(@" } } } "); } Console.WriteLine(po.Execute()); Console.WriteLine("code:"); Console.WriteLine(po.ToString()); PrinterObject.Save(po, args[0]); } catch (Exception ex) { Console.WriteLine(ex.Message); } finally { Console.WriteLine("Touch your keyboard"); Console.ReadKey(); } }