/// <summary>
        /// performs lazy initialization to ensure our current code model is up-to-date.
        ///
        /// If we haven't yet created our CodeDom backing we'll create it for the 1st time.  If we've
        /// created our backing, but some elements have been changed that we haven't yet reparsed
        /// then we'll reparse & merge any of the appropriate changes.
        /// </summary>
        private void Initialize()
        {
            if (ccu != null)
            {
                if (isDirty)
                {
                    Reparse();
                    isDirty = false;
                }
                return;
            }

            IMergeDestination merger = MergeDestination;

            if (null == textBuffer)
            {
                using (FileStream fs = new FileStream(Name, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) {
                    if ((null == merger) && (null != parent))
                    {
                        merger = new FileCodeMerger(parent);
                    }
                    ccu = provider.ParseMergable(new StreamReader(fs), merger);
                }
            }
            else
            {
                // Find the size of the buffer.
                int lastLine;
                int lastColumn;
                ErrorHandler.ThrowOnFailure(textBuffer.GetLastLineIndex(out lastLine, out lastColumn));
                // Get the text in the buffer.
                string text;
                ErrorHandler.ThrowOnFailure(textBuffer.GetLineText(0, 0, lastLine, lastColumn, out text));
                if (null == merger)
                {
                    merger = new TextBufferMerger(textBuffer);
                }
                ccu = provider.ParseMergable(text, Name, merger);
            }
        }
Example #2
0
        /// <summary>
        /// performs lazy initialization to ensure our current code model is up-to-date.
        /// 
        /// If we haven't yet created our CodeDom backing we'll create it for the 1st time.  If we've
        /// created our backing, but some elements have been changed that we haven't yet reparsed
        /// then we'll reparse & merge any of the appropriate changes.
        /// </summary>
        private void Initialize()
        {
            if (ccu != null) {
                if (isDirty) {
                    Reparse();
                    isDirty = false;
                }
                return;
            }

            IMergeDestination merger = MergeDestination;
            if (null == textBuffer) {
                using (FileStream fs = new FileStream(Name, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) {
                    if ((null == merger) && (null != parent)) {
                        merger = new FileCodeMerger(parent);
                    }
                    ccu = provider.ParseMergable(new StreamReader(fs),  merger);
                }
            } else {
                // Find the size of the buffer.
                int lastLine;
                int lastColumn;
                ErrorHandler.ThrowOnFailure(textBuffer.GetLastLineIndex(out lastLine, out lastColumn));
                // Get the text in the buffer.
                string text;
                ErrorHandler.ThrowOnFailure(textBuffer.GetLineText(0, 0, lastLine, lastColumn, out text));
                if (null == merger) {
                    merger = new TextBufferMerger(textBuffer);
                }
                ccu = provider.ParseMergable(text, Name, merger);
            }
        }