/// <summary>
        /// Create a JSON string representation of this object
        /// </summary>
        /// <param name="options"></param>
        /// <returns></returns>
        /// <since>7.0</since>
        public string ToJSON(Pixel.Rhino.FileIO.SerializationOptions options)
        {
            string json          = null;
            uint   length        = 0;
            bool   writeuserdata = true;

            if (options != null)
            {
                writeuserdata = options.WriteUserData;
            }
#if RHINO_SDK
            int rhino_version = (options != null) ? options.RhinoVersion : RhinoApp.ExeVersion;
#else
            int rhino_version = (options != null) ? options.RhinoVersion : 7;
#endif
            // 28 Aug 2014 S. Baer (RH-28446)
            // We switched to 50,60,70,... type numbers after Rhino 4
            if (rhino_version > 4 && rhino_version < 50)
            {
                rhino_version *= 10;
            }

            // NOTE:
            //   ON_WriteBufferArchive_NewWriter may change value of rhino_version
            //   if it is too big or the object type requires a different archive version.
            IntPtr pConstOnObject = ConstPointer();
            IntPtr pWriteBuffer   = UnsafeNativeMethods.ON_WriteBufferArchive_NewWriter(pConstOnObject, ref rhino_version, writeuserdata, ref length);
            if (length < int.MaxValue && length > 0 && pWriteBuffer != IntPtr.Zero)
            {
                int    sz         = (int)length;
                IntPtr pByteArray = UnsafeNativeMethods.ON_WriteBufferArchive_Buffer(pWriteBuffer);
                byte[] bytearray  = new byte[sz];
                System.Runtime.InteropServices.Marshal.Copy(pByteArray, bytearray, 0, sz);
                uint archive_opennurbs_version = UnsafeNativeMethods.ON_WriteBufferArchive_OpenNURBSVersion(pWriteBuffer);

                string data = Convert.ToBase64String(bytearray);
                System.Text.StringBuilder sb = new System.Text.StringBuilder(data.Length + 100);
                sb.Append($"{{\"version\":10000,\"{ARCHIVE_3DM_VERSION}\":{rhino_version},\"{ARCHIVE_OPENNURBS_VERSION}\":{(int)archive_opennurbs_version},\"data\":\"");
                sb.Append(data);
                sb.Append("\"}");
                json = sb.ToString();
            }
            UnsafeNativeMethods.ON_WriteBufferArchive_Delete(pWriteBuffer);
            return(json);
        }
        internal static void SerializeWriteON_Object(IntPtr pConstOnObject, SerializationInfo info, StreamingContext context)
        {
            Pixel.Rhino.FileIO.SerializationOptions options = context.Context as Pixel.Rhino.FileIO.SerializationOptions;

            uint length        = 0;
            bool writeuserdata = true;

            if (options != null)
            {
                writeuserdata = options.WriteUserData;
            }
#if RHINO_SDK
            int rhino_version = (options != null) ? options.RhinoVersion : RhinoApp.ExeVersion;
#else
            int rhino_version = (options != null) ? options.RhinoVersion : 7;
#endif
            // 28 Aug 2014 S. Baer (RH-28446)
            // We switched to 50,60,70,... type numbers after Rhino 4
            if (rhino_version > 4 && rhino_version < 50)
            {
                rhino_version *= 10;
            }

            // NOTE:
            //   ON_WriteBufferArchive_NewWriter may change value of rhino_version
            //   if it is too big or the object type requires a different archive version.
            IntPtr pWriteBuffer = UnsafeNativeMethods.ON_WriteBufferArchive_NewWriter(pConstOnObject, ref rhino_version, writeuserdata, ref length);

            if (length < int.MaxValue && length > 0 && pWriteBuffer != IntPtr.Zero)
            {
                int    sz         = (int)length;
                IntPtr pByteArray = UnsafeNativeMethods.ON_WriteBufferArchive_Buffer(pWriteBuffer);
                byte[] bytearray  = new byte[sz];
                System.Runtime.InteropServices.Marshal.Copy(pByteArray, bytearray, 0, sz);

                info.AddValue("version", 10000);
                info.AddValue(ARCHIVE_3DM_VERSION, rhino_version);
                uint archive_opennurbs_version = UnsafeNativeMethods.ON_WriteBufferArchive_OpenNURBSVersion(pWriteBuffer);
                info.AddValue(ARCHIVE_OPENNURBS_VERSION, (int)archive_opennurbs_version);
                info.AddValue("data", bytearray);
            }
            UnsafeNativeMethods.ON_WriteBufferArchive_Delete(pWriteBuffer);
        }