title: Newtonsoft JSON: How do I serialize some .NET objects that aren't strings, integers, etc... (like NetworkInterface)
body: <p>I'm trying to serialize information I obtain from <code>System.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces()</code></p>
  
  <p><code>GetAllNetworkInterfaces()</code> returns a collection of <code>NetworkInterface</code> objects.  Serializing it basically returns no useful information.</p>
  
  <pre><code>    {
        "IsReceiveOnly": false,
        "Description": "TAP-Windows Adapter V9",
        "SupportsMulticast": true,
        "NetworkInterfaceType": 6,
        "OperationalStatus": 2,
        "Speed": 100000000,
        "Id": "{BCE79C39-232A-4483-AF64-1D26E3AA7C83}",
        "Name": "Ethernet"
      },
      etc...
  </code></pre>
  
  <p>Each <code>NetworkInterface</code> object has a function <code>GetIPProperties</code> which returns an <code>IPInterfaceProperties</code> object which in turn has a <code>GetIPv4Properties()</code> function which returns an <code>IPv4InterfaceProperties</code> object.</p>
  
  <p>I see lots of examples of adding attributes to class properties to tell Newtonsoft JSON to serialize properties that aren't normal string, integer, boolean, etc...and even serializing the results from function calls, but I'm stumped on how I can indicate that for existing .NET objects.</p>
  
  <p>My current and very painful workaround is to create my own <code>MyNetworkInterface</code> class with the properties I want and then manually assign properties like:</p>
  
  <pre><code>for each adapter as NetworkInterface in NetworkInterface.GetAllNetworkInterfaces()
    my_custom_network_interface_object.some_property = real_network_interface_object.some_property
    dim ip_properties() as IPInterfaceProperties = real_network_interface_object.GetIPProperties()
    dim gateway_info() as GatewayIPAddressInformationCollection = ip_properties.GatewayAddresses
    for gw in gateway_info
       my_custom_network_interface_object.gateway.add(gw.ToString())
  </code></pre>
  
  <p>It seems like there should be a better way, and I'm just missing it.</p>
  
  <p>Coming from a Python background, I feel totally lost in VB.NET.  :)</p>