string BuildStringArrayJson <T>(T[] objects, int numValidObjects, KeepFunction <T> keepFunction, ToStringFunction <T> toString, StringBuilder jsoner) { jsoner.Clear(); jsoner.Append("["); bool gotOneString = false; for (int i = 0; i < numValidObjects; i++) { T obj = objects[i]; if (!keepFunction(obj)) { continue; } string theString = toString(obj); if (theString != null) { if (gotOneString) { jsoner.Append(","); } gotOneString = true; jsoner.Append("\""); jsoner.Append(theString); jsoner.Append("\""); } } jsoner.Append("]"); return(jsoner.ToString()); }
private AST Group2() { var ast = Group1(); if (CurrentToken.TokenType == TokenType.Function) { if (ast != null) { ThrowUnexpectedTokenTypeException(); } switch (CurrentToken.Value) { case "ToString": ast = new ToStringFunction(CurrentToken); break; case "DateTime.Now": ast = new DateTimeFunction(CurrentToken); break; case "string.Concat": ast = new StringConcatFunction(CurrentToken); break; case "AddMonths": ast = new AddMonths(CurrentToken); break; default: ThrowUnexpectedTokenTypeException(); break; } CurrentToken = _lexer.GetNextToken(); if (CurrentToken.TokenType != TokenType.OpenParenthesis) { ThrowUnexpectedTokenTypeException(); } CurrentToken = _lexer.GetNextToken(); while (CurrentToken.TokenType != TokenType.CloseParenthesis) { ast.ChildNodes.Add(Group10()); if (CurrentToken.TokenType == TokenType.Separator) { CurrentToken = _lexer.GetNextToken(); } } CurrentToken = _lexer.GetNextToken(); } return(ast); }
public static Dictionary <string, string> Create(object obj, ToStringFunction toString) { var dict = new Dictionary <string, string>(); foreach (PropertyDescriptor descriptor in TypeDescriptor.GetProperties(obj)) { dict.Add(descriptor.Name, toString(descriptor.GetValue(obj))); } return(dict); }
public static string join <T>(this IEnumerable <T> list, ToStringFunction <T> toStringFunction, string separator = ", ") { var s = ""; var first = true; foreach (var t in list) { if (first) { first = false; } else { s += separator; } s += toStringFunction(t); } return(s); }