Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,11 @@ protected override void Dispose(bool disposing)
if (disposing && !IsDisposed)
{
_addDelegate(XamlNodeType.None, XamlNode.InternalNodeType.EndOfStream);
_addDelegate = new XamlNodeAddDelegate(ThrowBecauseWriterIsClosed);
_addLineInfoDelegate = (_addLineInfoDelegate != null)
? new XamlLineInfoAddDelegate(ThrowBecauseWriterIsClosed2)
: null;
_addDelegate = delegate { throw new XamlException(SR.Get(SRID.WriterIsClosed)); };
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we even need to set _addDelegate and _addLineInfoDelegate ? ThrowIsDisposed should already be called before the use of _addDelegate or _addLineInfoDelegate.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know. I'm just trying to maintain behavior just in case. 😄

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still think this PR is valid because it's faster than the existing code, which was already executed even if the new delegate is not invoked. A follow-up PR could be open to remove this "dead code" with more thorough testing to make sure that the delegates are never executed after dispose. I only said this over a quick glance over the code but they might be invoked.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still think this PR is valid

It is 😄

if (_addLineInfoDelegate != null)
{
_addLineInfoDelegate = delegate { throw new XamlException(SR.Get(SRID.WriterIsClosed)); };
}
}
}
finally
Expand Down Expand Up @@ -111,17 +112,6 @@ public bool ShouldProvideLineInfo
}
#endregion


private void ThrowBecauseWriterIsClosed(XamlNodeType nodeType, object data)
{
throw new XamlException(SR.Get(SRID.WriterIsClosed));
}

private void ThrowBecauseWriterIsClosed2(int lineNumber, int linePosition)
{
throw new XamlException(SR.Get(SRID.WriterIsClosed));
}

private void ThrowIsDisposed()
{
if (IsDisposed)
Expand Down