using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Collections.ObjectModel;
using System.Runtime.Serialization;
using System.ComponentModel;
using System.Globalization;
using System.Collections.Specialized;
using System.Text.RegularExpressions;
using System.Runtime.Serialization.Formatters;
using System.ComponentModel.DataAnnotations;
using Newtonsoft.Json.Linq;
using Newtonsoft.Json.Converters;
using Newtonsoft.Json.Serialization;
public interface IEukaryote
System.Collections.Generic.IEnumerable<ICell> Cells { get; }
string GenericName { get; }
public sealed partial class PlantCell
public int Id { get { return 12324; } }
public sealed partial class Plant : IEukaryote
public System.Collections.Generic.IEnumerable<ICell> Cells { get { return (_valuesDict["Cells"] as System.Collections.IEnumerable).Cast<ICell>(); } }
public string GenericName { get { return _valuesDict["GenericName"] as string; } }
public string FieldIWantSerialized;
public int SomethingIDoNotWantSerialized { get { return 99999; } }
private readonly System.Collections.Generic.IDictionary<string, object> _valuesDict;
_valuesDict = new System.Collections.Generic.Dictionary<string, object>();
var cells = new System.Collections.Generic.List<PlantCell>();
cells.Add(new PlantCell());
_valuesDict["Cells"] = cells;
_valuesDict["GenericName"] = "HousePlant";
this.FieldIWantSerialized = "FieldIWantSerialized Value";
public override string ToString()
return Newtonsoft.Json.JsonConvert.SerializeObject(this,
new Newtonsoft.Json.JsonSerializerSettings()
ContractResolver = new Newtonsoft.Json.Serialization.CamelCasePropertyNamesContractResolver()
[System.ComponentModel.DataAnnotations.MetadataType(typeof(PlantMetadata))]
public sealed partial class Plant
[JsonObject(MemberSerialization.OptIn)]
internal sealed class PlantMetadata
public IEnumerable<ICell> Cells { get; set; }
public string GenericName { get; set; }
public string FieldIWantSerialized;
public static void Test()
var s = plant.ToString();
Assert.IsTrue(s.Contains("cells"));
Assert.IsTrue(s.Contains("genericName"));
Assert.IsTrue(s.Contains("fieldIWantSerialized"));
Assert.IsTrue(s.IndexOf("SomethingIDoNotWantSerialized", StringComparison.OrdinalIgnoreCase) == -1);
public static void Main()
Console.WriteLine("Environment version: " + Environment.Version);
Console.WriteLine("Json.NET version: " + typeof(JsonSerializer).Assembly.FullName);
public class AssertionFailedException : System.Exception
public AssertionFailedException() : base() { }
public AssertionFailedException(string s) : base(s) { }
public static class Assert
public static void IsTrue(bool value)
throw new AssertionFailedException("failed");