コード例 #1
0
        public static string ToJson(this Model model, NameSerialization nameSerialization = NameSerialization.AsParent)
        {
            var json = nameSerialization == NameSerialization.AsParent
                ? $"\"{model.Name}\":"
                : string.Empty;

            var properties = JsonProperties(model).Where(js => !string.IsNullOrWhiteSpace(js)).ToList();

            if (nameSerialization == NameSerialization.AsProperty)
            {
                properties.Insert(0, string.Format(StringPropertyTemplate, Constants.RootNameProperty, model.Name));
            }

            json += "{"
                    + string.Join(", ", properties)
                    + "}";

            return(json);
        }
コード例 #2
0
 private static string ToJson(this IEnumerable <Model> models, NameSerialization nameSerialization)
 {
     return(string.Join(", ", models.Select(m => m.ToJson(nameSerialization)).ToArray()));
 }