public object SerializePrototype(IPrototype proto, bool pretty) { JSONPrototype jsonProto = proto as JSONPrototype; if (jsonProto == null) { return(null); } string json = _js.Serialize(jsonProto.Children); if (json == null) { return(null); } return(pretty ? Prettify(json) : json); }
private object MakeValue(object value, Type type, bool asInput, int depth) { if (value == null || depth > MaxDepth) { return(null); } if (type == null) { type = value.GetType(); } if (asInput) { JSONPrototype proto = value as JSONPrototype; if (proto != null) { return(proto.Children); } } else { Dictionary <string, object> subObj = value as Dictionary <string, object>; if (subObj != null) { return(new JSONPrototype(_enumConverter, subObj)); } } if (type.IsEnum) { return(_enumConverter.EnumToString(value)); } if (type == typeof(string)) { return(value as string); } { IEnumerable arr = value as IEnumerable; if (arr != null) { bool allTypesSame = IsIEnumerableOfT(type); Type underlyingType = null; ArrayList arrOut = new ArrayList(); foreach (object item in arr) { if (underlyingType == null || !allTypesSame) { underlyingType = item.GetType(); } arrOut.Add(MakeValue(item, underlyingType, asInput, depth + 1)); } return(arrOut); } } return(value); }