public override void OnValue(string value, ValueType type) { if (type == ValueType.Null) { _jsonWriter.WriteNull(); return; } bool boolValue; if (type == ValueType.Boolean && bool.TryParse(value, out boolValue)) { _jsonWriter.WriteValue(boolValue); } else { decimal numberValue; if (type == ValueType.Number && decimal.TryParse(value, out numberValue)) { if (numberValue % 1 == 0) { _jsonWriter.WriteValue((long)numberValue); } else { _jsonWriter.WriteValue(numberValue); } } else { _jsonWriter.WriteValue(value); } } }
private string ResolveObjectValue(object objectValue, out ValueType valueType) { var value = objectValue as Parameter; if (value != null) { return(ResolveValueParameter(value, out valueType)); } var alias = objectValue as Alias; valueType = ValueType.None; return(alias != null?ResolveValueAlias(alias, out valueType) : null); }
protected string ResolveValueAlias(Alias alias, out ValueType valueType) { var aliasDef = _context.NamespaceResolver.GetAliasDefinition(alias.Name); AliasContext.Push(new AliasContext { AliasDefinition = aliasDef, Alias = alias, AliasNsInfo = GetContextNsInfo() }); var result = aliasDef.ObjectValue == null?ResolveNodeValue(aliasDef, out valueType) : ResolveObjectValue(aliasDef.ObjectValue, out valueType); AliasContext.Pop(); return(result); }
protected string ResolveNodeValue(DOM.Antlr.IValueNode node, out ValueType valueType) { if (((IValueNode)node).ValueType != ValueType.SingleQuotedString) { valueType = ((IValueNode)node).ValueType; return(((IValueNode)node).Value); } var sb = new StringBuilder(); foreach (var item in node.InterpolationItems) { var alias = item as Alias; if (alias != null) { sb.Append(ResolveValueAlias(alias, out valueType)); continue; } var param = item as Parameter; if (param != null) { sb.Append(ResolveValueParameter(param, out valueType)); continue; } var token = item as CommonToken; if (token == null) { continue; } if (token.Type == MalinaLexer.SQS_ESCAPE) { ResolveSqsEscape(token, sb); } else { sb.Append(token.Type == MalinaLexer.SQS_EOL ? ResolveSqsEol(token, node.ValueIndent) : token.Text); } } valueType = ValueType.SingleQuotedString; return(sb.ToString()); }
protected string ResolveValueParameter(Parameter parameter, out ValueType valueType) { var aliasContext = GetAliasContextForParameter(parameter); if (parameter.Name == "_") { //Resolving default value parameter if (aliasContext.Alias.ObjectValue != null) { return(ResolveObjectValue(aliasContext.Alias.ObjectValue, out valueType)); } return(ResolveNodeValue((DOM.Antlr.IValueNode)aliasContext.Alias, out valueType)); } var argument = aliasContext.Alias.Arguments.FirstOrDefault(a => a.Name == parameter.Name); if (argument != null) { if (argument.ObjectValue != null) { return(ResolveObjectValue(argument.ObjectValue, out valueType)); } valueType = argument.ValueType; return(argument.Value); } //if argument is not found lookup default value in the Alias Definition var paramDef = ((DOM.Antlr.AliasDefinition)aliasContext.AliasDefinition).Parameters.First(p => p.Name == parameter.Name); //If parameteres default value is Parameter or Alias then resolve it if (paramDef.ObjectValue != null) { return(ResolveObjectValue(paramDef.ObjectValue, out valueType)); } valueType = paramDef.ValueType; return(paramDef.Value); }
public override void OnValue(string value, ValueType type) { _xmlTextWriter.WriteString(value); }
public virtual void OnValue(string value, ValueType type) { }