Plugin to read document data

I want to build a plugin that will read document data saved by my plugin, post it to a form and be able to edit the fields. I have the following code that works in the original plugin, but fails in the new plugin. the EditDocumentData_Data Find() method calls
TryGetValue(documentSerialNumber, out EditDocumentData_Data data)
which returns data = null

//The data //

namespace EditDocumentData
{
    internal class EditDocumentData_Data
    {

        // Our data major and minor version numbers
        private const int MAJOR = 1;
        private const int MINOR = 0;

        // The dictionary used to store key/value pairs
        private ArchivableDictionary m_dictionary;



.
        public EditDocumentData_Data()
        {
            m_dictionary = new ArchivableDictionary();
        }

 
       public string GetDocumentData(string Key, string Val)
        {
            string res = "";
            m_dictionary.TryGetString(Val, out res);
            return res;
        }



        public bool SetDocumentData(string Key, string Val)
        {
            //Result result = new Result();
            bool result;
            result = m_dictionary.Set(Key, Val);
            return result;
        }




        public void Write(BinaryArchiveWriter archive)
        {
            // Write the version of our data
            archive.Write3dmChunkVersion(MAJOR, MINOR);
            // Write the dictionary
            archive.WriteDictionary(Dictionary);
        }



        public void Read(BinaryArchiveReader archive)
        {
            archive.Read3dmChunkVersion(out var major, out var minor);
            if (MAJOR == major && MINOR == minor)
            {
                var dictionary = archive.ReadDictionary();
                if (null != dictionary && dictionary.Count > 0)
                    Dictionary = dictionary;
            }
        }



        #region Properties

        public ArchivableDictionary Dictionary
        {
            get
            {
                if (null == m_dictionary)
                    m_dictionary = new ArchivableDictionary();
                return m_dictionary;
            }
            set
            {
                m_dictionary = value;
            }
        }

        public int Count
        {
            get { return Dictionary.Count; }
        }

        #endregion // Properties
    }
}






//The DataTable//


namespace EditDocumentData
{
    internal class EditDocumentData_DataTable : Dictionary<uint, EditDocumentData_Data>
    {
        private static EditDocumentData_DataTable g_table;

        private EditDocumentData_DataTable()
        {
        }



        public static EditDocumentData_DataTable Instance
        {
            get
            {
                if (null == g_table)
                    g_table = new EditDocumentData_DataTable();
                return g_table;
            }
        }

        public EditDocumentData_Data Find(uint documentSerialNumber)
        {
            if (TryGetValue(documentSerialNumber, out EditDocumentData_Data data))
                return data;
            else return null;
        }

        public EditDocumentData_Data FindOrCreate(uint documentSerialNumber)
        {
            if (!TryGetValue(documentSerialNumber, out EditDocumentData_Data data))
            {
                data = new EditDocumentData_Data();
                Add(documentSerialNumber, data);
            }
            return data;
        }
    }
}

Assigned to Developer category

1 Like