string Cast(IBasicToken token) { if (token.Source != null && !String.IsNullOrEmpty(token.ToString())) { return("''" + token.Source.ToString() + "''"); } return("''''"); }
public static void ToSql(this IToken token, StringBuilder builder) { if (token is IExpression) { ToSql((IExpression)token, builder); } if (token is IBasicToken) { IBasicToken basicToken = token as IBasicToken; basicToken.Evaluate(); if (basicToken.Value != null) { builder.AppendFormat("{0}", basicToken.Value.ToString().Replace("'", "''")); } } else { System.Reflection.MethodInfo concreteMethod = token.GetType().GetMethod("ToSql", new Type[] { typeof(StringBuilder) }); if (null != concreteMethod) { concreteMethod.Invoke(token, new object[] { builder }); } } }
public static void ToConfiguration(this IToken token, IConfigurationElement config) { if (!config.Attributes.ContainsKey("type")) { config.AddAttribute("type").Value = token.Key; } else if ((string)config.GetAttributeReference("type").Value != token.Key) { config.GetAttributeReference("type").Value = token.Key; } IExpression expression = token as IExpression; if (null != expression) { IConfigurationElement operandsElement = config.AddElement("operands"); int index = 0; foreach (IToken operand in expression.Operands.Where(o => null != o)) { IConfigurationElement operandElement = operandsElement.AddElement(index.ToString()); operand.ToConfiguration(operandElement); index++; } } else { IBasicToken basicToken = token as IBasicToken; if (null != basicToken) { IConfigurationElement sourceElement = config.AddElement("source"); if (null != basicToken.Source) { if (basicToken.Source is Control) { sourceElement.AddAttribute("id").Value = ((Control)basicToken.Source).ID; } else { sourceElement.AddAttribute("id").Value = basicToken.Source; } if (!String.IsNullOrEmpty(basicToken.Member)) { sourceElement.AddAttribute("member").Value = basicToken.Member; } } else if (null != basicToken.Value) { sourceElement.AddAttribute("value").Value = basicToken.Source; } } else { System.Reflection.MethodInfo concreteMethod = token.GetType().GetMethod("ToConfiguration", new Type[] { typeof(IConfigurationElement) }); if (null != concreteMethod) { concreteMethod.Invoke(token, new object[] { config }); } } } }
string Cast(IBasicToken token) { if (token.Source != null && !String.IsNullOrEmpty(token.ToString())) return "''" + token.Source.ToString() + "''"; return "''''"; }