diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/BamlReader.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/BamlReader.cs index d40a210595c..675f6294527 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/BamlReader.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/BamlReader.cs @@ -182,7 +182,7 @@ public BamlReader(Stream bamlStream) _properties = new ArrayList(); _haveUnprocessedRecord = false; _deferableContentBlockDepth = -1; - _nodeStack = new Stack(); + _nodeStack = new Stack(); _reverseXmlnsTable = new Dictionary>(); } @@ -1447,9 +1447,9 @@ private BamlKeyInfo ProcessKeyTree() // track of when we have entered a constructor parameter section and when // we have written out the first parameter to handle adding commas between // constructor parameters. - Stack readProperty = new Stack(); - Stack readConstructor = new Stack(); - Stack readFirstConstructor = new Stack(); + Stack readProperty = new(); + Stack readConstructor = new(); + Stack readFirstConstructor = new(); readProperty.Push(false); // Property has not yet been read readConstructor.Push(false); // Constructor section has not been read readFirstConstructor.Push(false); // First constructor parameter has not been read @@ -1493,8 +1493,8 @@ private BamlKeyInfo ProcessKeyTree() case BamlRecordType.PropertyComplexStart: ReadPropertyComplexStartRecord(); - nodeInfo = (BamlNodeInfo)_nodeStack.Pop(); - if ((bool)readProperty.Pop()) + nodeInfo = _nodeStack.Pop(); + if (readProperty.Pop()) { markupString += ", "; } @@ -1520,12 +1520,12 @@ private BamlKeyInfo ProcessKeyTree() // If the text contains '{' or '}' then we have to escape these // so that it won't be interpreted as a MarkupExtension string escapedString = EscapeString(((BamlTextRecord)_currentBamlRecord).Value); - if ((bool)readFirstConstructor.Peek()) + if (readFirstConstructor.Peek()) { markupString += ", "; } markupString += escapedString; - if ((bool)readConstructor.Peek()) + if (readConstructor.Peek()) { readFirstConstructor.Pop(); readFirstConstructor.Push(true); @@ -1534,11 +1534,11 @@ private BamlKeyInfo ProcessKeyTree() case BamlRecordType.ElementStart: // Process commas between constructor parameters - if ((bool)readFirstConstructor.Peek()) + if (readFirstConstructor.Peek()) { markupString += ", "; } - if ((bool)readConstructor.Peek()) + if (readConstructor.Peek()) { readFirstConstructor.Pop(); readFirstConstructor.Push(true); @@ -1585,11 +1585,11 @@ private BamlKeyInfo ProcessKeyTree() case BamlRecordType.ConstructorParameterType: // Process commas between constructor parameters - if ((bool)readFirstConstructor.Peek()) + if (readFirstConstructor.Peek()) { markupString += ", "; } - if ((bool)readConstructor.Peek()) + if (readConstructor.Peek()) { readFirstConstructor.Pop(); readFirstConstructor.Push(true); @@ -1603,7 +1603,7 @@ private BamlKeyInfo ProcessKeyTree() { string value = ((BamlPropertyRecord)_currentBamlRecord).Value; BamlPropertyInfo propertyInfo = ReadPropertyRecordCore(value); - if ((bool)readProperty.Pop()) + if (readProperty.Pop()) { markupString += ", "; } @@ -1615,7 +1615,7 @@ private BamlKeyInfo ProcessKeyTree() case BamlRecordType.PropertyCustom: { BamlPropertyInfo propertyInfo = GetPropertyCustomRecordInfo(); - if ((bool)readProperty.Pop()) + if (readProperty.Pop()) { markupString += ", "; } @@ -1628,7 +1628,7 @@ private BamlKeyInfo ProcessKeyTree() { string value = MapTable.GetStringFromStringId(((BamlPropertyStringReferenceRecord)_currentBamlRecord).StringId); BamlPropertyInfo propertyInfo = ReadPropertyRecordCore(value); - if ((bool)readProperty.Pop()) + if (readProperty.Pop()) { markupString += ", "; } @@ -1642,7 +1642,7 @@ private BamlKeyInfo ProcessKeyTree() string value = GetTypeValueString(((BamlPropertyTypeReferenceRecord)_currentBamlRecord).TypeId); string attributeName = MapTable.GetAttributeNameFromId( ((BamlPropertyTypeReferenceRecord)_currentBamlRecord).AttributeId); - if ((bool)readProperty.Pop()) + if (readProperty.Pop()) { markupString += ", "; } @@ -1656,7 +1656,7 @@ private BamlKeyInfo ProcessKeyTree() string value = GetExtensionValueString((BamlPropertyWithExtensionRecord)_currentBamlRecord); string attributeName = MapTable.GetAttributeNameFromId( ((BamlPropertyWithExtensionRecord)_currentBamlRecord).AttributeId); - if ((bool)readProperty.Pop()) + if (readProperty.Pop()) { markupString += ", "; } @@ -1842,7 +1842,7 @@ private void ReadDocumentEndRecord() { // Pop information off the node stack to ensure we have matched all the // start and end nodes and have nothing left but the start document node. - BamlNodeInfo nodeInfo = (BamlNodeInfo)_nodeStack.Pop(); + BamlNodeInfo nodeInfo = _nodeStack.Pop(); if (nodeInfo.RecordType != BamlRecordType.DocumentStart) { throw new InvalidOperationException(SR.Format(SR.BamlScopeError, @@ -2025,7 +2025,7 @@ private void ReadElementEndRecord() // Pop information off the node stack that tells us what element this // is the end of. Check to make sure the record on the stack is for a // start element. - BamlNodeInfo nodeInfo = (BamlNodeInfo)_nodeStack.Pop(); + BamlNodeInfo nodeInfo = _nodeStack.Pop(); if (nodeInfo.RecordType != BamlRecordType.ElementStart) { throw new InvalidOperationException(SR.Format(SR.BamlScopeError, @@ -2112,7 +2112,7 @@ private void ReadPropertyComplexEndRecord() // Pop information off the node info stack that tells us what the starting // record was for this ending record. Check to make sure it is the // correct type. If not, throw an exception. - BamlNodeInfo nodeInfo = (BamlNodeInfo)_nodeStack.Pop(); + BamlNodeInfo nodeInfo = _nodeStack.Pop(); BamlRecordType expectedType; switch (nodeInfo.RecordType) { @@ -2240,7 +2240,7 @@ private void ReadConstructorEnd() // Pop information off the node stack that tells us what element this // is the end of. Check to make sure the record on the stack is for a // start element. - BamlNodeInfo nodeInfo = (BamlNodeInfo)_nodeStack.Pop(); + BamlNodeInfo nodeInfo = _nodeStack.Pop(); if (nodeInfo.RecordType != BamlRecordType.ConstructorParametersStart) { throw new InvalidOperationException(SR.Format(SR.BamlScopeError, @@ -2842,7 +2842,7 @@ private BamlMapTable MapTable private BamlAttributeUsage _attributeUsage; // Stack of node information about the element tree being built. - private Stack _nodeStack; + private readonly Stack _nodeStack; // Context information used when reading baml file. This contains the XamlTypeMapper used // for resolving binary property information into strings.