Exemple #1
0
        // Serialize this instance to a Grasshopper writer object.
        //Serialization is required for saving persistent data into a .gh or .ghx file.
        public override bool Write(GH_IO.Serialization.GH_IWriter writer)
        {
            IFormatter   formatter    = RFSerializer.GetInstance().Formatter;
            MemoryStream memoryStream = new MemoryStream();

            try
            {
                formatter.Serialize(memoryStream, Value);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            string text = Convert.ToBase64String(memoryStream.ToArray());

            writer.SetString("Object_bin", text);
            return(base.Write(writer));
        }
Exemple #2
0
        // Deserialize this instance from a Grasshopper reader object.
        //Serialization is required for reading persistent data from a .gh or .ghx file.
        public override bool Read(GH_IO.Serialization.GH_IReader reader)
        {
            string s = "";

            if (reader.TryGetString("Object_bin", ref s))
            {
                IFormatter   formatter           = RFSerializer.GetInstance().Formatter;
                MemoryStream serializationStream = new MemoryStream(Convert.FromBase64String(s));
                try
                {
                    serializationStream.Position = 0;
                    Value = ((RFFilter)formatter.Deserialize(serializationStream));
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
            return(base.Read(reader));
        }