public static List<Directive> BindingVariables(List<Directive> bufferDirectives, Variable[] variables) { if (bufferDirectives != null && variables != null) { StringBuilder declarationVariables = new StringBuilder(); for (int i = 0; i < variables.Length; i++) { if (variables[i].Type.ToString().Equals(ArgumentType.String.ToString())) declarationVariables.Append(" " + variables[i].Value.GetType() + " " + variables[i].Name + " = \"" + variables[i].Value + "\"; "); else if (variables[i].Type.ToString().Equals(ArgumentType.Boolean.ToString())) declarationVariables.Append(" " + variables[i].Value.GetType() + " " + variables[i].Name + " = true; "); else if (variables[i].Type.ToString().Equals(ArgumentType.Double.ToString())) declarationVariables.Append(" " + variables[i].Value.GetType() + " " + variables[i].Name + " = " + variables[i].Value.ToString().Replace(",", ".") + "; "); else declarationVariables.Append(" " + variables[i].Value.GetType() + " " + variables[i].Name + " = " + variables[i].Value + "; "); } bufferDirectives.Insert(0, new Directive() { Text = declarationVariables.ToString(), IsCode = true }); } return bufferDirectives; }
public ParserJava(String templateText, String[] namespaces, Variable[] variables, Object[] values) { this.bufferDirectives = new List<Directive>(); this.templateText = templateText; this.variables = ValidatorSyntaxJava.ValidateVariables(variables, values); this.values = values; this.namespaces = namespaces; }
public ParserCSharp(String templateText, String[] namespaces, Variable[] variables, Object[] values) { this.bufferDirectives = new List<Directive>(); this.templateText = templateText; this.variables = ValidatorSyntaxCSharp.ValidateVariables(variables, values); this.values = values; this.namespaces = namespaces; if(this.namespaces != null) if(this.namespaces.Length == 0) this.namespaces = new String[] { "using System;" }; }
public static Variable[] ValidateVariables(Variable[] variables, Object[] values) { if (variables != null && values != null) { if (variables.Length != values.Length) throw new Exception(); for (int i = 0; i < variables.Length; i++) { variables[i].Value = values[i]; } return variables; } return null; }
public static Variable[] ValidateVariables(Variable[] variables, Object[] values) { if (variables != null && values != null) { if (variables.Length != values.Length) throw new Exception(); for (int i = 0; i < variables.Length; i++) { if (values[i].GetType().ToString().Contains(variables[i].Type.ToString())) variables[i].Value = values[i]; else throw new Exception(); } return variables; } return null; }
public abstract String Parse(String templateText, String[] namespaces, Variable[] variables, object[] values);
public String Parse(String templateText, String[] namespaces, Variable[] variables, object[] values) { return this.lang.Parse(templateText, namespaces, variables, values); }
public override string Parse(String templateText, String[] namespaces, Variable[] variables, Object[] values) { this.parserLang = new ParserJava(templateText, namespaces, variables, values); return this.parserLang.Parse(); }