Exemplo n.º 1
0
        /// <summary>
        /// Private dispose method called by both the finalizer and the public
        /// <see cref="Dispose()"/> method. We take care of finalizing the key
        /// and calling back our parent.
        /// </summary>
        /// <param name="disposing">Whether this is called from the <see cref="Dispose()"/>
        /// method (<c>true</c>) or the finalizer (<c>false</c>).</param>
        private void Dispose(bool disposing)
        {
            // Nothing to do to actually finalize the key; next key writer will
            // add another newline.

            if (parent != null)
            {
                // Clear reference to ourselves in parent so that it can add other keys.
                Debug.Assert(parent.keyWriter == this);
                parent.keyWriter = null;
                parent           = null;
            }
            writer = null;
        }
Exemplo n.º 2
0
        /// <summary>
        /// Internal constructor called by <see cref="RegistryFileWriter"/> when
        /// a new key is added to the registry import file.
        /// </summary>
        /// <param name="keyPath">Path of the registry key, including root key.</param>
        /// <param name="parent">Parent <see cref="RegistryFileWriter"/> that
        /// created us. We need to call it back when we're done.</param>
        internal RegistryKeyWriter(string keyPath, RegistryFileWriter parent)
        {
            Debug.Assert(!String.IsNullOrEmpty(keyPath));
            Debug.Assert(parent != null);

            // Save reference to parent and its internal writer.
            this.parent = parent;
            this.writer = parent.writer;

            // Save reference to ourselves in parent to mark us as active.
            Debug.Assert(parent.keyWriter == null);
            parent.keyWriter = this;

            // Add a newline to the file to separate this key's values
            // from values of the previous key (or from the file header).
            this.writer.WriteLine();

            // Write the key header.
            this.writer.WriteLine("[{0}]", keyPath);
        }