public static string Format <T>(T entity, params string[] names) { JavascriptBuilder jbuilder = new JavascriptBuilder(255); jbuilder.Append <T>(entity, names); return(jbuilder.ToString()); }
public static string DataDrilldown <T>(Tree <T> tree, string nameMember, string valueMember) { JavascriptBuilder builder = new JavascriptBuilder(512); AppendDrilldown <T>( builder, tree, ClassSchema <T> .Instance[nameMember], ClassSchema <T> .Instance[valueMember]); return(builder.ToString()); }
public static void AppendDrilldown <T>( JavascriptBuilder builder, Tree <T> tree, AspectMember nameMember, AspectMember valueMember) { builder.AppendRaw("["); bool outercomma = false; foreach (TreeNode <T> node in tree) { if (outercomma) { builder.AppendRaw(", "); } else { outercomma = true; } builder.AppendLine("{"); builder.AppendRaw("y: "); builder.Append(valueMember.GetValue(node.Value)); builder.AppendLine(", drilldown: {"); builder.AppendRaw("name: "); builder.Append(nameMember.GetValue(node.Value)); builder.AppendLine(", categories: ["); bool prependComma = false; foreach (TreeNode <T> child in node) { if (prependComma) { builder.AppendRaw(", "); } else { prependComma = true; } builder.Append(nameMember.GetValue(node.Value)); } builder.AppendLine("]"); builder.AppendLine(", data: ["); prependComma = false; foreach (TreeNode <T> child in node) { if (prependComma) { builder.AppendRaw(", "); } else { prependComma = true; } builder.Append(valueMember.GetValue(node.Value)); } builder.AppendLine("]"); builder.AppendLine("}"); builder.AppendRaw("}"); } builder.AppendRaw("]"); }
public static string Format(object value) { if (value == null) { return("null"); } else { Type tp = value.GetType(); if (tp == PrimitiveTypes.Boolean) { return(Format((bool)value)); } else if (tp == PrimitiveTypes.Byte) { return(Format((byte)value)); } else if (tp == PrimitiveTypes.Char) { return(Format((char)value)); } else if (tp == PrimitiveTypes.Decimal) { return(Format((decimal)value)); } else if (tp == PrimitiveTypes.Double) { return(Format((double)value)); } else if (tp == PrimitiveTypes.Float) { return(Format((float)value)); } else if (tp == PrimitiveTypes.Int) { return(Format((int)value)); } else if (tp == PrimitiveTypes.Long) { return(Format((long)value)); } else if (tp == PrimitiveTypes.Short) { return(Format((short)value)); } else if (tp == PrimitiveTypes.String) { return(Format((string)value)); } else if (tp == PrimitiveTypes.UInt) { return(Format((int)value)); } else if (tp == PrimitiveTypes.ULong) { return(Format((long)value)); } else if (tp.IsArray) { return(Format((Array)value)); } else if (PrimitiveTypes.IEnumerable.IsAssignableFrom(tp)) { return(Format((System.Collections.IEnumerable)value)); } else { JavascriptBuilder builder = new JavascriptBuilder(); builder.Append(value); return(builder.ToString()); } } }