using System.Collections;
using System.Collections.Generic;
using System.Runtime.Serialization.Formatters;
using System.ComponentModel.DataAnnotations;
using System.Globalization;
using Newtonsoft.Json.Linq;
using Newtonsoft.Json.Converters;
using Newtonsoft.Json.Serialization;
public abstract class WorkbenchAPI
protected abstract IReadOnlyCollection<dynamic> GetResults();
public string status { get; set; }
public HttpStatusCode code { get; set; }
public string error { get; set; }
public string guid { get; set; }
public IReadOnlyCollection<dynamic> results => GetResults();
public class WorkbenchAPI<T> : WorkbenchAPI where T : class
protected override IReadOnlyCollection<dynamic> GetResults() => results;
public new List<T> results { get; set; } = new List<T>();
public string SamAccountName { get; set; }
public string CN { get; set; }
public string EmailAddress { get; set; }
public static void Test()
var root = JsonConvert.DeserializeObject<WorkbenchAPI<ClassA>>(json);
var accounts = root.results.Select(r => r.SamAccountName).ToList();
WorkbenchAPI baseRoot = root;
var count = baseRoot.results.Count;
var guid = baseRoot.guid;
Console.WriteLine("Accounts: {0}", string.Join(',', accounts));
Console.WriteLine("guid = {0}, result count = {1}", guid, count);
var json2 = JsonConvert.SerializeObject(root, Newtonsoft.Json.Formatting.Indented);
Console.WriteLine(json2);
""SamAccountName"": ""dizbuster"",
""EmailAddress"": ""dizbuster@whatever.com"",
public static void Main()
Console.WriteLine("Environment version: {0} ({1})", System.Runtime.InteropServices.RuntimeInformation.FrameworkDescription , GetNetCoreVersion());
Console.WriteLine("Json.NET version: " + typeof(JsonSerializer).Assembly.FullName);
Console.WriteLine("Failed with unhandled exception: ");
public static string GetNetCoreVersion()
var assembly = typeof(System.Runtime.GCSettings).GetTypeInfo().Assembly;
var assemblyPath = assembly.CodeBase.Split(new[] { '/', '\\' }, StringSplitOptions.RemoveEmptyEntries);
int netCoreAppIndex = Array.IndexOf(assemblyPath, "Microsoft.NETCore.App");
if (netCoreAppIndex > 0 && netCoreAppIndex < assemblyPath.Length - 2)
return assemblyPath[netCoreAppIndex + 1];