diff --git a/OpenXmlFormats/DocumentPropertiesCustom.cs b/OpenXmlFormats/DocumentPropertiesCustom.cs index 7cae85fc2..f4140d27a 100644 --- a/OpenXmlFormats/DocumentPropertiesCustom.cs +++ b/OpenXmlFormats/DocumentPropertiesCustom.cs @@ -388,16 +388,15 @@ public string linkTarget } public override bool Equals(object obj) { - if (!(obj is CT_Property)) + if (obj is not CT_Property property) return false; - CT_Property a = (CT_Property)obj; - if (a.fmtidField != this.fmtidField - ||a.itemElementNameField!=this.itemElementNameField - ||a.itemField!=this.itemField - ||a.linkTargetField!=this.linkTargetField - ||a.nameField!=this.nameField - ||a.pidField!=this.pidField) + if (property.fmtidField != this.fmtidField + ||property.itemElementNameField!=this.itemElementNameField + ||property.itemField!=this.itemField + ||property.linkTargetField!=this.linkTargetField + ||property.nameField!=this.nameField + ||property.pidField!=this.pidField) return false; return true; diff --git a/OpenXmlFormats/Spreadsheet/PivotTable/CT_PivotCacheDefinition.cs b/OpenXmlFormats/Spreadsheet/PivotTable/CT_PivotCacheDefinition.cs index 3091e1d14..3150b972e 100644 --- a/OpenXmlFormats/Spreadsheet/PivotTable/CT_PivotCacheDefinition.cs +++ b/OpenXmlFormats/Spreadsheet/PivotTable/CT_PivotCacheDefinition.cs @@ -1879,18 +1879,18 @@ internal void Write(StreamWriter sw, string nodeName) { foreach (object o in this.Items) { - if (o is CT_Number) - ((CT_Number)o).Write(sw, "n"); - else if (o is CT_Boolean) - ((CT_Boolean)o).Write(sw, "b"); - else if (o is CT_DateTime) - ((CT_DateTime)o).Write(sw, "d"); - else if (o is CT_Error) - ((CT_Error)o).Write(sw, "e"); - else if (o is CT_Missing) - ((CT_Missing)o).Write(sw, "m"); - else if (o is CT_String) - ((CT_String)o).Write(sw, "s"); + if (o is CT_Number number) + number.Write(sw, "n"); + else if (o is CT_Boolean b) + b.Write(sw, "b"); + else if (o is CT_DateTime time) + time.Write(sw, "d"); + else if (o is CT_Error error) + error.Write(sw, "e"); + else if (o is CT_Missing missing) + missing.Write(sw, "m"); + else if (o is CT_String ctString) + ctString.Write(sw, "s"); } } @@ -5461,18 +5461,18 @@ internal void Write(StreamWriter sw, string nodeName) sw.Write(">"); foreach (object o in this.Items) { - if (o is CT_Error) - ((CT_Error)o).Write(sw, "e"); - else if (o is CT_Boolean) - ((CT_Boolean)o).Write(sw, "b"); - else if (o is CT_DateTime) - ((CT_DateTime)o).Write(sw, "d"); - else if (o is CT_Number) - ((CT_Number)o).Write(sw, "n"); - else if (o is CT_Missing) - ((CT_Missing)o).Write(sw, "m"); - else if (o is CT_String) - ((CT_String)o).Write(sw, "s"); + if (o is CT_Error error) + error.Write(sw, "e"); + else if (o is CT_Boolean b) + b.Write(sw, "b"); + else if (o is CT_DateTime time) + time.Write(sw, "d"); + else if (o is CT_Number number) + number.Write(sw, "n"); + else if (o is CT_Missing missing) + missing.Write(sw, "m"); + else if (o is CT_String ctString) + ctString.Write(sw, "s"); } sw.Write(string.Format("", nodeName)); } @@ -7421,14 +7421,14 @@ internal void Write(StreamWriter sw, string nodeName) sw.Write(">"); foreach (object o in this.Items) { - if (o is CT_Missing) - ((CT_Missing)o).Write(sw, "m"); - else if (o is CT_Number) - ((CT_Number)o).Write(sw, "n"); - else if (o is CT_Error) - ((CT_Error)o).Write(sw, "e"); - else if (o is CT_String) - ((CT_String)o).Write(sw, "s"); + if (o is CT_Missing missing) + missing.Write(sw, "m"); + else if (o is CT_Number number) + number.Write(sw, "n"); + else if (o is CT_Error error) + error.Write(sw, "e"); + else if (o is CT_String ctString) + ctString.Write(sw, "s"); } sw.Write(string.Format("", nodeName)); } diff --git a/OpenXmlFormats/Spreadsheet/PivotTable/CT_PivotCacheRecords.cs b/OpenXmlFormats/Spreadsheet/PivotTable/CT_PivotCacheRecords.cs index 1c45a507e..6df6e361d 100644 --- a/OpenXmlFormats/Spreadsheet/PivotTable/CT_PivotCacheRecords.cs +++ b/OpenXmlFormats/Spreadsheet/PivotTable/CT_PivotCacheRecords.cs @@ -200,20 +200,20 @@ internal void Write(StreamWriter sw) foreach (object o in this.fields) { - if (o is CT_Number) - ((CT_Number)o).Write(sw, "n"); - else if (o is CT_Boolean) - ((CT_Boolean)o).Write(sw, "b"); - else if (o is CT_DateTime) - ((CT_DateTime)o).Write(sw, "d"); - else if (o is CT_Error) - ((CT_Error)o).Write(sw, "e"); - else if (o is CT_Missing) - ((CT_Missing)o).Write(sw, "m"); - else if (o is CT_String) - ((CT_String)o).Write(sw, "s"); - else if (o is CT_Index) - ((CT_Index)o).Write(sw, "x"); + if (o is CT_Number number) + number.Write(sw, "n"); + else if (o is CT_Boolean b) + b.Write(sw, "b"); + else if (o is CT_DateTime time) + time.Write(sw, "d"); + else if (o is CT_Error error) + error.Write(sw, "e"); + else if (o is CT_Missing missing) + missing.Write(sw, "m"); + else if (o is CT_String ctString) + ctString.Write(sw, "s"); + else if (o is CT_Index index) + index.Write(sw, "x"); } sw.Write(""); diff --git a/OpenXmlFormats/Wordprocessing/CustomXml.cs b/OpenXmlFormats/Wordprocessing/CustomXml.cs index 53a89f4ef..219727114 100644 --- a/OpenXmlFormats/Wordprocessing/CustomXml.cs +++ b/OpenXmlFormats/Wordprocessing/CustomXml.cs @@ -201,62 +201,62 @@ internal void Write(StreamWriter sw, string nodeName) this.customXmlPr.Write(sw, "customXmlPr"); foreach (object o in this.Items) { - if (o is CT_TrackChange) - ((CT_TrackChange)o).Write(sw, "customXmlMoveFromRangeStart"); - else if (o is CT_OMathPara) - ((CT_OMathPara)o).Write(sw, "oMathPara"); - else if (o is CT_SdtRow) - ((CT_SdtRow)o).Write(sw, "sdt"); - else if (o is CT_TrackChange) - ((CT_TrackChange)o).Write(sw, "customXmlDelRangeStart"); - else if (o is CT_TrackChange) - ((CT_TrackChange)o).Write(sw, "customXmlInsRangeStart"); - else if (o is CT_Markup) - ((CT_Markup)o).Write(sw, "customXmlMoveFromRangeEnd"); - else if (o is CT_OMath) - ((CT_OMath)o).Write(sw, "oMath"); - else if (o is CT_Markup) - ((CT_Markup)o).Write(sw, "customXmlMoveToRangeEnd"); - else if (o is CT_TrackChange) - ((CT_TrackChange)o).Write(sw, "customXmlMoveToRangeStart"); - else if (o is CT_Markup) - ((CT_Markup)o).Write(sw, "customXmlDelRangeEnd"); - else if (o is CT_RunTrackChange) - ((CT_RunTrackChange)o).Write(sw, "ins"); - else if (o is CT_RunTrackChange) - ((CT_RunTrackChange)o).Write(sw, "moveFrom"); - else if (o is CT_MarkupRange) - ((CT_MarkupRange)o).Write(sw, "moveFromRangeEnd"); - else if (o is CT_MoveBookmark) - ((CT_MoveBookmark)o).Write(sw, "moveFromRangeStart"); - else if (o is CT_RunTrackChange) - ((CT_RunTrackChange)o).Write(sw, "moveTo"); - else if (o is CT_MarkupRange) - ((CT_MarkupRange)o).Write(sw, "moveToRangeEnd"); - else if (o is CT_MoveBookmark) - ((CT_MoveBookmark)o).Write(sw, "moveToRangeStart"); - else if (o is CT_Perm) - ((CT_Perm)o).Write(sw, "permEnd"); - else if (o is CT_PermStart) - ((CT_PermStart)o).Write(sw, "permStart"); - else if (o is CT_ProofErr) - ((CT_ProofErr)o).Write(sw, "proofErr"); - else if (o is CT_Markup) - ((CT_Markup)o).Write(sw, "customXmlInsRangeEnd"); - else if (o is CT_Row) - ((CT_Row)o).Write(sw, "tr"); - else if (o is CT_RunTrackChange) - ((CT_RunTrackChange)o).Write(sw, "del"); - else if (o is CT_MarkupRange) - ((CT_MarkupRange)o).Write(sw, "bookmarkEnd"); - else if (o is CT_Bookmark) - ((CT_Bookmark)o).Write(sw, "bookmarkStart"); - else if (o is CT_MarkupRange) - ((CT_MarkupRange)o).Write(sw, "commentRangeEnd"); - else if (o is CT_MarkupRange) - ((CT_MarkupRange)o).Write(sw, "commentRangeStart"); - else if (o is CT_CustomXmlRow) - ((CT_CustomXmlRow)o).Write(sw, "customXml"); + if (o is CT_TrackChange change) + change.Write(sw, "customXmlMoveFromRangeStart"); + else if (o is CT_OMathPara para) + para.Write(sw, "oMathPara"); + else if (o is CT_SdtRow row) + row.Write(sw, "sdt"); + else if (o is CT_TrackChange trackChange) + trackChange.Write(sw, "customXmlDelRangeStart"); + else if (o is CT_TrackChange ctTrackChange) + ctTrackChange.Write(sw, "customXmlInsRangeStart"); + else if (o is CT_Markup markup) + markup.Write(sw, "customXmlMoveFromRangeEnd"); + else if (o is CT_OMath math) + math.Write(sw, "oMath"); + else if (o is CT_Markup ctMarkup) + ctMarkup.Write(sw, "customXmlMoveToRangeEnd"); + else if (o is CT_TrackChange change1) + change1.Write(sw, "customXmlMoveToRangeStart"); + else if (o is CT_Markup markup1) + markup1.Write(sw, "customXmlDelRangeEnd"); + else if (o is CT_RunTrackChange runTrackChange) + runTrackChange.Write(sw, "ins"); + else if (o is CT_RunTrackChange ctRunTrackChange) + ctRunTrackChange.Write(sw, "moveFrom"); + else if (o is CT_MarkupRange range) + range.Write(sw, "moveFromRangeEnd"); + else if (o is CT_MoveBookmark bookmark) + bookmark.Write(sw, "moveFromRangeStart"); + else if (o is CT_RunTrackChange trackChange1) + trackChange1.Write(sw, "moveTo"); + else if (o is CT_MarkupRange markupRange) + markupRange.Write(sw, "moveToRangeEnd"); + else if (o is CT_MoveBookmark moveBookmark) + moveBookmark.Write(sw, "moveToRangeStart"); + else if (o is CT_Perm perm) + perm.Write(sw, "permEnd"); + else if (o is CT_PermStart start) + start.Write(sw, "permStart"); + else if (o is CT_ProofErr err) + err.Write(sw, "proofErr"); + else if (o is CT_Markup ctMarkup1) + ctMarkup1.Write(sw, "customXmlInsRangeEnd"); + else if (o is CT_Row ctRow) + ctRow.Write(sw, "tr"); + else if (o is CT_RunTrackChange runTrackChange1) + runTrackChange1.Write(sw, "del"); + else if (o is CT_MarkupRange ctMarkupRange) + ctMarkupRange.Write(sw, "bookmarkEnd"); + else if (o is CT_Bookmark ctBookmark) + ctBookmark.Write(sw, "bookmarkStart"); + else if (o is CT_MarkupRange range1) + range1.Write(sw, "commentRangeEnd"); + else if (o is CT_MarkupRange markupRange1) + markupRange1.Write(sw, "commentRangeStart"); + else if (o is CT_CustomXmlRow xmlRow) + xmlRow.Write(sw, "customXml"); } sw.WriteEndW(nodeName); } @@ -1002,70 +1002,70 @@ internal void Write(StreamWriter sw, string nodeName) sw.Write(">"); foreach (object o in this.Items) { - if (o is CT_Bookmark) - ((CT_Bookmark)o).Write(sw, "bookmarkStart"); - else if (o is CT_MoveBookmark) - ((CT_MoveBookmark)o).Write(sw, "moveFromRangeStart"); - else if (o is CT_RunTrackChange) - ((CT_RunTrackChange)o).Write(sw, "moveTo"); - else if (o is CT_OMath) - ((CT_OMath)o).Write(sw, "oMath"); - else if (o is CT_Markup) - ((CT_Markup)o).Write(sw, "customXmlDelRangeEnd"); - else if (o is CT_TrackChange) - ((CT_TrackChange)o).Write(sw, "customXmlDelRangeStart"); - else if (o is CT_Markup) - ((CT_Markup)o).Write(sw, "customXmlInsRangeEnd"); - else if (o is CT_TrackChange) - ((CT_TrackChange)o).Write(sw, "customXmlInsRangeStart"); - else if (o is CT_Markup) - ((CT_Markup)o).Write(sw, "customXmlMoveFromRangeEnd"); - else if (o is CT_TrackChange) - ((CT_TrackChange)o).Write(sw, "customXmlMoveFromRangeStart"); - else if (o is CT_Markup) - ((CT_Markup)o).Write(sw, "customXmlMoveToRangeEnd"); - else if (o is CT_TrackChange) - ((CT_TrackChange)o).Write(sw, "customXmlMoveToRangeStart"); - else if (o is CT_RunTrackChange) - ((CT_RunTrackChange)o).Write(sw, "del"); - else if (o is CT_MarkupRange) - ((CT_MarkupRange)o).Write(sw, "commentRangeEnd"); - else if (o is CT_SimpleField) - ((CT_SimpleField)o).Write(sw, "fldSimple"); - else if (o is CT_Hyperlink1) - ((CT_Hyperlink1)o).Write(sw, "hyperlink"); - else if (o is CT_RunTrackChange) - ((CT_RunTrackChange)o).Write(sw, "ins"); - else if (o is CT_RunTrackChange) - ((CT_RunTrackChange)o).Write(sw, "moveFrom"); - else if (o is CT_MarkupRange) - ((CT_MarkupRange)o).Write(sw, "moveFromRangeEnd"); - else if (o is CT_CustomXmlRun) - ((CT_CustomXmlRun)o).Write(sw, "customXml"); - else if (o is CT_MarkupRange) - ((CT_MarkupRange)o).Write(sw, "moveToRangeEnd"); - else if (o is CT_MoveBookmark) - ((CT_MoveBookmark)o).Write(sw, "moveToRangeStart"); - else if (o is CT_Perm) - ((CT_Perm)o).Write(sw, "permEnd"); - else if (o is CT_PermStart) - ((CT_PermStart)o).Write(sw, "permStart"); - else if (o is CT_MarkupRange) - ((CT_MarkupRange)o).Write(sw, "bookmarkEnd"); - else if (o is CT_R) - ((CT_R)o).Write(sw, "r"); - else if (o is CT_SdtRun) - ((CT_SdtRun)o).Write(sw, "sdt"); - else if (o is CT_SmartTagRun) - ((CT_SmartTagRun)o).Write(sw, "smartTag"); - else if (o is CT_Rel) - ((CT_Rel)o).Write(sw, "subDoc"); - else if (o is CT_ProofErr) - ((CT_ProofErr)o).Write(sw, "proofErr"); - else if (o is CT_MarkupRange) - ((CT_MarkupRange)o).Write(sw, "commentRangeStart"); - else if (o is CT_OMathPara) - ((CT_OMathPara)o).Write(sw, "oMathPara"); + if (o is CT_Bookmark bookmark) + bookmark.Write(sw, "bookmarkStart"); + else if (o is CT_MoveBookmark moveBookmark) + moveBookmark.Write(sw, "moveFromRangeStart"); + else if (o is CT_RunTrackChange change) + change.Write(sw, "moveTo"); + else if (o is CT_OMath math) + math.Write(sw, "oMath"); + else if (o is CT_Markup markup) + markup.Write(sw, "customXmlDelRangeEnd"); + else if (o is CT_TrackChange trackChange) + trackChange.Write(sw, "customXmlDelRangeStart"); + else if (o is CT_Markup ctMarkup) + ctMarkup.Write(sw, "customXmlInsRangeEnd"); + else if (o is CT_TrackChange ctTrackChange) + ctTrackChange.Write(sw, "customXmlInsRangeStart"); + else if (o is CT_Markup markup1) + markup1.Write(sw, "customXmlMoveFromRangeEnd"); + else if (o is CT_TrackChange change1) + change1.Write(sw, "customXmlMoveFromRangeStart"); + else if (o is CT_Markup ctMarkup1) + ctMarkup1.Write(sw, "customXmlMoveToRangeEnd"); + else if (o is CT_TrackChange trackChange1) + trackChange1.Write(sw, "customXmlMoveToRangeStart"); + else if (o is CT_RunTrackChange runTrackChange) + runTrackChange.Write(sw, "del"); + else if (o is CT_MarkupRange range) + range.Write(sw, "commentRangeEnd"); + else if (o is CT_SimpleField field) + field.Write(sw, "fldSimple"); + else if (o is CT_Hyperlink1 hyperlink1) + hyperlink1.Write(sw, "hyperlink"); + else if (o is CT_RunTrackChange ctRunTrackChange) + ctRunTrackChange.Write(sw, "ins"); + else if (o is CT_RunTrackChange runTrackChange1) + runTrackChange1.Write(sw, "moveFrom"); + else if (o is CT_MarkupRange markupRange) + markupRange.Write(sw, "moveFromRangeEnd"); + else if (o is CT_CustomXmlRun run) + run.Write(sw, "customXml"); + else if (o is CT_MarkupRange ctMarkupRange) + ctMarkupRange.Write(sw, "moveToRangeEnd"); + else if (o is CT_MoveBookmark ctMoveBookmark) + ctMoveBookmark.Write(sw, "moveToRangeStart"); + else if (o is CT_Perm perm) + perm.Write(sw, "permEnd"); + else if (o is CT_PermStart start) + start.Write(sw, "permStart"); + else if (o is CT_MarkupRange range1) + range1.Write(sw, "bookmarkEnd"); + else if (o is CT_R r) + r.Write(sw, "r"); + else if (o is CT_SdtRun sdtRun) + sdtRun.Write(sw, "sdt"); + else if (o is CT_SmartTagRun tagRun) + tagRun.Write(sw, "smartTag"); + else if (o is CT_Rel rel) + rel.Write(sw, "subDoc"); + else if (o is CT_ProofErr err) + err.Write(sw, "proofErr"); + else if (o is CT_MarkupRange markupRange1) + markupRange1.Write(sw, "commentRangeStart"); + else if (o is CT_OMathPara para) + para.Write(sw, "oMathPara"); } sw.WriteEndW(nodeName); } @@ -1494,70 +1494,70 @@ internal void Write(StreamWriter sw, string nodeName) } foreach (object o in this.Items) { - if (o is CT_TrackChange) - ((CT_TrackChange)o).Write(sw, "customXmlMoveToRangeStart"); - else if (o is CT_SimpleField) - ((CT_SimpleField)o).Write(sw, "fldSimple"); - else if (o is CT_Hyperlink1) - ((CT_Hyperlink1)o).Write(sw, "hyperlink"); - else if (o is CT_RunTrackChange) - ((CT_RunTrackChange)o).Write(sw, "ins"); - else if (o is CT_RunTrackChange) - ((CT_RunTrackChange)o).Write(sw, "moveFrom"); - else if (o is CT_MarkupRange) - ((CT_MarkupRange)o).Write(sw, "moveFromRangeEnd"); - else if (o is CT_MoveBookmark) - ((CT_MoveBookmark)o).Write(sw, "moveFromRangeStart"); - else if (o is CT_RunTrackChange) - ((CT_RunTrackChange)o).Write(sw, "moveTo"); - else if (o is CT_MarkupRange) - ((CT_MarkupRange)o).Write(sw, "moveToRangeEnd"); - else if (o is CT_MoveBookmark) - ((CT_MoveBookmark)o).Write(sw, "moveToRangeStart"); - else if (o is CT_Perm) - ((CT_Perm)o).Write(sw, "permEnd"); - else if (o is CT_PermStart) - ((CT_PermStart)o).Write(sw, "permStart"); - else if (o is CT_ProofErr) - ((CT_ProofErr)o).Write(sw, "proofErr"); - else if (o is CT_R) - ((CT_R)o).Write(sw, "r"); - else if (o is CT_SdtRun) - ((CT_SdtRun)o).Write(sw, "sdt"); - else if (o is CT_SmartTagRun) - ((CT_SmartTagRun)o).Write(sw, "smartTag"); - else if (o is CT_Rel) - ((CT_Rel)o).Write(sw, "subDoc"); - else if (o is CT_OMath) - ((CT_OMath)o).Write(sw, "oMath"); - else if (o is CT_RunTrackChange) - ((CT_RunTrackChange)o).Write(sw, "del"); - else if (o is CT_OMathPara) - ((CT_OMathPara)o).Write(sw, "oMathPara"); - else if (o is CT_MarkupRange) - ((CT_MarkupRange)o).Write(sw, "bookmarkEnd"); - else if (o is CT_Bookmark) - ((CT_Bookmark)o).Write(sw, "bookmarkStart"); - else if (o is CT_MarkupRange) - ((CT_MarkupRange)o).Write(sw, "commentRangeEnd"); - else if (o is CT_MarkupRange) - ((CT_MarkupRange)o).Write(sw, "commentRangeStart"); - else if (o is CT_CustomXmlRun) - ((CT_CustomXmlRun)o).Write(sw, "customXml"); - else if (o is CT_Markup) - ((CT_Markup)o).Write(sw, "customXmlDelRangeEnd"); - else if (o is CT_TrackChange) - ((CT_TrackChange)o).Write(sw, "customXmlDelRangeStart"); - else if (o is CT_Markup) - ((CT_Markup)o).Write(sw, "customXmlInsRangeEnd"); - else if (o is CT_TrackChange) - ((CT_TrackChange)o).Write(sw, "customXmlInsRangeStart"); - else if (o is CT_Markup) - ((CT_Markup)o).Write(sw, "customXmlMoveFromRangeEnd"); - else if (o is CT_TrackChange) - ((CT_TrackChange)o).Write(sw, "customXmlMoveFromRangeStart"); - else if (o is CT_Markup) - ((CT_Markup)o).Write(sw, "customXmlMoveToRangeEnd"); + if (o is CT_TrackChange change) + change.Write(sw, "customXmlMoveToRangeStart"); + else if (o is CT_SimpleField field) + field.Write(sw, "fldSimple"); + else if (o is CT_Hyperlink1 hyperlink1) + hyperlink1.Write(sw, "hyperlink"); + else if (o is CT_RunTrackChange trackChange) + trackChange.Write(sw, "ins"); + else if (o is CT_RunTrackChange runTrackChange) + runTrackChange.Write(sw, "moveFrom"); + else if (o is CT_MarkupRange range) + range.Write(sw, "moveFromRangeEnd"); + else if (o is CT_MoveBookmark bookmark) + bookmark.Write(sw, "moveFromRangeStart"); + else if (o is CT_RunTrackChange ctRunTrackChange) + ctRunTrackChange.Write(sw, "moveTo"); + else if (o is CT_MarkupRange markupRange) + markupRange.Write(sw, "moveToRangeEnd"); + else if (o is CT_MoveBookmark moveBookmark) + moveBookmark.Write(sw, "moveToRangeStart"); + else if (o is CT_Perm perm) + perm.Write(sw, "permEnd"); + else if (o is CT_PermStart start) + start.Write(sw, "permStart"); + else if (o is CT_ProofErr err) + err.Write(sw, "proofErr"); + else if (o is CT_R r) + r.Write(sw, "r"); + else if (o is CT_SdtRun run) + run.Write(sw, "sdt"); + else if (o is CT_SmartTagRun tagRun) + tagRun.Write(sw, "smartTag"); + else if (o is CT_Rel rel) + rel.Write(sw, "subDoc"); + else if (o is CT_OMath math) + math.Write(sw, "oMath"); + else if (o is CT_RunTrackChange change1) + change1.Write(sw, "del"); + else if (o is CT_OMathPara para) + para.Write(sw, "oMathPara"); + else if (o is CT_MarkupRange ctMarkupRange) + ctMarkupRange.Write(sw, "bookmarkEnd"); + else if (o is CT_Bookmark ctBookmark) + ctBookmark.Write(sw, "bookmarkStart"); + else if (o is CT_MarkupRange range1) + range1.Write(sw, "commentRangeEnd"); + else if (o is CT_MarkupRange markupRange1) + markupRange1.Write(sw, "commentRangeStart"); + else if (o is CT_CustomXmlRun xmlRun) + xmlRun.Write(sw, "customXml"); + else if (o is CT_Markup markup) + markup.Write(sw, "customXmlDelRangeEnd"); + else if (o is CT_TrackChange ctTrackChange) + ctTrackChange.Write(sw, "customXmlDelRangeStart"); + else if (o is CT_Markup ctMarkup) + ctMarkup.Write(sw, "customXmlInsRangeEnd"); + else if (o is CT_TrackChange trackChange1) + trackChange1.Write(sw, "customXmlInsRangeStart"); + else if (o is CT_Markup markup1) + markup1.Write(sw, "customXmlMoveFromRangeEnd"); + else if (o is CT_TrackChange ctTrackChange1) + ctTrackChange1.Write(sw, "customXmlMoveFromRangeStart"); + else if (o is CT_Markup ctMarkup1) + ctMarkup1.Write(sw, "customXmlMoveToRangeEnd"); } sw.WriteEndW(nodeName); } @@ -1873,64 +1873,64 @@ internal void Write(StreamWriter sw, string nodeName) sw.Write(">"); foreach (object o in this.Items) { - if (o is CT_RunTrackChange) - ((CT_RunTrackChange)o).Write(sw, "del"); - else if (o is CT_RunTrackChange) - ((CT_RunTrackChange)o).Write(sw, "moveFrom"); - else if (o is CT_RunTrackChange) - ((CT_RunTrackChange)o).Write(sw, "moveTo"); - else if (o is CT_Bookmark) - ((CT_Bookmark)o).Write(sw, "bookmarkStart"); - else if (o is CT_MarkupRange) - ((CT_MarkupRange)o).Write(sw, "commentRangeStart"); - else if (o is CT_CustomXmlBlock) - ((CT_CustomXmlBlock)o).Write(sw, "customXml"); - else if (o is CT_Markup) - ((CT_Markup)o).Write(sw, "customXmlDelRangeEnd"); - else if (o is CT_TrackChange) - ((CT_TrackChange)o).Write(sw, "customXmlDelRangeStart"); - else if (o is CT_Markup) - ((CT_Markup)o).Write(sw, "customXmlInsRangeEnd"); - else if (o is CT_TrackChange) - ((CT_TrackChange)o).Write(sw, "customXmlInsRangeStart"); - else if (o is CT_Markup) - ((CT_Markup)o).Write(sw, "customXmlMoveFromRangeEnd"); - else if (o is CT_TrackChange) - ((CT_TrackChange)o).Write(sw, "customXmlMoveFromRangeStart"); - else if (o is CT_Markup) - ((CT_Markup)o).Write(sw, "customXmlMoveToRangeEnd"); - else if (o is CT_TrackChange) - ((CT_TrackChange)o).Write(sw, "customXmlMoveToRangeStart"); - else if (o is CT_OMath) - ((CT_OMath)o).Write(sw, "oMath"); - else if (o is CT_RunTrackChange) - ((CT_RunTrackChange)o).Write(sw, "ins"); - else if (o is CT_MarkupRange) - ((CT_MarkupRange)o).Write(sw, "moveFromRangeEnd"); - else if (o is CT_MoveBookmark) - ((CT_MoveBookmark)o).Write(sw, "moveFromRangeStart"); - else if (o is CT_MarkupRange) - ((CT_MarkupRange)o).Write(sw, "commentRangeEnd"); - else if (o is CT_MarkupRange) - ((CT_MarkupRange)o).Write(sw, "moveToRangeEnd"); - else if (o is CT_MoveBookmark) - ((CT_MoveBookmark)o).Write(sw, "moveToRangeStart"); - else if (o is CT_P) - ((CT_P)o).Write(sw, "p"); - else if (o is CT_Perm) - ((CT_Perm)o).Write(sw, "permEnd"); - else if (o is CT_MarkupRange) - ((CT_MarkupRange)o).Write(sw, "bookmarkEnd"); - else if (o is CT_ProofErr) - ((CT_ProofErr)o).Write(sw, "proofErr"); - else if (o is CT_SdtBlock) - ((CT_SdtBlock)o).Write(sw, "sdt"); - else if (o is CT_Tbl) - ((CT_Tbl)o).Write(sw, "tbl"); - else if (o is CT_PermStart) - ((CT_PermStart)o).Write(sw, "permStart"); - else if (o is CT_OMathPara) - ((CT_OMathPara)o).Write(sw, "oMathPara"); + if (o is CT_RunTrackChange change) + change.Write(sw, "del"); + else if (o is CT_RunTrackChange trackChange) + trackChange.Write(sw, "moveFrom"); + else if (o is CT_RunTrackChange runTrackChange) + runTrackChange.Write(sw, "moveTo"); + else if (o is CT_Bookmark bookmark) + bookmark.Write(sw, "bookmarkStart"); + else if (o is CT_MarkupRange range) + range.Write(sw, "commentRangeStart"); + else if (o is CT_CustomXmlBlock block) + block.Write(sw, "customXml"); + else if (o is CT_Markup markup) + markup.Write(sw, "customXmlDelRangeEnd"); + else if (o is CT_TrackChange ctTrackChange) + ctTrackChange.Write(sw, "customXmlDelRangeStart"); + else if (o is CT_Markup ctMarkup) + ctMarkup.Write(sw, "customXmlInsRangeEnd"); + else if (o is CT_TrackChange change1) + change1.Write(sw, "customXmlInsRangeStart"); + else if (o is CT_Markup markup1) + markup1.Write(sw, "customXmlMoveFromRangeEnd"); + else if (o is CT_TrackChange trackChange1) + trackChange1.Write(sw, "customXmlMoveFromRangeStart"); + else if (o is CT_Markup ctMarkup1) + ctMarkup1.Write(sw, "customXmlMoveToRangeEnd"); + else if (o is CT_TrackChange ctTrackChange1) + ctTrackChange1.Write(sw, "customXmlMoveToRangeStart"); + else if (o is CT_OMath math) + math.Write(sw, "oMath"); + else if (o is CT_RunTrackChange ctRunTrackChange) + ctRunTrackChange.Write(sw, "ins"); + else if (o is CT_MarkupRange markupRange) + markupRange.Write(sw, "moveFromRangeEnd"); + else if (o is CT_MoveBookmark moveBookmark) + moveBookmark.Write(sw, "moveFromRangeStart"); + else if (o is CT_MarkupRange ctMarkupRange) + ctMarkupRange.Write(sw, "commentRangeEnd"); + else if (o is CT_MarkupRange range1) + range1.Write(sw, "moveToRangeEnd"); + else if (o is CT_MoveBookmark ctMoveBookmark) + ctMoveBookmark.Write(sw, "moveToRangeStart"); + else if (o is CT_P p) + p.Write(sw, "p"); + else if (o is CT_Perm perm) + perm.Write(sw, "permEnd"); + else if (o is CT_MarkupRange markupRange1) + markupRange1.Write(sw, "bookmarkEnd"); + else if (o is CT_ProofErr err) + err.Write(sw, "proofErr"); + else if (o is CT_SdtBlock sdtBlock) + sdtBlock.Write(sw, "sdt"); + else if (o is CT_Tbl tbl) + tbl.Write(sw, "tbl"); + else if (o is CT_PermStart start) + start.Write(sw, "permStart"); + else if (o is CT_OMathPara para) + para.Write(sw, "oMathPara"); } sw.WriteEndW(nodeName); } @@ -2306,62 +2306,62 @@ internal void Write(StreamWriter sw, string nodeName) this.customXmlPr.Write(sw, "customXmlPr"); foreach (object o in this.Items) { - if (o is CT_TrackChange) - ((CT_TrackChange)o).Write(sw, "customXmlMoveToRangeStart"); - else if (o is CT_Markup) - ((CT_Markup)o).Write(sw, "customXmlMoveFromRangeEnd"); - else if (o is CT_SdtCell) - ((CT_SdtCell)o).Write(sw, "sdt"); - else if (o is CT_Tc) - ((CT_Tc)o).Write(sw, "tc"); - else if (o is CT_Perm) - ((CT_Perm)o).Write(sw, "permEnd"); - else if (o is CT_TrackChange) - ((CT_TrackChange)o).Write(sw, "customXmlInsRangeStart"); - else if (o is CT_RunTrackChange) - ((CT_RunTrackChange)o).Write(sw, "del"); - else if (o is CT_RunTrackChange) - ((CT_RunTrackChange)o).Write(sw, "ins"); - else if (o is CT_RunTrackChange) - ((CT_RunTrackChange)o).Write(sw, "moveFrom"); - else if (o is CT_MarkupRange) - ((CT_MarkupRange)o).Write(sw, "moveFromRangeEnd"); - else if (o is CT_MoveBookmark) - ((CT_MoveBookmark)o).Write(sw, "moveFromRangeStart"); - else if (o is CT_RunTrackChange) - ((CT_RunTrackChange)o).Write(sw, "moveTo"); - else if (o is CT_MarkupRange) - ((CT_MarkupRange)o).Write(sw, "moveToRangeEnd"); - else if (o is CT_MoveBookmark) - ((CT_MoveBookmark)o).Write(sw, "moveToRangeStart"); - else if (o is CT_Markup) - ((CT_Markup)o).Write(sw, "customXmlMoveToRangeEnd"); - else if (o is CT_PermStart) - ((CT_PermStart)o).Write(sw, "permStart"); - else if (o is CT_ProofErr) - ((CT_ProofErr)o).Write(sw, "proofErr"); - else if (o is CT_TrackChange) - ((CT_TrackChange)o).Write(sw, "customXmlMoveFromRangeStart"); - else if (o is CT_OMath) - ((CT_OMath)o).Write(sw, "oMath"); - else if (o is CT_OMathPara) - ((CT_OMathPara)o).Write(sw, "oMathPara"); - else if (o is CT_MarkupRange) - ((CT_MarkupRange)o).Write(sw, "bookmarkEnd"); - else if (o is CT_Bookmark) - ((CT_Bookmark)o).Write(sw, "bookmarkStart"); - else if (o is CT_MarkupRange) - ((CT_MarkupRange)o).Write(sw, "commentRangeEnd"); - else if (o is CT_MarkupRange) - ((CT_MarkupRange)o).Write(sw, "commentRangeStart"); - else if (o is CT_CustomXmlCell) - ((CT_CustomXmlCell)o).Write(sw, "customXml"); - else if (o is CT_Markup) - ((CT_Markup)o).Write(sw, "customXmlDelRangeEnd"); - else if (o is CT_TrackChange) - ((CT_TrackChange)o).Write(sw, "customXmlDelRangeStart"); - else if (o is CT_Markup) - ((CT_Markup)o).Write(sw, "customXmlInsRangeEnd"); + if (o is CT_TrackChange change) + change.Write(sw, "customXmlMoveToRangeStart"); + else if (o is CT_Markup markup) + markup.Write(sw, "customXmlMoveFromRangeEnd"); + else if (o is CT_SdtCell cell) + cell.Write(sw, "sdt"); + else if (o is CT_Tc tc) + tc.Write(sw, "tc"); + else if (o is CT_Perm perm) + perm.Write(sw, "permEnd"); + else if (o is CT_TrackChange trackChange) + trackChange.Write(sw, "customXmlInsRangeStart"); + else if (o is CT_RunTrackChange runTrackChange) + runTrackChange.Write(sw, "del"); + else if (o is CT_RunTrackChange ctRunTrackChange) + ctRunTrackChange.Write(sw, "ins"); + else if (o is CT_RunTrackChange change1) + change1.Write(sw, "moveFrom"); + else if (o is CT_MarkupRange range) + range.Write(sw, "moveFromRangeEnd"); + else if (o is CT_MoveBookmark bookmark) + bookmark.Write(sw, "moveFromRangeStart"); + else if (o is CT_RunTrackChange trackChange1) + trackChange1.Write(sw, "moveTo"); + else if (o is CT_MarkupRange markupRange) + markupRange.Write(sw, "moveToRangeEnd"); + else if (o is CT_MoveBookmark moveBookmark) + moveBookmark.Write(sw, "moveToRangeStart"); + else if (o is CT_Markup ctMarkup) + ctMarkup.Write(sw, "customXmlMoveToRangeEnd"); + else if (o is CT_PermStart start) + start.Write(sw, "permStart"); + else if (o is CT_ProofErr err) + err.Write(sw, "proofErr"); + else if (o is CT_TrackChange ctTrackChange) + ctTrackChange.Write(sw, "customXmlMoveFromRangeStart"); + else if (o is CT_OMath math) + math.Write(sw, "oMath"); + else if (o is CT_OMathPara para) + para.Write(sw, "oMathPara"); + else if (o is CT_MarkupRange ctMarkupRange) + ctMarkupRange.Write(sw, "bookmarkEnd"); + else if (o is CT_Bookmark ctBookmark) + ctBookmark.Write(sw, "bookmarkStart"); + else if (o is CT_MarkupRange range1) + range1.Write(sw, "commentRangeEnd"); + else if (o is CT_MarkupRange markupRange1) + markupRange1.Write(sw, "commentRangeStart"); + else if (o is CT_CustomXmlCell xmlCell) + xmlCell.Write(sw, "customXml"); + else if (o is CT_Markup markup1) + markup1.Write(sw, "customXmlDelRangeEnd"); + else if (o is CT_TrackChange ctTrackChange1) + ctTrackChange1.Write(sw, "customXmlDelRangeStart"); + else if (o is CT_Markup ctMarkup1) + ctMarkup1.Write(sw, "customXmlInsRangeEnd"); } sw.WriteEndW(nodeName); } diff --git a/OpenXmlFormats/Wordprocessing/Document.cs b/OpenXmlFormats/Wordprocessing/Document.cs index 3a02611db..73246b2b3 100644 --- a/OpenXmlFormats/Wordprocessing/Document.cs +++ b/OpenXmlFormats/Wordprocessing/Document.cs @@ -338,66 +338,66 @@ internal void Write(StreamWriter sw, string nodeName) int i=0; foreach(object o in this.Items) { - if(o is CT_RunTrackChange && this.itemsElementNameField[i] == DocumentBodyItemChoiceType.moveTo) - ((CT_RunTrackChange) o).Write(sw, "moveTo"); - else if(o is CT_OMathPara) - ((CT_OMathPara) o).Write(sw, "oMathPara"); - else if(o is CT_CustomXmlBlock) - ((CT_CustomXmlBlock) o).Write(sw, "customXml"); - else if(o is CT_OMath) - ((CT_OMath) o).Write(sw, "oMath"); - else if(o is CT_AltChunk) - ((CT_AltChunk) o).Write(sw, "altChunk"); - else if((o is CT_MarkupRange)&&this.itemsElementNameField[i]== DocumentBodyItemChoiceType.bookmarkEnd) - ((CT_MarkupRange) o).Write(sw, "bookmarkEnd"); - else if(o is CT_Bookmark && this.itemsElementNameField[i] == DocumentBodyItemChoiceType.bookmarkStart) - ((CT_Bookmark) o).Write(sw, "bookmarkStart"); - else if(o is CT_MarkupRange && this.itemsElementNameField[i] == DocumentBodyItemChoiceType.commentRangeEnd) - ((CT_MarkupRange) o).Write(sw, "commentRangeEnd"); - else if(o is CT_MarkupRange && this.itemsElementNameField[i] == DocumentBodyItemChoiceType.commentRangeStart) - ((CT_MarkupRange) o).Write(sw, "commentRangeStart"); - else if(o is CT_Markup && this.itemsElementNameField[i] == DocumentBodyItemChoiceType.customXmlDelRangeEnd) - ((CT_Markup) o).Write(sw, "customXmlDelRangeEnd"); - else if(o is CT_TrackChange && this.itemsElementNameField[i] == DocumentBodyItemChoiceType.customXmlDelRangeStart) - ((CT_TrackChange) o).Write(sw, "customXmlDelRangeStart"); - else if(o is CT_Markup && this.itemsElementNameField[i] == DocumentBodyItemChoiceType.customXmlInsRangeEnd) - ((CT_Markup) o).Write(sw, "customXmlInsRangeEnd"); - else if(o is CT_TrackChange && this.itemsElementNameField[i] == DocumentBodyItemChoiceType.customXmlInsRangeStart) - ((CT_TrackChange) o).Write(sw, "customXmlInsRangeStart"); - else if(o is CT_Markup && this.itemsElementNameField[i] == DocumentBodyItemChoiceType.customXmlMoveFromRangeEnd) - ((CT_Markup) o).Write(sw, "customXmlMoveFromRangeEnd"); - else if(o is CT_TrackChange && this.itemsElementNameField[i] == DocumentBodyItemChoiceType.customXmlMoveFromRangeStart) - ((CT_TrackChange) o).Write(sw, "customXmlMoveFromRangeStart"); - else if(o is CT_Markup && this.itemsElementNameField[i] == DocumentBodyItemChoiceType.customXmlMoveToRangeEnd) - ((CT_Markup) o).Write(sw, "customXmlMoveToRangeEnd"); - else if(o is CT_TrackChange && this.itemsElementNameField[i] == DocumentBodyItemChoiceType.customXmlMoveToRangeStart) - ((CT_TrackChange) o).Write(sw, "customXmlMoveToRangeStart"); - else if(o is CT_RunTrackChange && this.itemsElementNameField[i] == DocumentBodyItemChoiceType.del) - ((CT_RunTrackChange) o).Write(sw, "del"); - else if(o is CT_RunTrackChange && this.itemsElementNameField[i] == DocumentBodyItemChoiceType.ins) - ((CT_RunTrackChange) o).Write(sw, "ins"); - else if(o is CT_RunTrackChange && this.itemsElementNameField[i] == DocumentBodyItemChoiceType.moveFrom) - ((CT_RunTrackChange) o).Write(sw, "moveFrom"); - else if(o is CT_MarkupRange && this.itemsElementNameField[i] == DocumentBodyItemChoiceType.moveFromRangeEnd) - ((CT_MarkupRange) o).Write(sw, "moveFromRangeEnd"); - else if(o is CT_MoveBookmark && this.itemsElementNameField[i] == DocumentBodyItemChoiceType.moveFromRangeStart) - ((CT_MoveBookmark) o).Write(sw, "moveFromRangeStart"); - else if(o is CT_MarkupRange && this.itemsElementNameField[i] == DocumentBodyItemChoiceType.moveToRangeEnd) - ((CT_MarkupRange) o).Write(sw, "moveToRangeEnd"); - else if(o is CT_MoveBookmark && this.itemsElementNameField[i] == DocumentBodyItemChoiceType.moveToRangeStart) - ((CT_MoveBookmark) o).Write(sw, "moveToRangeStart"); - else if(o is CT_P) - ((CT_P) o).Write(sw, "p"); - else if(o is CT_Perm) - ((CT_Perm) o).Write(sw, "permEnd"); - else if(o is CT_PermStart) - ((CT_PermStart) o).Write(sw, "permStart"); - else if(o is CT_ProofErr) - ((CT_ProofErr) o).Write(sw, "proofErr"); - else if(o is CT_SdtBlock) - ((CT_SdtBlock) o).Write(sw, "sdt"); - else if(o is CT_Tbl) - ((CT_Tbl) o).Write(sw, "tbl"); + if(o is CT_RunTrackChange change && this.itemsElementNameField[i] == DocumentBodyItemChoiceType.moveTo) + change.Write(sw, "moveTo"); + else if(o is CT_OMathPara para) + para.Write(sw, "oMathPara"); + else if(o is CT_CustomXmlBlock block) + block.Write(sw, "customXml"); + else if(o is CT_OMath math) + math.Write(sw, "oMath"); + else if(o is CT_AltChunk chunk) + chunk.Write(sw, "altChunk"); + else if((o is CT_MarkupRange range)&&this.itemsElementNameField[i]== DocumentBodyItemChoiceType.bookmarkEnd) + range.Write(sw, "bookmarkEnd"); + else if(o is CT_Bookmark bookmark && this.itemsElementNameField[i] == DocumentBodyItemChoiceType.bookmarkStart) + bookmark.Write(sw, "bookmarkStart"); + else if(o is CT_MarkupRange markupRange && this.itemsElementNameField[i] == DocumentBodyItemChoiceType.commentRangeEnd) + markupRange.Write(sw, "commentRangeEnd"); + else if(o is CT_MarkupRange ctMarkupRange && this.itemsElementNameField[i] == DocumentBodyItemChoiceType.commentRangeStart) + ctMarkupRange.Write(sw, "commentRangeStart"); + else if(o is CT_Markup markup && this.itemsElementNameField[i] == DocumentBodyItemChoiceType.customXmlDelRangeEnd) + markup.Write(sw, "customXmlDelRangeEnd"); + else if(o is CT_TrackChange trackChange && this.itemsElementNameField[i] == DocumentBodyItemChoiceType.customXmlDelRangeStart) + trackChange.Write(sw, "customXmlDelRangeStart"); + else if(o is CT_Markup ctMarkup && this.itemsElementNameField[i] == DocumentBodyItemChoiceType.customXmlInsRangeEnd) + ctMarkup.Write(sw, "customXmlInsRangeEnd"); + else if(o is CT_TrackChange ctTrackChange && this.itemsElementNameField[i] == DocumentBodyItemChoiceType.customXmlInsRangeStart) + ctTrackChange.Write(sw, "customXmlInsRangeStart"); + else if(o is CT_Markup markup1 && this.itemsElementNameField[i] == DocumentBodyItemChoiceType.customXmlMoveFromRangeEnd) + markup1.Write(sw, "customXmlMoveFromRangeEnd"); + else if(o is CT_TrackChange change1 && this.itemsElementNameField[i] == DocumentBodyItemChoiceType.customXmlMoveFromRangeStart) + change1.Write(sw, "customXmlMoveFromRangeStart"); + else if(o is CT_Markup ctMarkup1 && this.itemsElementNameField[i] == DocumentBodyItemChoiceType.customXmlMoveToRangeEnd) + ctMarkup1.Write(sw, "customXmlMoveToRangeEnd"); + else if(o is CT_TrackChange trackChange1 && this.itemsElementNameField[i] == DocumentBodyItemChoiceType.customXmlMoveToRangeStart) + trackChange1.Write(sw, "customXmlMoveToRangeStart"); + else if(o is CT_RunTrackChange runTrackChange && this.itemsElementNameField[i] == DocumentBodyItemChoiceType.del) + runTrackChange.Write(sw, "del"); + else if(o is CT_RunTrackChange ctRunTrackChange && this.itemsElementNameField[i] == DocumentBodyItemChoiceType.ins) + ctRunTrackChange.Write(sw, "ins"); + else if(o is CT_RunTrackChange runTrackChange1 && this.itemsElementNameField[i] == DocumentBodyItemChoiceType.moveFrom) + runTrackChange1.Write(sw, "moveFrom"); + else if(o is CT_MarkupRange range1 && this.itemsElementNameField[i] == DocumentBodyItemChoiceType.moveFromRangeEnd) + range1.Write(sw, "moveFromRangeEnd"); + else if(o is CT_MoveBookmark moveBookmark && this.itemsElementNameField[i] == DocumentBodyItemChoiceType.moveFromRangeStart) + moveBookmark.Write(sw, "moveFromRangeStart"); + else if(o is CT_MarkupRange markupRange1 && this.itemsElementNameField[i] == DocumentBodyItemChoiceType.moveToRangeEnd) + markupRange1.Write(sw, "moveToRangeEnd"); + else if(o is CT_MoveBookmark ctMoveBookmark && this.itemsElementNameField[i] == DocumentBodyItemChoiceType.moveToRangeStart) + ctMoveBookmark.Write(sw, "moveToRangeStart"); + else if(o is CT_P p) + p.Write(sw, "p"); + else if(o is CT_Perm perm) + perm.Write(sw, "permEnd"); + else if(o is CT_PermStart start) + start.Write(sw, "permStart"); + else if(o is CT_ProofErr err) + err.Write(sw, "proofErr"); + else if(o is CT_SdtBlock sdtBlock) + sdtBlock.Write(sw, "sdt"); + else if(o is CT_Tbl tbl) + tbl.Write(sw, "tbl"); i++; } if(this.sectPr != null) diff --git a/OpenXmlFormats/Wordprocessing/FormField.cs b/OpenXmlFormats/Wordprocessing/FormField.cs index a506bb35c..ec633aad2 100644 --- a/OpenXmlFormats/Wordprocessing/FormField.cs +++ b/OpenXmlFormats/Wordprocessing/FormField.cs @@ -637,8 +637,8 @@ internal void Write(StreamWriter sw, string nodeName) this.checkedField.Write(sw, "checked"); if (this.itemField != null) { - if (this.itemField is CT_OnOff) - (this.itemField as CT_OnOff).Write(sw, "sizeAuto"); + if (this.itemField is CT_OnOff off) + off.Write(sw, "sizeAuto"); else (this.itemField as CT_HpsMeasure).Write(sw, "size"); } diff --git a/OpenXmlFormats/Wordprocessing/HdrFtr.cs b/OpenXmlFormats/Wordprocessing/HdrFtr.cs index e08c950c8..89a9c8061 100644 --- a/OpenXmlFormats/Wordprocessing/HdrFtr.cs +++ b/OpenXmlFormats/Wordprocessing/HdrFtr.cs @@ -204,66 +204,66 @@ internal void Write(StreamWriter sw, string nodeName) sw.Write("mc:Ignorable=\"w14 w15 w16se w16cid w16 w16cex w16sdtdh wp14\">"); foreach (object o in this.Items) { - if (o is CT_TrackChange) - ((CT_TrackChange)o).Write(sw, "customXmlInsRangeStart"); - else if (o is CT_TrackChange) - ((CT_TrackChange)o).Write(sw, "customXmlMoveFromRangeStart"); - else if (o is CT_Markup) - ((CT_Markup)o).Write(sw, "customXmlMoveToRangeEnd"); - else if (o is CT_TrackChange) - ((CT_TrackChange)o).Write(sw, "customXmlMoveToRangeStart"); - else if (o is CT_RunTrackChange) - ((CT_RunTrackChange)o).Write(sw, "del"); - else if (o is CT_RunTrackChange) - ((CT_RunTrackChange)o).Write(sw, "ins"); - else if (o is CT_RunTrackChange) - ((CT_RunTrackChange)o).Write(sw, "moveFrom"); - else if (o is CT_MarkupRange) - ((CT_MarkupRange)o).Write(sw, "moveFromRangeEnd"); - else if (o is CT_MoveBookmark) - ((CT_MoveBookmark)o).Write(sw, "moveFromRangeStart"); - else if (o is CT_RunTrackChange) - ((CT_RunTrackChange)o).Write(sw, "moveTo"); - else if (o is CT_MarkupRange) - ((CT_MarkupRange)o).Write(sw, "moveToRangeEnd"); - else if (o is CT_MoveBookmark) - ((CT_MoveBookmark)o).Write(sw, "moveToRangeStart"); - else if (o is CT_P) - ((CT_P)o).Write(sw, "p"); - else if (o is CT_Perm) - ((CT_Perm)o).Write(sw, "permEnd"); - else if (o is CT_PermStart) - ((CT_PermStart)o).Write(sw, "permStart"); - else if (o is CT_ProofErr) - ((CT_ProofErr)o).Write(sw, "proofErr"); - else if (o is CT_SdtBlock) - ((CT_SdtBlock)o).Write(sw, "sdt"); - else if (o is CT_Tbl) - ((CT_Tbl)o).Write(sw, "tbl"); - else if (o is CT_Markup) - ((CT_Markup)o).Write(sw, "customXmlMoveFromRangeEnd"); - else if (o is CT_OMath) - ((CT_OMath)o).Write(sw, "oMath"); - else if (o is CT_OMathPara) - ((CT_OMathPara)o).Write(sw, "oMathPara"); - else if (o is CT_AltChunk) - ((CT_AltChunk)o).Write(sw, "altChunk"); - else if (o is CT_MarkupRange) - ((CT_MarkupRange)o).Write(sw, "bookmarkEnd"); - else if (o is CT_Bookmark) - ((CT_Bookmark)o).Write(sw, "bookmarkStart"); - else if (o is CT_MarkupRange) - ((CT_MarkupRange)o).Write(sw, "commentRangeEnd"); - else if (o is CT_MarkupRange) - ((CT_MarkupRange)o).Write(sw, "commentRangeStart"); - else if (o is CT_CustomXmlBlock) - ((CT_CustomXmlBlock)o).Write(sw, "customXml"); - else if (o is CT_Markup) - ((CT_Markup)o).Write(sw, "customXmlDelRangeEnd"); - else if (o is CT_TrackChange) - ((CT_TrackChange)o).Write(sw, "customXmlDelRangeStart"); - else if (o is CT_Markup) - ((CT_Markup)o).Write(sw, "customXmlInsRangeEnd"); + if (o is CT_TrackChange change) + change.Write(sw, "customXmlInsRangeStart"); + else if (o is CT_TrackChange trackChange) + trackChange.Write(sw, "customXmlMoveFromRangeStart"); + else if (o is CT_Markup markup) + markup.Write(sw, "customXmlMoveToRangeEnd"); + else if (o is CT_TrackChange ctTrackChange) + ctTrackChange.Write(sw, "customXmlMoveToRangeStart"); + else if (o is CT_RunTrackChange runTrackChange) + runTrackChange.Write(sw, "del"); + else if (o is CT_RunTrackChange ctRunTrackChange) + ctRunTrackChange.Write(sw, "ins"); + else if (o is CT_RunTrackChange change1) + change1.Write(sw, "moveFrom"); + else if (o is CT_MarkupRange range) + range.Write(sw, "moveFromRangeEnd"); + else if (o is CT_MoveBookmark bookmark) + bookmark.Write(sw, "moveFromRangeStart"); + else if (o is CT_RunTrackChange trackChange1) + trackChange1.Write(sw, "moveTo"); + else if (o is CT_MarkupRange markupRange) + markupRange.Write(sw, "moveToRangeEnd"); + else if (o is CT_MoveBookmark moveBookmark) + moveBookmark.Write(sw, "moveToRangeStart"); + else if (o is CT_P p) + p.Write(sw, "p"); + else if (o is CT_Perm perm) + perm.Write(sw, "permEnd"); + else if (o is CT_PermStart start) + start.Write(sw, "permStart"); + else if (o is CT_ProofErr err) + err.Write(sw, "proofErr"); + else if (o is CT_SdtBlock block) + block.Write(sw, "sdt"); + else if (o is CT_Tbl tbl) + tbl.Write(sw, "tbl"); + else if (o is CT_Markup ctMarkup) + ctMarkup.Write(sw, "customXmlMoveFromRangeEnd"); + else if (o is CT_OMath math) + math.Write(sw, "oMath"); + else if (o is CT_OMathPara para) + para.Write(sw, "oMathPara"); + else if (o is CT_AltChunk chunk) + chunk.Write(sw, "altChunk"); + else if (o is CT_MarkupRange ctMarkupRange) + ctMarkupRange.Write(sw, "bookmarkEnd"); + else if (o is CT_Bookmark ctBookmark) + ctBookmark.Write(sw, "bookmarkStart"); + else if (o is CT_MarkupRange range1) + range1.Write(sw, "commentRangeEnd"); + else if (o is CT_MarkupRange markupRange1) + markupRange1.Write(sw, "commentRangeStart"); + else if (o is CT_CustomXmlBlock xmlBlock) + xmlBlock.Write(sw, "customXml"); + else if (o is CT_Markup markup1) + markup1.Write(sw, "customXmlDelRangeEnd"); + else if (o is CT_TrackChange ctTrackChange1) + ctTrackChange1.Write(sw, "customXmlDelRangeStart"); + else if (o is CT_Markup ctMarkup1) + ctMarkup1.Write(sw, "customXmlInsRangeEnd"); } sw.WriteEndW(nodeName); } @@ -1053,66 +1053,66 @@ internal void Write(StreamWriter sw, string nodeName) int i = 0; foreach (object o in this.Items) { - if (o is CT_TrackChange&& this.itemsElementNameField[i]== ItemsChoiceType7.customXmlDelRangeStart) - ((CT_TrackChange)o).Write(sw, "customXmlDelRangeStart"); - else if (o is CT_MarkupRange && this.itemsElementNameField[i] == ItemsChoiceType7.moveToRangeEnd) - ((CT_MarkupRange)o).Write(sw, "moveToRangeEnd"); - else if (o is CT_Markup && this.itemsElementNameField[i] == ItemsChoiceType7.customXmlMoveFromRangeEnd) - ((CT_Markup)o).Write(sw, "customXmlMoveFromRangeEnd"); - else if (o is CT_RunTrackChange && this.itemsElementNameField[i] == ItemsChoiceType7.ins) - ((CT_RunTrackChange)o).Write(sw, "ins"); - else if (o is CT_Markup && this.itemsElementNameField[i] == ItemsChoiceType7.customXmlDelRangeEnd) - ((CT_Markup)o).Write(sw, "customXmlDelRangeEnd"); - else if (o is CT_Markup && this.itemsElementNameField[i] == ItemsChoiceType7.customXmlInsRangeEnd) - ((CT_Markup)o).Write(sw, "customXmlInsRangeEnd"); - else if (o is CT_TrackChange && this.itemsElementNameField[i] == ItemsChoiceType7.customXmlInsRangeStart) - ((CT_TrackChange)o).Write(sw, "customXmlInsRangeStart"); - else if (o is CT_RunTrackChange && this.itemsElementNameField[i] == ItemsChoiceType7.moveTo) - ((CT_RunTrackChange)o).Write(sw, "moveTo"); - else if (o is CT_MoveBookmark && this.itemsElementNameField[i] == ItemsChoiceType7.moveToRangeStart) - ((CT_MoveBookmark)o).Write(sw, "moveToRangeStart"); - else if (o is CT_TrackChange && this.itemsElementNameField[i] == ItemsChoiceType7.customXmlMoveFromRangeStart) - ((CT_TrackChange)o).Write(sw, "customXmlMoveFromRangeStart"); - else if (o is CT_Markup && this.itemsElementNameField[i] == ItemsChoiceType7.customXmlMoveToRangeEnd) - ((CT_Markup)o).Write(sw, "customXmlMoveToRangeEnd"); - else if (o is CT_TrackChange && this.itemsElementNameField[i] == ItemsChoiceType7.customXmlMoveToRangeStart) - ((CT_TrackChange)o).Write(sw, "customXmlMoveToRangeStart"); - else if (o is CT_RunTrackChange && this.itemsElementNameField[i] == ItemsChoiceType7.del) - ((CT_RunTrackChange)o).Write(sw, "del"); - else if (o is CT_P) - ((CT_P)o).Write(sw, "p"); - else if (o is CT_Perm) - ((CT_Perm)o).Write(sw, "permEnd"); - else if (o is CT_PermStart) - ((CT_PermStart)o).Write(sw, "permStart"); - else if (o is CT_ProofErr) - ((CT_ProofErr)o).Write(sw, "proofErr"); - else if (o is CT_SdtBlock) - ((CT_SdtBlock)o).Write(sw, "sdt"); - else if (o is CT_RunTrackChange && this.itemsElementNameField[i] == ItemsChoiceType7.moveFrom) - ((CT_RunTrackChange)o).Write(sw, "moveFrom"); - else if (o is CT_MarkupRange && this.itemsElementNameField[i] == ItemsChoiceType7.moveFromRangeEnd) - ((CT_MarkupRange)o).Write(sw, "moveFromRangeEnd"); - else if (o is CT_Tbl) - ((CT_Tbl)o).Write(sw, "tbl"); - else if (o is CT_MoveBookmark && this.itemsElementNameField[i] == ItemsChoiceType7.moveFromRangeStart) - ((CT_MoveBookmark)o).Write(sw, "moveFromRangeStart"); - else if (o is CT_OMath) - ((CT_OMath)o).Write(sw, "oMath"); - else if (o is CT_OMathPara) - ((CT_OMathPara)o).Write(sw, "oMathPara"); - else if (o is CT_AltChunk) - ((CT_AltChunk)o).Write(sw, "altChunk"); - else if (o is CT_MarkupRange && this.itemsElementNameField[i] == ItemsChoiceType7.bookmarkEnd) - ((CT_MarkupRange)o).Write(sw, "bookmarkEnd"); - else if (o is CT_Bookmark && this.itemsElementNameField[i] == ItemsChoiceType7.bookmarkStart) - ((CT_Bookmark)o).Write(sw, "bookmarkStart"); - else if (o is CT_MarkupRange && this.itemsElementNameField[i] == ItemsChoiceType7.commentRangeEnd) - ((CT_MarkupRange)o).Write(sw, "commentRangeEnd"); - else if (o is CT_MarkupRange && this.itemsElementNameField[i] == ItemsChoiceType7.commentRangeStart) - ((CT_MarkupRange)o).Write(sw, "commentRangeStart"); - else if (o is CT_CustomXmlBlock) - ((CT_CustomXmlBlock)o).Write(sw, "customXml"); + if (o is CT_TrackChange change&& this.itemsElementNameField[i]== ItemsChoiceType7.customXmlDelRangeStart) + change.Write(sw, "customXmlDelRangeStart"); + else if (o is CT_MarkupRange range && this.itemsElementNameField[i] == ItemsChoiceType7.moveToRangeEnd) + range.Write(sw, "moveToRangeEnd"); + else if (o is CT_Markup markup && this.itemsElementNameField[i] == ItemsChoiceType7.customXmlMoveFromRangeEnd) + markup.Write(sw, "customXmlMoveFromRangeEnd"); + else if (o is CT_RunTrackChange trackChange && this.itemsElementNameField[i] == ItemsChoiceType7.ins) + trackChange.Write(sw, "ins"); + else if (o is CT_Markup ctMarkup && this.itemsElementNameField[i] == ItemsChoiceType7.customXmlDelRangeEnd) + ctMarkup.Write(sw, "customXmlDelRangeEnd"); + else if (o is CT_Markup markup1 && this.itemsElementNameField[i] == ItemsChoiceType7.customXmlInsRangeEnd) + markup1.Write(sw, "customXmlInsRangeEnd"); + else if (o is CT_TrackChange ctTrackChange && this.itemsElementNameField[i] == ItemsChoiceType7.customXmlInsRangeStart) + ctTrackChange.Write(sw, "customXmlInsRangeStart"); + else if (o is CT_RunTrackChange runTrackChange && this.itemsElementNameField[i] == ItemsChoiceType7.moveTo) + runTrackChange.Write(sw, "moveTo"); + else if (o is CT_MoveBookmark bookmark && this.itemsElementNameField[i] == ItemsChoiceType7.moveToRangeStart) + bookmark.Write(sw, "moveToRangeStart"); + else if (o is CT_TrackChange change1 && this.itemsElementNameField[i] == ItemsChoiceType7.customXmlMoveFromRangeStart) + change1.Write(sw, "customXmlMoveFromRangeStart"); + else if (o is CT_Markup ctMarkup1 && this.itemsElementNameField[i] == ItemsChoiceType7.customXmlMoveToRangeEnd) + ctMarkup1.Write(sw, "customXmlMoveToRangeEnd"); + else if (o is CT_TrackChange trackChange1 && this.itemsElementNameField[i] == ItemsChoiceType7.customXmlMoveToRangeStart) + trackChange1.Write(sw, "customXmlMoveToRangeStart"); + else if (o is CT_RunTrackChange ctRunTrackChange && this.itemsElementNameField[i] == ItemsChoiceType7.del) + ctRunTrackChange.Write(sw, "del"); + else if (o is CT_P p) + p.Write(sw, "p"); + else if (o is CT_Perm perm) + perm.Write(sw, "permEnd"); + else if (o is CT_PermStart start) + start.Write(sw, "permStart"); + else if (o is CT_ProofErr err) + err.Write(sw, "proofErr"); + else if (o is CT_SdtBlock block) + block.Write(sw, "sdt"); + else if (o is CT_RunTrackChange runTrackChange1 && this.itemsElementNameField[i] == ItemsChoiceType7.moveFrom) + runTrackChange1.Write(sw, "moveFrom"); + else if (o is CT_MarkupRange markupRange && this.itemsElementNameField[i] == ItemsChoiceType7.moveFromRangeEnd) + markupRange.Write(sw, "moveFromRangeEnd"); + else if (o is CT_Tbl tbl) + tbl.Write(sw, "tbl"); + else if (o is CT_MoveBookmark moveBookmark && this.itemsElementNameField[i] == ItemsChoiceType7.moveFromRangeStart) + moveBookmark.Write(sw, "moveFromRangeStart"); + else if (o is CT_OMath math) + math.Write(sw, "oMath"); + else if (o is CT_OMathPara para) + para.Write(sw, "oMathPara"); + else if (o is CT_AltChunk chunk) + chunk.Write(sw, "altChunk"); + else if (o is CT_MarkupRange ctMarkupRange && this.itemsElementNameField[i] == ItemsChoiceType7.bookmarkEnd) + ctMarkupRange.Write(sw, "bookmarkEnd"); + else if (o is CT_Bookmark ctBookmark && this.itemsElementNameField[i] == ItemsChoiceType7.bookmarkStart) + ctBookmark.Write(sw, "bookmarkStart"); + else if (o is CT_MarkupRange range1 && this.itemsElementNameField[i] == ItemsChoiceType7.commentRangeEnd) + range1.Write(sw, "commentRangeEnd"); + else if (o is CT_MarkupRange markupRange1 && this.itemsElementNameField[i] == ItemsChoiceType7.commentRangeStart) + markupRange1.Write(sw, "commentRangeStart"); + else if (o is CT_CustomXmlBlock xmlBlock) + xmlBlock.Write(sw, "customXml"); i++; } sw.WriteEndW(nodeName); diff --git a/OpenXmlFormats/Wordprocessing/Markup.cs b/OpenXmlFormats/Wordprocessing/Markup.cs index 9fc2b7a3f..ff064200b 100644 --- a/OpenXmlFormats/Wordprocessing/Markup.cs +++ b/OpenXmlFormats/Wordprocessing/Markup.cs @@ -481,66 +481,66 @@ public CT_Comment() sw.Write(">"); foreach (object o in this.Items) { - if (o is CT_PermStart) - ((CT_PermStart)o).Write(sw, "permStart"); - else if (o is CT_Markup) - ((CT_Markup)o).Write(sw, "customXmlInsRangeEnd"); - else if (o is CT_TrackChange) - ((CT_TrackChange)o).Write(sw, "customXmlInsRangeStart"); - else if (o is CT_Perm) - ((CT_Perm)o).Write(sw, "permEnd"); - else if (o is CT_Markup) - ((CT_Markup)o).Write(sw, "customXmlMoveFromRangeEnd"); - else if (o is CT_ProofErr) - ((CT_ProofErr)o).Write(sw, "proofErr"); - else if (o is CT_SdtBlock) - ((CT_SdtBlock)o).Write(sw, "sdt"); - else if (o is CT_Tbl) - ((CT_Tbl)o).Write(sw, "tbl"); - else if (o is CT_MoveBookmark) - ((CT_MoveBookmark)o).Write(sw, "moveFromRangeStart"); - else if (o is CT_Markup) - ((CT_Markup)o).Write(sw, "customXmlMoveToRangeEnd"); - else if (o is CT_OMath) - ((CT_OMath)o).Write(sw, "oMath"); - else if (o is CT_OMathPara) - ((CT_OMathPara)o).Write(sw, "oMathPara"); - else if (o is CT_AltChunk) - ((CT_AltChunk)o).Write(sw, "altChunk"); - else if (o is CT_MarkupRange) - ((CT_MarkupRange)o).Write(sw, "bookmarkEnd"); - else if (o is CT_Bookmark) - ((CT_Bookmark)o).Write(sw, "bookmarkStart"); - else if (o is CT_TrackChange) - ((CT_TrackChange)o).Write(sw, "customXmlMoveToRangeStart"); - else if (o is CT_MarkupRange) - ((CT_MarkupRange)o).Write(sw, "commentRangeEnd"); - else if (o is CT_MarkupRange) - ((CT_MarkupRange)o).Write(sw, "commentRangeStart"); - else if (o is CT_RunTrackChange) - ((CT_RunTrackChange)o).Write(sw, "moveTo"); - else if (o is CT_TrackChange) - ((CT_TrackChange)o).Write(sw, "customXmlMoveFromRangeStart"); - else if (o is CT_MarkupRange) - ((CT_MarkupRange)o).Write(sw, "moveToRangeEnd"); - else if (o is CT_CustomXmlBlock) - ((CT_CustomXmlBlock)o).Write(sw, "customXml"); - else if (o is CT_MoveBookmark) - ((CT_MoveBookmark)o).Write(sw, "moveToRangeStart"); - else if (o is CT_P) - ((CT_P)o).Write(sw, "p"); - else if (o is CT_Markup) - ((CT_Markup)o).Write(sw, "customXmlDelRangeEnd"); - else if (o is CT_RunTrackChange) - ((CT_RunTrackChange)o).Write(sw, "del"); - else if (o is CT_RunTrackChange) - ((CT_RunTrackChange)o).Write(sw, "ins"); - else if (o is CT_RunTrackChange) - ((CT_RunTrackChange)o).Write(sw, "moveFrom"); - else if (o is CT_TrackChange) - ((CT_TrackChange)o).Write(sw, "customXmlDelRangeStart"); - else if (o is CT_MarkupRange) - ((CT_MarkupRange)o).Write(sw, "moveFromRangeEnd"); + if (o is CT_PermStart start) + start.Write(sw, "permStart"); + else if (o is CT_Markup markup) + markup.Write(sw, "customXmlInsRangeEnd"); + else if (o is CT_TrackChange change) + change.Write(sw, "customXmlInsRangeStart"); + else if (o is CT_Perm perm) + perm.Write(sw, "permEnd"); + else if (o is CT_Markup ctMarkup) + ctMarkup.Write(sw, "customXmlMoveFromRangeEnd"); + else if (o is CT_ProofErr err) + err.Write(sw, "proofErr"); + else if (o is CT_SdtBlock block) + block.Write(sw, "sdt"); + else if (o is CT_Tbl tbl) + tbl.Write(sw, "tbl"); + else if (o is CT_MoveBookmark bookmark) + bookmark.Write(sw, "moveFromRangeStart"); + else if (o is CT_Markup markup1) + markup1.Write(sw, "customXmlMoveToRangeEnd"); + else if (o is CT_OMath math) + math.Write(sw, "oMath"); + else if (o is CT_OMathPara para) + para.Write(sw, "oMathPara"); + else if (o is CT_AltChunk chunk) + chunk.Write(sw, "altChunk"); + else if (o is CT_MarkupRange range) + range.Write(sw, "bookmarkEnd"); + else if (o is CT_Bookmark ctBookmark) + ctBookmark.Write(sw, "bookmarkStart"); + else if (o is CT_TrackChange trackChange) + trackChange.Write(sw, "customXmlMoveToRangeStart"); + else if (o is CT_MarkupRange markupRange) + markupRange.Write(sw, "commentRangeEnd"); + else if (o is CT_MarkupRange ctMarkupRange) + ctMarkupRange.Write(sw, "commentRangeStart"); + else if (o is CT_RunTrackChange runTrackChange) + runTrackChange.Write(sw, "moveTo"); + else if (o is CT_TrackChange ctTrackChange) + ctTrackChange.Write(sw, "customXmlMoveFromRangeStart"); + else if (o is CT_MarkupRange range1) + range1.Write(sw, "moveToRangeEnd"); + else if (o is CT_CustomXmlBlock xmlBlock) + xmlBlock.Write(sw, "customXml"); + else if (o is CT_MoveBookmark moveBookmark) + moveBookmark.Write(sw, "moveToRangeStart"); + else if (o is CT_P p) + p.Write(sw, "p"); + else if (o is CT_Markup ctMarkup1) + ctMarkup1.Write(sw, "customXmlDelRangeEnd"); + else if (o is CT_RunTrackChange ctRunTrackChange) + ctRunTrackChange.Write(sw, "del"); + else if (o is CT_RunTrackChange change1) + change1.Write(sw, "ins"); + else if (o is CT_RunTrackChange trackChange1) + trackChange1.Write(sw, "moveFrom"); + else if (o is CT_TrackChange ctTrackChange1) + ctTrackChange1.Write(sw, "customXmlDelRangeStart"); + else if (o is CT_MarkupRange markupRange1) + markupRange1.Write(sw, "moveFromRangeEnd"); } sw.WriteEndW(nodeName); } diff --git a/OpenXmlFormats/Wordprocessing/Paragraph.cs b/OpenXmlFormats/Wordprocessing/Paragraph.cs index 5f4e9d2b5..824895a0c 100644 --- a/OpenXmlFormats/Wordprocessing/Paragraph.cs +++ b/OpenXmlFormats/Wordprocessing/Paragraph.cs @@ -265,70 +265,70 @@ internal void Write(StreamWriter sw, string nodeName) int i = 0; foreach (object o in this.Items) { - if (o is CT_MarkupRange && this.itemsElementNameField[i] == ParagraphItemsChoiceType.bookmarkEnd) - ((CT_MarkupRange)o).Write(sw, "bookmarkEnd"); - else if (o is CT_MoveBookmark && this.itemsElementNameField[i] == ParagraphItemsChoiceType.moveFromRangeStart) - ((CT_MoveBookmark)o).Write(sw, "moveFromRangeStart"); - else if (o is CT_RunTrackChange && this.itemsElementNameField[i] == ParagraphItemsChoiceType.moveTo) - ((CT_RunTrackChange)o).Write(sw, "moveTo"); - else if (o is CT_OMathPara) - ((CT_OMathPara)o).Write(sw, "oMathPara"); - else if (o is CT_OMath) - ((CT_OMath)o).Write(sw, "oMath"); - else if (o is CT_Bookmark && this.itemsElementNameField[i] == ParagraphItemsChoiceType.bookmarkStart) - ((CT_Bookmark)o).Write(sw, "bookmarkStart"); - else if (o is CT_MarkupRange&& this.itemsElementNameField[i] == ParagraphItemsChoiceType.commentRangeEnd) - ((CT_MarkupRange)o).Write(sw, "commentRangeEnd"); - else if (o is CT_MarkupRange && this.itemsElementNameField[i] == ParagraphItemsChoiceType.commentRangeStart) - ((CT_MarkupRange)o).Write(sw, "commentRangeStart"); - else if (o is CT_CustomXmlRun) - ((CT_CustomXmlRun)o).Write(sw, "customXml"); - else if (o is CT_Markup && this.itemsElementNameField[i] == ParagraphItemsChoiceType.customXmlDelRangeEnd) - ((CT_Markup)o).Write(sw, "customXmlDelRangeEnd"); - else if (o is CT_TrackChange && this.itemsElementNameField[i] == ParagraphItemsChoiceType.customXmlDelRangeStart) - ((CT_TrackChange)o).Write(sw, "customXmlDelRangeStart"); - else if (o is CT_Markup && this.itemsElementNameField[i] == ParagraphItemsChoiceType.customXmlInsRangeEnd) - ((CT_Markup)o).Write(sw, "customXmlInsRangeEnd"); - else if (o is CT_TrackChange && this.itemsElementNameField[i] == ParagraphItemsChoiceType.customXmlInsRangeStart) - ((CT_TrackChange)o).Write(sw, "customXmlInsRangeStart"); - else if (o is CT_Markup && this.itemsElementNameField[i] == ParagraphItemsChoiceType.customXmlMoveFromRangeEnd) - ((CT_Markup)o).Write(sw, "customXmlMoveFromRangeEnd"); - else if (o is CT_TrackChange && this.itemsElementNameField[i] == ParagraphItemsChoiceType.customXmlMoveFromRangeStart) - ((CT_TrackChange)o).Write(sw, "customXmlMoveFromRangeStart"); - else if (o is CT_Markup && this.itemsElementNameField[i] == ParagraphItemsChoiceType.customXmlMoveToRangeEnd) - ((CT_Markup)o).Write(sw, "customXmlMoveToRangeEnd"); - else if (o is CT_TrackChange && this.itemsElementNameField[i] == ParagraphItemsChoiceType.customXmlMoveToRangeStart) - ((CT_TrackChange)o).Write(sw, "customXmlMoveToRangeStart"); - else if (o is CT_RunTrackChange && this.itemsElementNameField[i] == ParagraphItemsChoiceType.del) - ((CT_RunTrackChange)o).Write(sw, "del"); - else if (o is CT_SimpleField) - ((CT_SimpleField)o).Write(sw, "fldSimple"); - else if (o is CT_Hyperlink1) - ((CT_Hyperlink1)o).Write(sw, "hyperlink"); - else if (o is CT_RunTrackChange && this.itemsElementNameField[i] == ParagraphItemsChoiceType.ins) - ((CT_RunTrackChange)o).Write(sw, "ins"); - else if (o is CT_RunTrackChange && this.itemsElementNameField[i] == ParagraphItemsChoiceType.moveFrom) - ((CT_RunTrackChange)o).Write(sw, "moveFrom"); - else if (o is CT_MarkupRange && this.itemsElementNameField[i] == ParagraphItemsChoiceType.moveFromRangeEnd) - ((CT_MarkupRange)o).Write(sw, "moveFromRangeEnd"); - else if (o is CT_MarkupRange && this.itemsElementNameField[i] == ParagraphItemsChoiceType.moveToRangeEnd) - ((CT_MarkupRange)o).Write(sw, "moveToRangeEnd"); - else if (o is CT_MoveBookmark && this.itemsElementNameField[i] == ParagraphItemsChoiceType.moveToRangeStart) - ((CT_MoveBookmark)o).Write(sw, "moveToRangeStart"); - else if (o is CT_Perm) - ((CT_Perm)o).Write(sw, "permEnd"); - else if (o is CT_PermStart) - ((CT_PermStart)o).Write(sw, "permStart"); - else if (o is CT_ProofErr) - ((CT_ProofErr)o).Write(sw, "proofErr"); - else if (o is CT_R) - ((CT_R)o).Write(sw, "r"); - else if (o is CT_SdtRun) - ((CT_SdtRun)o).Write(sw, "sdt"); - else if (o is CT_SmartTagRun) - ((CT_SmartTagRun)o).Write(sw, "smartTag"); - else if (o is CT_Rel) - ((CT_Rel)o).Write(sw, "subDoc"); + if (o is CT_MarkupRange range && this.itemsElementNameField[i] == ParagraphItemsChoiceType.bookmarkEnd) + range.Write(sw, "bookmarkEnd"); + else if (o is CT_MoveBookmark bookmark && this.itemsElementNameField[i] == ParagraphItemsChoiceType.moveFromRangeStart) + bookmark.Write(sw, "moveFromRangeStart"); + else if (o is CT_RunTrackChange change && this.itemsElementNameField[i] == ParagraphItemsChoiceType.moveTo) + change.Write(sw, "moveTo"); + else if (o is CT_OMathPara para) + para.Write(sw, "oMathPara"); + else if (o is CT_OMath math) + math.Write(sw, "oMath"); + else if (o is CT_Bookmark ctBookmark && this.itemsElementNameField[i] == ParagraphItemsChoiceType.bookmarkStart) + ctBookmark.Write(sw, "bookmarkStart"); + else if (o is CT_MarkupRange markupRange&& this.itemsElementNameField[i] == ParagraphItemsChoiceType.commentRangeEnd) + markupRange.Write(sw, "commentRangeEnd"); + else if (o is CT_MarkupRange ctMarkupRange && this.itemsElementNameField[i] == ParagraphItemsChoiceType.commentRangeStart) + ctMarkupRange.Write(sw, "commentRangeStart"); + else if (o is CT_CustomXmlRun run) + run.Write(sw, "customXml"); + else if (o is CT_Markup markup && this.itemsElementNameField[i] == ParagraphItemsChoiceType.customXmlDelRangeEnd) + markup.Write(sw, "customXmlDelRangeEnd"); + else if (o is CT_TrackChange trackChange && this.itemsElementNameField[i] == ParagraphItemsChoiceType.customXmlDelRangeStart) + trackChange.Write(sw, "customXmlDelRangeStart"); + else if (o is CT_Markup ctMarkup && this.itemsElementNameField[i] == ParagraphItemsChoiceType.customXmlInsRangeEnd) + ctMarkup.Write(sw, "customXmlInsRangeEnd"); + else if (o is CT_TrackChange ctTrackChange && this.itemsElementNameField[i] == ParagraphItemsChoiceType.customXmlInsRangeStart) + ctTrackChange.Write(sw, "customXmlInsRangeStart"); + else if (o is CT_Markup markup1 && this.itemsElementNameField[i] == ParagraphItemsChoiceType.customXmlMoveFromRangeEnd) + markup1.Write(sw, "customXmlMoveFromRangeEnd"); + else if (o is CT_TrackChange change1 && this.itemsElementNameField[i] == ParagraphItemsChoiceType.customXmlMoveFromRangeStart) + change1.Write(sw, "customXmlMoveFromRangeStart"); + else if (o is CT_Markup ctMarkup1 && this.itemsElementNameField[i] == ParagraphItemsChoiceType.customXmlMoveToRangeEnd) + ctMarkup1.Write(sw, "customXmlMoveToRangeEnd"); + else if (o is CT_TrackChange trackChange1 && this.itemsElementNameField[i] == ParagraphItemsChoiceType.customXmlMoveToRangeStart) + trackChange1.Write(sw, "customXmlMoveToRangeStart"); + else if (o is CT_RunTrackChange runTrackChange && this.itemsElementNameField[i] == ParagraphItemsChoiceType.del) + runTrackChange.Write(sw, "del"); + else if (o is CT_SimpleField field) + field.Write(sw, "fldSimple"); + else if (o is CT_Hyperlink1 hyperlink1) + hyperlink1.Write(sw, "hyperlink"); + else if (o is CT_RunTrackChange ctRunTrackChange && this.itemsElementNameField[i] == ParagraphItemsChoiceType.ins) + ctRunTrackChange.Write(sw, "ins"); + else if (o is CT_RunTrackChange runTrackChange1 && this.itemsElementNameField[i] == ParagraphItemsChoiceType.moveFrom) + runTrackChange1.Write(sw, "moveFrom"); + else if (o is CT_MarkupRange range1 && this.itemsElementNameField[i] == ParagraphItemsChoiceType.moveFromRangeEnd) + range1.Write(sw, "moveFromRangeEnd"); + else if (o is CT_MarkupRange markupRange1 && this.itemsElementNameField[i] == ParagraphItemsChoiceType.moveToRangeEnd) + markupRange1.Write(sw, "moveToRangeEnd"); + else if (o is CT_MoveBookmark moveBookmark && this.itemsElementNameField[i] == ParagraphItemsChoiceType.moveToRangeStart) + moveBookmark.Write(sw, "moveToRangeStart"); + else if (o is CT_Perm perm) + perm.Write(sw, "permEnd"); + else if (o is CT_PermStart start) + start.Write(sw, "permStart"); + else if (o is CT_ProofErr err) + err.Write(sw, "proofErr"); + else if (o is CT_R r) + r.Write(sw, "r"); + else if (o is CT_SdtRun sdtRun) + sdtRun.Write(sw, "sdt"); + else if (o is CT_SmartTagRun tagRun) + tagRun.Write(sw, "smartTag"); + else if (o is CT_Rel rel) + rel.Write(sw, "subDoc"); i++; } sw.WriteEndW(nodeName); diff --git a/OpenXmlFormats/Wordprocessing/Picture.cs b/OpenXmlFormats/Wordprocessing/Picture.cs index b006c118a..5a7cb42fd 100644 --- a/OpenXmlFormats/Wordprocessing/Picture.cs +++ b/OpenXmlFormats/Wordprocessing/Picture.cs @@ -59,9 +59,8 @@ public List ItemsElementName public void Set(object obj) { - if (obj is CT_Group) + if (obj is CT_Group group) { - var group = (CT_Group)obj; foreach (var item in group.Items) { /*XmlSerializer xmlse = new XmlSerializer(item.GetType()); @@ -207,17 +206,17 @@ internal void Write(StreamWriter sw, string nodeName) this.control.Write(sw, "control"); foreach (var childnode in Items) { - if (childnode is XmlNode) + if (childnode is XmlNode node) { - sw.Write(((XmlNode)childnode).OuterXml); + sw.Write(node.OuterXml); } - else if (childnode is CT_Shape) + else if (childnode is CT_Shape shape) { - ((CT_Shape)childnode).Write(sw, "shape"); + shape.Write(sw, "shape"); } - else if (childnode is CT_Shapetype) + else if (childnode is CT_Shapetype shapetype) { - ((CT_Shapetype)childnode).Write(sw, "shapetype"); + shapetype.Write(sw, "shapetype"); } } sw.WriteEndW(nodeName); diff --git a/OpenXmlFormats/Wordprocessing/Run.cs b/OpenXmlFormats/Wordprocessing/Run.cs index 8a0db34f4..5433cfb4e 100644 --- a/OpenXmlFormats/Wordprocessing/Run.cs +++ b/OpenXmlFormats/Wordprocessing/Run.cs @@ -724,18 +724,18 @@ internal void Write(StreamWriter sw, string nodeName) int i = 0; foreach (object o in this.Items) { - if ((o is CT_Text) && this.ItemsElementName[i] == RunItemsChoiceType.instrText) - ((CT_Text)o).Write(sw, "instrText"); - else if (o is CT_Object) - ((CT_Object)o).Write(sw, "object"); + if ((o is CT_Text text) && this.ItemsElementName[i] == RunItemsChoiceType.instrText) + text.Write(sw, "instrText"); + else if (o is CT_Object ctObject) + ctObject.Write(sw, "object"); else if (o is CT_Empty && this.ItemsElementName[i] == RunItemsChoiceType.pgNum) sw.Write(""); else if (o is CT_Empty && this.ItemsElementName[i] == RunItemsChoiceType.annotationRef) sw.Write(""); - else if (o is CT_Br) - ((CT_Br)o).Write(sw, "br"); - else if (o is CT_Markup) - ((CT_Markup)o).Write(sw, "commentReference"); + else if (o is CT_Br br) + br.Write(sw, "br"); + else if (o is CT_Markup markup) + markup.Write(sw, "commentReference"); else if (o is CT_Empty && this.ItemsElementName[i] == RunItemsChoiceType.continuationSeparator) sw.Write(""); else if (o is CT_Empty && this.ItemsElementName[i] == RunItemsChoiceType.cr) @@ -744,20 +744,20 @@ internal void Write(StreamWriter sw, string nodeName) sw.Write(""); else if (o is CT_Empty && this.ItemsElementName[i] == RunItemsChoiceType.dayShort) sw.Write(""); - else if ((o is CT_Text) && this.ItemsElementName[i] == RunItemsChoiceType.delInstrText) - ((CT_Text)o).Write(sw, "delInstrText"); - else if (o is CT_Text && this.ItemsElementName[i] == RunItemsChoiceType.delText) - ((CT_Text)o).Write(sw, "delText"); - else if (o is CT_Drawing) - ((CT_Drawing)o).Write(sw, "drawing"); + else if ((o is CT_Text ctText) && this.ItemsElementName[i] == RunItemsChoiceType.delInstrText) + ctText.Write(sw, "delInstrText"); + else if (o is CT_Text text1 && this.ItemsElementName[i] == RunItemsChoiceType.delText) + text1.Write(sw, "delText"); + else if (o is CT_Drawing drawing) + drawing.Write(sw, "drawing"); else if (o is CT_Empty && this.ItemsElementName[i] == RunItemsChoiceType.endnoteRef) sw.Write(""); - else if (o is CT_FtnEdnRef && this.ItemsElementName[i] == RunItemsChoiceType.endnoteReference) - ((CT_FtnEdnRef)o).Write(sw, "endnoteReference"); - else if (o is CT_FtnEdnRef && this.ItemsElementName[i] == RunItemsChoiceType.footnoteReference) - ((CT_FtnEdnRef)o).Write(sw, "footnoteReference"); - else if (o is CT_FldChar) - ((CT_FldChar)o).Write(sw, "fldChar"); + else if (o is CT_FtnEdnRef @ref && this.ItemsElementName[i] == RunItemsChoiceType.endnoteReference) + @ref.Write(sw, "endnoteReference"); + else if (o is CT_FtnEdnRef ednRef && this.ItemsElementName[i] == RunItemsChoiceType.footnoteReference) + ednRef.Write(sw, "footnoteReference"); + else if (o is CT_FldChar fldChar) + fldChar.Write(sw, "fldChar"); else if (o is CT_Empty && this.ItemsElementName[i] == RunItemsChoiceType.footnoteRef) sw.Write(""); else if (o is CT_Empty && this.ItemsElementName[i] == RunItemsChoiceType.lastRenderedPageBreak) @@ -770,20 +770,20 @@ internal void Write(StreamWriter sw, string nodeName) sw.Write(""); else if (o is CT_Empty && this.ItemsElementName[i] == RunItemsChoiceType.yearLong) sw.Write(""); - else if (o is CT_Picture) - ((CT_Picture)o).Write(sw, "pict"); - else if (o is CT_PTab) - ((CT_PTab)o).Write(sw, "ptab"); - else if (o is CT_Ruby) - ((CT_Ruby)o).Write(sw, "ruby"); + else if (o is CT_Picture picture) + picture.Write(sw, "pict"); + else if (o is CT_PTab tab) + tab.Write(sw, "ptab"); + else if (o is CT_Ruby ruby) + ruby.Write(sw, "ruby"); else if (o is CT_Empty && this.ItemsElementName[i] == RunItemsChoiceType.separator) sw.Write(""); else if (o is CT_Empty && this.ItemsElementName[i] == RunItemsChoiceType.softHyphen) sw.Write(""); - else if (o is CT_Sym) - ((CT_Sym)o).Write(sw, "sym"); - else if ((o is CT_Text) && this.ItemsElementName[i] == RunItemsChoiceType.t) - ((CT_Text)o).Write(sw, "t"); + else if (o is CT_Sym sym) + sym.Write(sw, "sym"); + else if ((o is CT_Text ctText1) && this.ItemsElementName[i] == RunItemsChoiceType.t) + ctText1.Write(sw, "t"); else if (o is CT_Empty&& this.ItemsElementName[i]== RunItemsChoiceType.tab) sw.Write(""); else if (o is CT_Empty&& this.ItemsElementName[i]== RunItemsChoiceType.yearShort) @@ -1340,58 +1340,58 @@ internal void Write(StreamWriter sw, string nodeName) int i = 0; foreach (object o in this.Items) { - if (o is CT_OMath) - ((CT_OMath)o).Write(sw, "oMath"); - else if (o is CT_PermStart) - ((CT_PermStart)o).Write(sw, "permStart"); - else if (o is CT_ProofErr) - ((CT_ProofErr)o).Write(sw, "proofErr"); - else if (o is CT_Perm) - ((CT_Perm)o).Write(sw, "permEnd"); - else if (o is CT_MoveBookmark && this.itemsElementNameField[i] == ItemsChoiceType16.moveToRangeStart) - ((CT_MoveBookmark)o).Write(sw, "moveToRangeStart"); - else if (o is CT_MarkupRange && this.itemsElementNameField[i] == ItemsChoiceType16.moveToRangeEnd) - ((CT_MarkupRange)o).Write(sw, "moveToRangeEnd"); - else if (o is CT_RunTrackChange&& this.itemsElementNameField[i]== ItemsChoiceType16.moveTo) - ((CT_RunTrackChange)o).Write(sw, "moveTo"); - else if (o is CT_RunTrackChange && this.itemsElementNameField[i] == ItemsChoiceType16.moveFrom) - ((CT_RunTrackChange)o).Write(sw, "moveFrom"); - else if (o is CT_MoveBookmark && this.itemsElementNameField[i] == ItemsChoiceType16.moveFromRangeStart) - ((CT_MoveBookmark)o).Write(sw, "moveFromRangeStart"); - else if (o is CT_MarkupRange && this.itemsElementNameField[i] == ItemsChoiceType16.moveFromRangeEnd) - ((CT_MarkupRange)o).Write(sw, "moveFromRangeEnd"); - else if (o is CT_Markup && this.itemsElementNameField[i] == ItemsChoiceType16.customXmlInsRangeEnd) - ((CT_Markup)o).Write(sw, "customXmlInsRangeEnd"); - else if (o is CT_TrackChange && this.itemsElementNameField[i] == ItemsChoiceType16.customXmlInsRangeStart) - ((CT_TrackChange)o).Write(sw, "customXmlInsRangeStart"); - else if (o is CT_Markup && this.itemsElementNameField[i] == ItemsChoiceType16.customXmlMoveFromRangeEnd) - ((CT_Markup)o).Write(sw, "customXmlMoveFromRangeEnd"); - else if (o is CT_TrackChange && this.itemsElementNameField[i] == ItemsChoiceType16.customXmlMoveFromRangeStart) - ((CT_TrackChange)o).Write(sw, "customXmlMoveFromRangeStart"); - else if (o is CT_Markup && this.itemsElementNameField[i] == ItemsChoiceType16.customXmlMoveToRangeEnd) - ((CT_Markup)o).Write(sw, "customXmlMoveToRangeEnd"); - else if (o is CT_TrackChange && this.itemsElementNameField[i] == ItemsChoiceType16.customXmlMoveToRangeStart) - ((CT_TrackChange)o).Write(sw, "customXmlMoveToRangeStart"); - else if (o is CT_RunTrackChange && this.itemsElementNameField[i] == ItemsChoiceType16.del) - ((CT_RunTrackChange)o).Write(sw, "del"); - else if (o is CT_RunTrackChange && this.itemsElementNameField[i] == ItemsChoiceType16.ins) - ((CT_RunTrackChange)o).Write(sw, "ins"); - else if (o is CT_TrackChange && this.itemsElementNameField[i] == ItemsChoiceType16.customXmlDelRangeStart) - ((CT_TrackChange)o).Write(sw, "customXmlDelRangeStart"); - else if (o is CT_Markup && this.itemsElementNameField[i] == ItemsChoiceType16.customXmlDelRangeEnd) - ((CT_Markup)o).Write(sw, "customXmlDelRangeEnd"); - else if (o is CT_MarkupRange && this.itemsElementNameField[i] == ItemsChoiceType16.commentRangeStart) - ((CT_MarkupRange)o).Write(sw, "commentRangeStart"); - else if (o is CT_MarkupRange && this.itemsElementNameField[i] == ItemsChoiceType16.commentRangeEnd) - ((CT_MarkupRange)o).Write(sw, "commentRangeEnd"); - else if (o is CT_Bookmark) - ((CT_Bookmark)o).Write(sw, "bookmarkStart"); - else if (o is CT_MarkupRange && this.itemsElementNameField[i] == ItemsChoiceType16.bookmarkEnd) - ((CT_MarkupRange)o).Write(sw, "bookmarkEnd"); - else if (o is CT_OMathPara) - ((CT_OMathPara)o).Write(sw, "oMathPara"); - else if (o is CT_R) - ((CT_R)o).Write(sw, "r"); + if (o is CT_OMath math) + math.Write(sw, "oMath"); + else if (o is CT_PermStart start) + start.Write(sw, "permStart"); + else if (o is CT_ProofErr err) + err.Write(sw, "proofErr"); + else if (o is CT_Perm perm) + perm.Write(sw, "permEnd"); + else if (o is CT_MoveBookmark bookmark && this.itemsElementNameField[i] == ItemsChoiceType16.moveToRangeStart) + bookmark.Write(sw, "moveToRangeStart"); + else if (o is CT_MarkupRange range && this.itemsElementNameField[i] == ItemsChoiceType16.moveToRangeEnd) + range.Write(sw, "moveToRangeEnd"); + else if (o is CT_RunTrackChange change&& this.itemsElementNameField[i]== ItemsChoiceType16.moveTo) + change.Write(sw, "moveTo"); + else if (o is CT_RunTrackChange trackChange && this.itemsElementNameField[i] == ItemsChoiceType16.moveFrom) + trackChange.Write(sw, "moveFrom"); + else if (o is CT_MoveBookmark moveBookmark && this.itemsElementNameField[i] == ItemsChoiceType16.moveFromRangeStart) + moveBookmark.Write(sw, "moveFromRangeStart"); + else if (o is CT_MarkupRange markupRange && this.itemsElementNameField[i] == ItemsChoiceType16.moveFromRangeEnd) + markupRange.Write(sw, "moveFromRangeEnd"); + else if (o is CT_Markup markup && this.itemsElementNameField[i] == ItemsChoiceType16.customXmlInsRangeEnd) + markup.Write(sw, "customXmlInsRangeEnd"); + else if (o is CT_TrackChange ctTrackChange && this.itemsElementNameField[i] == ItemsChoiceType16.customXmlInsRangeStart) + ctTrackChange.Write(sw, "customXmlInsRangeStart"); + else if (o is CT_Markup ctMarkup && this.itemsElementNameField[i] == ItemsChoiceType16.customXmlMoveFromRangeEnd) + ctMarkup.Write(sw, "customXmlMoveFromRangeEnd"); + else if (o is CT_TrackChange change1 && this.itemsElementNameField[i] == ItemsChoiceType16.customXmlMoveFromRangeStart) + change1.Write(sw, "customXmlMoveFromRangeStart"); + else if (o is CT_Markup markup1 && this.itemsElementNameField[i] == ItemsChoiceType16.customXmlMoveToRangeEnd) + markup1.Write(sw, "customXmlMoveToRangeEnd"); + else if (o is CT_TrackChange trackChange1 && this.itemsElementNameField[i] == ItemsChoiceType16.customXmlMoveToRangeStart) + trackChange1.Write(sw, "customXmlMoveToRangeStart"); + else if (o is CT_RunTrackChange runTrackChange && this.itemsElementNameField[i] == ItemsChoiceType16.del) + runTrackChange.Write(sw, "del"); + else if (o is CT_RunTrackChange ctRunTrackChange && this.itemsElementNameField[i] == ItemsChoiceType16.ins) + ctRunTrackChange.Write(sw, "ins"); + else if (o is CT_TrackChange ctTrackChange1 && this.itemsElementNameField[i] == ItemsChoiceType16.customXmlDelRangeStart) + ctTrackChange1.Write(sw, "customXmlDelRangeStart"); + else if (o is CT_Markup ctMarkup1 && this.itemsElementNameField[i] == ItemsChoiceType16.customXmlDelRangeEnd) + ctMarkup1.Write(sw, "customXmlDelRangeEnd"); + else if (o is CT_MarkupRange ctMarkupRange && this.itemsElementNameField[i] == ItemsChoiceType16.commentRangeStart) + ctMarkupRange.Write(sw, "commentRangeStart"); + else if (o is CT_MarkupRange range1 && this.itemsElementNameField[i] == ItemsChoiceType16.commentRangeEnd) + range1.Write(sw, "commentRangeEnd"); + else if (o is CT_Bookmark ctBookmark) + ctBookmark.Write(sw, "bookmarkStart"); + else if (o is CT_MarkupRange markupRange1 && this.itemsElementNameField[i] == ItemsChoiceType16.bookmarkEnd) + markupRange1.Write(sw, "bookmarkEnd"); + else if (o is CT_OMathPara para) + para.Write(sw, "oMathPara"); + else if (o is CT_R r) + r.Write(sw, "r"); i++; } sw.WriteEndW(nodeName); @@ -2318,104 +2318,104 @@ public CT_RunTrackChange() sw.Write(">"); foreach (object o in this.Items) { - if (o is CT_Func) - ((CT_Func)o).Write(sw, "func"); - else if (o is CT_SSubSup) - ((CT_SSubSup)o).Write(sw, "sSubSup"); - else if (o is CT_TrackChange) - ((CT_TrackChange)o).Write(sw, "customXmlInsRangeStart"); - else if (o is CT_Acc) - ((CT_Acc)o).Write(sw, "acc"); - else if (o is CT_Bar) - ((CT_Bar)o).Write(sw, "bar"); - else if (o is CT_BorderBox) - ((CT_BorderBox)o).Write(sw, "borderBox"); - else if (o is CT_Box) - ((CT_Box)o).Write(sw, "box"); - else if (o is CT_D) - ((CT_D)o).Write(sw, "d"); - else if (o is CT_EqArr) - ((CT_EqArr)o).Write(sw, "eqArr"); - else if (o is CT_F) - ((CT_F)o).Write(sw, "f"); - else if (o is CT_GroupChr) - ((CT_GroupChr)o).Write(sw, "groupChr"); - else if (o is CT_LimLow) - ((CT_LimLow)o).Write(sw, "limLow"); - else if (o is CT_M) - ((CT_M)o).Write(sw, "m"); - else if (o is CT_Nary) - ((CT_Nary)o).Write(sw, "nary"); - else if (o is CT_OMath) - ((CT_OMath)o).Write(sw, "oMath"); - else if (o is CT_OMathPara) - ((CT_OMathPara)o).Write(sw, "oMathPara"); - else if (o is CT_Phant) - ((CT_Phant)o).Write(sw, "phant"); - else if (o is CT_R) - ((CT_R)o).Write(sw, "r"); - else if (o is CT_Rad) - ((CT_Rad)o).Write(sw, "rad"); - else if (o is CT_SPre) - ((CT_SPre)o).Write(sw, "sPre"); - else if (o is CT_SSub) - ((CT_SSub)o).Write(sw, "sSub"); - else if (o is CT_SSup) - ((CT_SSup)o).Write(sw, "sSup"); - else if (o is CT_MarkupRange) - ((CT_MarkupRange)o).Write(sw, "bookmarkEnd"); - else if (o is CT_Bookmark) - ((CT_Bookmark)o).Write(sw, "bookmarkStart"); - else if (o is CT_MarkupRange) - ((CT_MarkupRange)o).Write(sw, "commentRangeEnd"); - else if (o is CT_MarkupRange) - ((CT_MarkupRange)o).Write(sw, "commentRangeStart"); - else if (o is CT_CustomXmlRun) - ((CT_CustomXmlRun)o).Write(sw, "customXml"); - else if (o is CT_Markup) - ((CT_Markup)o).Write(sw, "customXmlDelRangeEnd"); - else if (o is CT_TrackChange) - ((CT_TrackChange)o).Write(sw, "customXmlDelRangeStart"); - else if (o is CT_Markup) - ((CT_Markup)o).Write(sw, "customXmlInsRangeEnd"); - else if (o is CT_LimUpp) - ((CT_LimUpp)o).Write(sw, "limUpp"); - else if (o is CT_Markup) - ((CT_Markup)o).Write(sw, "customXmlMoveFromRangeEnd"); - else if (o is CT_TrackChange) - ((CT_TrackChange)o).Write(sw, "customXmlMoveFromRangeStart"); - else if (o is CT_Markup) - ((CT_Markup)o).Write(sw, "customXmlMoveToRangeEnd"); - else if (o is CT_TrackChange) - ((CT_TrackChange)o).Write(sw, "customXmlMoveToRangeStart"); - else if (o is CT_RunTrackChange) - ((CT_RunTrackChange)o).Write(sw, "del"); - else if (o is CT_RunTrackChange) - ((CT_RunTrackChange)o).Write(sw, "ins"); - else if (o is CT_RunTrackChange) - ((CT_RunTrackChange)o).Write(sw, "moveFrom"); - else if (o is CT_MarkupRange) - ((CT_MarkupRange)o).Write(sw, "moveFromRangeEnd"); - else if (o is CT_MoveBookmark) - ((CT_MoveBookmark)o).Write(sw, "moveFromRangeStart"); - else if (o is CT_RunTrackChange) - ((CT_RunTrackChange)o).Write(sw, "moveTo"); - else if (o is CT_MarkupRange) - ((CT_MarkupRange)o).Write(sw, "moveToRangeEnd"); - else if (o is CT_MoveBookmark) - ((CT_MoveBookmark)o).Write(sw, "moveToRangeStart"); - else if (o is CT_Perm) - ((CT_Perm)o).Write(sw, "permEnd"); - else if (o is CT_PermStart) - ((CT_PermStart)o).Write(sw, "permStart"); - else if (o is CT_ProofErr) - ((CT_ProofErr)o).Write(sw, "proofErr"); - else if (o is CT_R) - ((CT_R)o).Write(sw, "r"); - else if (o is CT_SdtRun) - ((CT_SdtRun)o).Write(sw, "sdt"); - else if (o is CT_SmartTagRun) - ((CT_SmartTagRun)o).Write(sw, "smartTag"); + if (o is CT_Func func) + func.Write(sw, "func"); + else if (o is CT_SSubSup sup) + sup.Write(sw, "sSubSup"); + else if (o is CT_TrackChange change) + change.Write(sw, "customXmlInsRangeStart"); + else if (o is CT_Acc acc) + acc.Write(sw, "acc"); + else if (o is CT_Bar bar) + bar.Write(sw, "bar"); + else if (o is CT_BorderBox box) + box.Write(sw, "borderBox"); + else if (o is CT_Box ctBox) + ctBox.Write(sw, "box"); + else if (o is CT_D d) + d.Write(sw, "d"); + else if (o is CT_EqArr arr) + arr.Write(sw, "eqArr"); + else if (o is CT_F f) + f.Write(sw, "f"); + else if (o is CT_GroupChr chr) + chr.Write(sw, "groupChr"); + else if (o is CT_LimLow low) + low.Write(sw, "limLow"); + else if (o is CT_M m) + m.Write(sw, "m"); + else if (o is CT_Nary nary) + nary.Write(sw, "nary"); + else if (o is CT_OMath math) + math.Write(sw, "oMath"); + else if (o is CT_OMathPara para) + para.Write(sw, "oMathPara"); + else if (o is CT_Phant phant) + phant.Write(sw, "phant"); + else if (o is CT_R r) + r.Write(sw, "r"); + else if (o is CT_Rad rad) + rad.Write(sw, "rad"); + else if (o is CT_SPre pre) + pre.Write(sw, "sPre"); + else if (o is CT_SSub sub) + sub.Write(sw, "sSub"); + else if (o is CT_SSup sSup) + sSup.Write(sw, "sSup"); + else if (o is CT_MarkupRange range) + range.Write(sw, "bookmarkEnd"); + else if (o is CT_Bookmark bookmark) + bookmark.Write(sw, "bookmarkStart"); + else if (o is CT_MarkupRange markupRange) + markupRange.Write(sw, "commentRangeEnd"); + else if (o is CT_MarkupRange ctMarkupRange) + ctMarkupRange.Write(sw, "commentRangeStart"); + else if (o is CT_CustomXmlRun run) + run.Write(sw, "customXml"); + else if (o is CT_Markup markup) + markup.Write(sw, "customXmlDelRangeEnd"); + else if (o is CT_TrackChange trackChange) + trackChange.Write(sw, "customXmlDelRangeStart"); + else if (o is CT_Markup ctMarkup) + ctMarkup.Write(sw, "customXmlInsRangeEnd"); + else if (o is CT_LimUpp upp) + upp.Write(sw, "limUpp"); + else if (o is CT_Markup markup1) + markup1.Write(sw, "customXmlMoveFromRangeEnd"); + else if (o is CT_TrackChange ctTrackChange) + ctTrackChange.Write(sw, "customXmlMoveFromRangeStart"); + else if (o is CT_Markup ctMarkup1) + ctMarkup1.Write(sw, "customXmlMoveToRangeEnd"); + else if (o is CT_TrackChange change1) + change1.Write(sw, "customXmlMoveToRangeStart"); + else if (o is CT_RunTrackChange runTrackChange) + runTrackChange.Write(sw, "del"); + else if (o is CT_RunTrackChange ctRunTrackChange) + ctRunTrackChange.Write(sw, "ins"); + else if (o is CT_RunTrackChange trackChange1) + trackChange1.Write(sw, "moveFrom"); + else if (o is CT_MarkupRange range1) + range1.Write(sw, "moveFromRangeEnd"); + else if (o is CT_MoveBookmark moveBookmark) + moveBookmark.Write(sw, "moveFromRangeStart"); + else if (o is CT_RunTrackChange runTrackChange1) + runTrackChange1.Write(sw, "moveTo"); + else if (o is CT_MarkupRange markupRange1) + markupRange1.Write(sw, "moveToRangeEnd"); + else if (o is CT_MoveBookmark ctMoveBookmark) + ctMoveBookmark.Write(sw, "moveToRangeStart"); + else if (o is CT_Perm perm) + perm.Write(sw, "permEnd"); + else if (o is CT_PermStart start) + start.Write(sw, "permStart"); + else if (o is CT_ProofErr err) + err.Write(sw, "proofErr"); + else if (o is CT_R ctR) + ctR.Write(sw, "r"); + else if (o is CT_SdtRun sdtRun) + sdtRun.Write(sw, "sdt"); + else if (o is CT_SmartTagRun tagRun) + tagRun.Write(sw, "smartTag"); } sw.Write(string.Format(""); foreach (object o in this.Items) { - if (o is CT_PermStart) - ((CT_PermStart)o).Write(sw, "permStart"); - else if (o is CT_SdtCell) - ((CT_SdtCell)o).Write(sw, "sdt"); - else if (o is CT_Markup) - ((CT_Markup)o).Write(sw, "customXmlMoveToRangeEnd"); - else if (o is CT_ProofErr) - ((CT_ProofErr)o).Write(sw, "proofErr"); - else if (o is CT_Markup) - ((CT_Markup)o).Write(sw, "customXmlDelRangeEnd"); - else if (o is CT_MarkupRange) - ((CT_MarkupRange)o).Write(sw, "moveFromRangeEnd"); - else if (o is CT_MoveBookmark) - ((CT_MoveBookmark)o).Write(sw, "moveFromRangeStart"); - else if (o is CT_RunTrackChange) - ((CT_RunTrackChange)o).Write(sw, "moveTo"); - else if (o is CT_MarkupRange) - ((CT_MarkupRange)o).Write(sw, "moveToRangeEnd"); - else if (o is CT_MoveBookmark) - ((CT_MoveBookmark)o).Write(sw, "moveToRangeStart"); - else if (o is CT_TrackChange) - ((CT_TrackChange)o).Write(sw, "customXmlMoveToRangeStart"); - else if (o is CT_Tc) - ((CT_Tc)o).Write(sw, "tc"); - else if (o is CT_RunTrackChange) - ((CT_RunTrackChange)o).Write(sw, "del"); - else if (o is CT_Perm) - ((CT_Perm)o).Write(sw, "permEnd"); - else if (o is CT_MarkupRange) - ((CT_MarkupRange)o).Write(sw, "commentRangeStart"); - else if (o is CT_RunTrackChange) - ((CT_RunTrackChange)o).Write(sw, "moveFrom"); - else if (o is CT_TrackChange) - ((CT_TrackChange)o).Write(sw, "customXmlMoveFromRangeStart"); - else if (o is CT_CustomXmlCell) - ((CT_CustomXmlCell)o).Write(sw, "customXml"); - else if (o is CT_OMath) - ((CT_OMath)o).Write(sw, "oMath"); - else if (o is CT_TrackChange) - ((CT_TrackChange)o).Write(sw, "customXmlDelRangeStart"); - else if (o is CT_Markup) - ((CT_Markup)o).Write(sw, "customXmlInsRangeEnd"); - else if (o is CT_RunTrackChange) - ((CT_RunTrackChange)o).Write(sw, "ins"); - else if (o is CT_TrackChange) - ((CT_TrackChange)o).Write(sw, "customXmlInsRangeStart"); - else if (o is CT_Markup) - ((CT_Markup)o).Write(sw, "customXmlMoveFromRangeEnd"); - else if (o is CT_OMathPara) - ((CT_OMathPara)o).Write(sw, "oMathPara"); - else if (o is CT_MarkupRange) - ((CT_MarkupRange)o).Write(sw, "bookmarkEnd"); - else if (o is CT_Bookmark) - ((CT_Bookmark)o).Write(sw, "bookmarkStart"); - else if (o is CT_MarkupRange) - ((CT_MarkupRange)o).Write(sw, "commentRangeEnd"); + if (o is CT_PermStart start) + start.Write(sw, "permStart"); + else if (o is CT_SdtCell cell) + cell.Write(sw, "sdt"); + else if (o is CT_Markup markup) + markup.Write(sw, "customXmlMoveToRangeEnd"); + else if (o is CT_ProofErr err) + err.Write(sw, "proofErr"); + else if (o is CT_Markup ctMarkup) + ctMarkup.Write(sw, "customXmlDelRangeEnd"); + else if (o is CT_MarkupRange range) + range.Write(sw, "moveFromRangeEnd"); + else if (o is CT_MoveBookmark bookmark) + bookmark.Write(sw, "moveFromRangeStart"); + else if (o is CT_RunTrackChange change) + change.Write(sw, "moveTo"); + else if (o is CT_MarkupRange markupRange) + markupRange.Write(sw, "moveToRangeEnd"); + else if (o is CT_MoveBookmark moveBookmark) + moveBookmark.Write(sw, "moveToRangeStart"); + else if (o is CT_TrackChange trackChange) + trackChange.Write(sw, "customXmlMoveToRangeStart"); + else if (o is CT_Tc tc) + tc.Write(sw, "tc"); + else if (o is CT_RunTrackChange runTrackChange) + runTrackChange.Write(sw, "del"); + else if (o is CT_Perm perm) + perm.Write(sw, "permEnd"); + else if (o is CT_MarkupRange ctMarkupRange) + ctMarkupRange.Write(sw, "commentRangeStart"); + else if (o is CT_RunTrackChange ctRunTrackChange) + ctRunTrackChange.Write(sw, "moveFrom"); + else if (o is CT_TrackChange ctTrackChange) + ctTrackChange.Write(sw, "customXmlMoveFromRangeStart"); + else if (o is CT_CustomXmlCell xmlCell) + xmlCell.Write(sw, "customXml"); + else if (o is CT_OMath math) + math.Write(sw, "oMath"); + else if (o is CT_TrackChange change1) + change1.Write(sw, "customXmlDelRangeStart"); + else if (o is CT_Markup markup1) + markup1.Write(sw, "customXmlInsRangeEnd"); + else if (o is CT_RunTrackChange trackChange1) + trackChange1.Write(sw, "ins"); + else if (o is CT_TrackChange ctTrackChange1) + ctTrackChange1.Write(sw, "customXmlInsRangeStart"); + else if (o is CT_Markup ctMarkup1) + ctMarkup1.Write(sw, "customXmlMoveFromRangeEnd"); + else if (o is CT_OMathPara para) + para.Write(sw, "oMathPara"); + else if (o is CT_MarkupRange range1) + range1.Write(sw, "bookmarkEnd"); + else if (o is CT_Bookmark ctBookmark) + ctBookmark.Write(sw, "bookmarkStart"); + else if (o is CT_MarkupRange markupRange1) + markupRange1.Write(sw, "commentRangeEnd"); } sw.WriteEndW(nodeName); } @@ -1152,64 +1152,64 @@ internal void Write(StreamWriter sw, string nodeName) sw.Write(">"); foreach (object o in this.Items) { - if (o is CT_Bookmark) - ((CT_Bookmark)o).Write(sw, "bookmarkStart"); - else if (o is CT_OMath) - ((CT_OMath)o).Write(sw, "oMath"); - else if (o is CT_OMathPara) - ((CT_OMathPara)o).Write(sw, "oMathPara"); - else if (o is CT_MarkupRange) - ((CT_MarkupRange)o).Write(sw, "bookmarkEnd"); - else if (o is CT_MarkupRange) - ((CT_MarkupRange)o).Write(sw, "commentRangeEnd"); - else if (o is CT_MarkupRange) - ((CT_MarkupRange)o).Write(sw, "commentRangeStart"); - else if (o is CT_CustomXmlBlock) - ((CT_CustomXmlBlock)o).Write(sw, "customXml"); - else if (o is CT_Markup) - ((CT_Markup)o).Write(sw, "customXmlDelRangeEnd"); - else if (o is CT_TrackChange) - ((CT_TrackChange)o).Write(sw, "customXmlDelRangeStart"); - else if (o is CT_Markup) - ((CT_Markup)o).Write(sw, "customXmlInsRangeEnd"); - else if (o is CT_TrackChange) - ((CT_TrackChange)o).Write(sw, "customXmlInsRangeStart"); - else if (o is CT_Markup) - ((CT_Markup)o).Write(sw, "customXmlMoveFromRangeEnd"); - else if (o is CT_TrackChange) - ((CT_TrackChange)o).Write(sw, "customXmlMoveFromRangeStart"); - else if (o is CT_Markup) - ((CT_Markup)o).Write(sw, "customXmlMoveToRangeEnd"); - else if (o is CT_TrackChange) - ((CT_TrackChange)o).Write(sw, "customXmlMoveToRangeStart"); - else if (o is CT_RunTrackChange) - ((CT_RunTrackChange)o).Write(sw, "del"); - else if (o is CT_RunTrackChange) - ((CT_RunTrackChange)o).Write(sw, "ins"); - else if (o is CT_RunTrackChange) - ((CT_RunTrackChange)o).Write(sw, "moveFrom"); - else if (o is CT_MarkupRange) - ((CT_MarkupRange)o).Write(sw, "moveFromRangeEnd"); - else if (o is CT_MoveBookmark) - ((CT_MoveBookmark)o).Write(sw, "moveFromRangeStart"); - else if (o is CT_RunTrackChange) - ((CT_RunTrackChange)o).Write(sw, "moveTo"); - else if (o is CT_MarkupRange) - ((CT_MarkupRange)o).Write(sw, "moveToRangeEnd"); - else if (o is CT_MoveBookmark) - ((CT_MoveBookmark)o).Write(sw, "moveToRangeStart"); - else if (o is CT_P) - ((CT_P)o).Write(sw, "p"); - else if (o is CT_Perm) - ((CT_Perm)o).Write(sw, "permEnd"); - else if (o is CT_PermStart) - ((CT_PermStart)o).Write(sw, "permStart"); - else if (o is CT_ProofErr) - ((CT_ProofErr)o).Write(sw, "proofErr"); - else if (o is CT_SdtBlock) - ((CT_SdtBlock)o).Write(sw, "sdt"); - else if (o is CT_Tbl) - ((CT_Tbl)o).Write(sw, "tbl"); + if (o is CT_Bookmark bookmark) + bookmark.Write(sw, "bookmarkStart"); + else if (o is CT_OMath math) + math.Write(sw, "oMath"); + else if (o is CT_OMathPara para) + para.Write(sw, "oMathPara"); + else if (o is CT_MarkupRange range) + range.Write(sw, "bookmarkEnd"); + else if (o is CT_MarkupRange markupRange) + markupRange.Write(sw, "commentRangeEnd"); + else if (o is CT_MarkupRange ctMarkupRange) + ctMarkupRange.Write(sw, "commentRangeStart"); + else if (o is CT_CustomXmlBlock block) + block.Write(sw, "customXml"); + else if (o is CT_Markup markup) + markup.Write(sw, "customXmlDelRangeEnd"); + else if (o is CT_TrackChange change) + change.Write(sw, "customXmlDelRangeStart"); + else if (o is CT_Markup ctMarkup) + ctMarkup.Write(sw, "customXmlInsRangeEnd"); + else if (o is CT_TrackChange trackChange) + trackChange.Write(sw, "customXmlInsRangeStart"); + else if (o is CT_Markup markup1) + markup1.Write(sw, "customXmlMoveFromRangeEnd"); + else if (o is CT_TrackChange ctTrackChange) + ctTrackChange.Write(sw, "customXmlMoveFromRangeStart"); + else if (o is CT_Markup ctMarkup1) + ctMarkup1.Write(sw, "customXmlMoveToRangeEnd"); + else if (o is CT_TrackChange change1) + change1.Write(sw, "customXmlMoveToRangeStart"); + else if (o is CT_RunTrackChange runTrackChange) + runTrackChange.Write(sw, "del"); + else if (o is CT_RunTrackChange ctRunTrackChange) + ctRunTrackChange.Write(sw, "ins"); + else if (o is CT_RunTrackChange trackChange1) + trackChange1.Write(sw, "moveFrom"); + else if (o is CT_MarkupRange range1) + range1.Write(sw, "moveFromRangeEnd"); + else if (o is CT_MoveBookmark moveBookmark) + moveBookmark.Write(sw, "moveFromRangeStart"); + else if (o is CT_RunTrackChange runTrackChange1) + runTrackChange1.Write(sw, "moveTo"); + else if (o is CT_MarkupRange markupRange1) + markupRange1.Write(sw, "moveToRangeEnd"); + else if (o is CT_MoveBookmark ctMoveBookmark) + ctMoveBookmark.Write(sw, "moveToRangeStart"); + else if (o is CT_P p) + p.Write(sw, "p"); + else if (o is CT_Perm perm) + perm.Write(sw, "permEnd"); + else if (o is CT_PermStart start) + start.Write(sw, "permStart"); + else if (o is CT_ProofErr err) + err.Write(sw, "proofErr"); + else if (o is CT_SdtBlock sdtBlock) + sdtBlock.Write(sw, "sdt"); + else if (o is CT_Tbl tbl) + tbl.Write(sw, "tbl"); } sw.WriteEndW(nodeName); } @@ -1648,62 +1648,62 @@ internal void Write(StreamWriter sw, string nodeName) sw.Write(">"); foreach (object o in this.Items) { - if (o is CT_OMath) - ((CT_OMath)o).Write(sw, "oMath"); - else if (o is CT_OMathPara) - ((CT_OMathPara)o).Write(sw, "oMathPara"); - else if (o is CT_MarkupRange) - ((CT_MarkupRange)o).Write(sw, "bookmarkEnd"); - else if (o is CT_Bookmark) - ((CT_Bookmark)o).Write(sw, "bookmarkStart"); - else if (o is CT_MarkupRange) - ((CT_MarkupRange)o).Write(sw, "commentRangeEnd"); - else if (o is CT_MarkupRange) - ((CT_MarkupRange)o).Write(sw, "commentRangeStart"); - else if (o is CT_CustomXmlRow) - ((CT_CustomXmlRow)o).Write(sw, "customXml"); - else if (o is CT_Markup) - ((CT_Markup)o).Write(sw, "customXmlDelRangeEnd"); - else if (o is CT_TrackChange) - ((CT_TrackChange)o).Write(sw, "customXmlDelRangeStart"); - else if (o is CT_Markup) - ((CT_Markup)o).Write(sw, "customXmlInsRangeEnd"); - else if (o is CT_TrackChange) - ((CT_TrackChange)o).Write(sw, "customXmlInsRangeStart"); - else if (o is CT_Markup) - ((CT_Markup)o).Write(sw, "customXmlMoveFromRangeEnd"); - else if (o is CT_TrackChange) - ((CT_TrackChange)o).Write(sw, "customXmlMoveFromRangeStart"); - else if (o is CT_Markup) - ((CT_Markup)o).Write(sw, "customXmlMoveToRangeEnd"); - else if (o is CT_TrackChange) - ((CT_TrackChange)o).Write(sw, "customXmlMoveToRangeStart"); - else if (o is CT_RunTrackChange) - ((CT_RunTrackChange)o).Write(sw, "del"); - else if (o is CT_RunTrackChange) - ((CT_RunTrackChange)o).Write(sw, "ins"); - else if (o is CT_RunTrackChange) - ((CT_RunTrackChange)o).Write(sw, "moveFrom"); - else if (o is CT_MarkupRange) - ((CT_MarkupRange)o).Write(sw, "moveFromRangeEnd"); - else if (o is CT_MoveBookmark) - ((CT_MoveBookmark)o).Write(sw, "moveFromRangeStart"); - else if (o is CT_RunTrackChange) - ((CT_RunTrackChange)o).Write(sw, "moveTo"); - else if (o is CT_MarkupRange) - ((CT_MarkupRange)o).Write(sw, "moveToRangeEnd"); - else if (o is CT_MoveBookmark) - ((CT_MoveBookmark)o).Write(sw, "moveToRangeStart"); - else if (o is CT_Perm) - ((CT_Perm)o).Write(sw, "permEnd"); - else if (o is CT_PermStart) - ((CT_PermStart)o).Write(sw, "permStart"); - else if (o is CT_ProofErr) - ((CT_ProofErr)o).Write(sw, "proofErr"); - else if (o is CT_SdtRow) - ((CT_SdtRow)o).Write(sw, "sdt"); - else if (o is CT_Row) - ((CT_Row)o).Write(sw, "tr"); + if (o is CT_OMath math) + math.Write(sw, "oMath"); + else if (o is CT_OMathPara para) + para.Write(sw, "oMathPara"); + else if (o is CT_MarkupRange range) + range.Write(sw, "bookmarkEnd"); + else if (o is CT_Bookmark bookmark) + bookmark.Write(sw, "bookmarkStart"); + else if (o is CT_MarkupRange markupRange) + markupRange.Write(sw, "commentRangeEnd"); + else if (o is CT_MarkupRange ctMarkupRange) + ctMarkupRange.Write(sw, "commentRangeStart"); + else if (o is CT_CustomXmlRow row) + row.Write(sw, "customXml"); + else if (o is CT_Markup markup) + markup.Write(sw, "customXmlDelRangeEnd"); + else if (o is CT_TrackChange change) + change.Write(sw, "customXmlDelRangeStart"); + else if (o is CT_Markup ctMarkup) + ctMarkup.Write(sw, "customXmlInsRangeEnd"); + else if (o is CT_TrackChange trackChange) + trackChange.Write(sw, "customXmlInsRangeStart"); + else if (o is CT_Markup markup1) + markup1.Write(sw, "customXmlMoveFromRangeEnd"); + else if (o is CT_TrackChange ctTrackChange) + ctTrackChange.Write(sw, "customXmlMoveFromRangeStart"); + else if (o is CT_Markup ctMarkup1) + ctMarkup1.Write(sw, "customXmlMoveToRangeEnd"); + else if (o is CT_TrackChange change1) + change1.Write(sw, "customXmlMoveToRangeStart"); + else if (o is CT_RunTrackChange runTrackChange) + runTrackChange.Write(sw, "del"); + else if (o is CT_RunTrackChange ctRunTrackChange) + ctRunTrackChange.Write(sw, "ins"); + else if (o is CT_RunTrackChange trackChange1) + trackChange1.Write(sw, "moveFrom"); + else if (o is CT_MarkupRange range1) + range1.Write(sw, "moveFromRangeEnd"); + else if (o is CT_MoveBookmark moveBookmark) + moveBookmark.Write(sw, "moveFromRangeStart"); + else if (o is CT_RunTrackChange runTrackChange1) + runTrackChange1.Write(sw, "moveTo"); + else if (o is CT_MarkupRange markupRange1) + markupRange1.Write(sw, "moveToRangeEnd"); + else if (o is CT_MoveBookmark ctMoveBookmark) + ctMoveBookmark.Write(sw, "moveToRangeStart"); + else if (o is CT_Perm perm) + perm.Write(sw, "permEnd"); + else if (o is CT_PermStart start) + start.Write(sw, "permStart"); + else if (o is CT_ProofErr err) + err.Write(sw, "proofErr"); + else if (o is CT_SdtRow sdtRow) + sdtRow.Write(sw, "sdt"); + else if (o is CT_Row ctRow) + ctRow.Write(sw, "tr"); } sw.WriteEndW(nodeName); } @@ -1956,46 +1956,46 @@ internal void Write(StreamWriter sw, string nodeName) SdtPrElementType t= this.itemsElementNameField[i]; if (o is CT_Empty && t== SdtPrElementType.richText) sw.Write(""); - else if (o is CT_SdtDocPart&& t == SdtPrElementType.docPartList) - ((CT_SdtDocPart)o).Write(sw, "docPartList"); - else if (o is CT_SdtDocPart&& t == SdtPrElementType.docPartObj) - ((CT_SdtDocPart)o).Write(sw, "docPartObj"); - else if (o is CT_SdtDropDownList) - ((CT_SdtDropDownList)o).Write(sw, "dropDownList"); + else if (o is CT_SdtDocPart part&& t == SdtPrElementType.docPartList) + part.Write(sw, "docPartList"); + else if (o is CT_SdtDocPart docPart&& t == SdtPrElementType.docPartObj) + docPart.Write(sw, "docPartObj"); + else if (o is CT_SdtDropDownList list) + list.Write(sw, "dropDownList"); else if (o is CT_Empty&& t== SdtPrElementType.equation) sw.Write(""); else if (o is CT_Empty&& t== SdtPrElementType.group) sw.Write(""); - else if (o is CT_DecimalNumber&& t== SdtPrElementType.id) - ((CT_DecimalNumber)o).Write(sw, "id"); - else if (o is CT_Lock) - ((CT_Lock)o).Write(sw, "lock"); - else if (o is CT_SdtDate) - ((CT_SdtDate)o).Write(sw, "date"); - else if (o is CT_Placeholder) - ((CT_Placeholder)o).Write(sw, "placeholder"); - else if (o is CT_RPr) - ((CT_RPr)o).Write(sw, "rPr"); - else if (o is CT_OnOff && t== SdtPrElementType.showingPlcHdr) - ((CT_OnOff)o).Write(sw, "showingPlcHdr"); - else if (o is CT_String&& t== SdtPrElementType.tag) - ((CT_String)o).Write(sw, "tag"); - else if (o is CT_OnOff && t== SdtPrElementType.temporary) - ((CT_OnOff)o).Write(sw, "temporary"); - else if (o is CT_SdtText) - ((CT_SdtText)o).Write(sw, "text"); + else if (o is CT_DecimalNumber number&& t== SdtPrElementType.id) + number.Write(sw, "id"); + else if (o is CT_Lock @lock) + @lock.Write(sw, "lock"); + else if (o is CT_SdtDate date) + date.Write(sw, "date"); + else if (o is CT_Placeholder placeholder) + placeholder.Write(sw, "placeholder"); + else if (o is CT_RPr pr) + pr.Write(sw, "rPr"); + else if (o is CT_OnOff off && t== SdtPrElementType.showingPlcHdr) + off.Write(sw, "showingPlcHdr"); + else if (o is CT_String ctString&& t== SdtPrElementType.tag) + ctString.Write(sw, "tag"); + else if (o is CT_OnOff onOff && t== SdtPrElementType.temporary) + onOff.Write(sw, "temporary"); + else if (o is CT_SdtText text) + text.Write(sw, "text"); else if (o is CT_Empty && t== SdtPrElementType.picture) sw.Write(""); - else if (o is CT_String&& t== SdtPrElementType.alias) - ((CT_String)o).Write(sw, "alias"); + else if (o is CT_String s&& t== SdtPrElementType.alias) + s.Write(sw, "alias"); else if (o is CT_Empty && t== SdtPrElementType.bibliography) sw.Write(""); else if (o is CT_Empty && t== SdtPrElementType.citation) sw.Write(""); - else if (o is CT_SdtComboBox) - ((CT_SdtComboBox)o).Write(sw, "comboBox"); - else if (o is CT_DataBinding) - ((CT_DataBinding)o).Write(sw, "dataBinding"); + else if (o is CT_SdtComboBox box) + box.Write(sw, "comboBox"); + else if (o is CT_DataBinding binding) + binding.Write(sw, "dataBinding"); } sw.WriteEndW(nodeName); @@ -2420,70 +2420,70 @@ internal void Write(StreamWriter sw, string nodeName) sw.Write(">"); foreach (object o in this.Items) { - if (o is CT_PermStart) - ((CT_PermStart)o).Write(sw, "permStart"); - else if (o is CT_MarkupRange) - ((CT_MarkupRange)o).Write(sw, "moveToRangeEnd"); - else if (o is CT_MoveBookmark) - ((CT_MoveBookmark)o).Write(sw, "moveToRangeStart"); - else if (o is CT_MarkupRange) - ((CT_MarkupRange)o).Write(sw, "commentRangeEnd"); - else if (o is CT_MarkupRange) - ((CT_MarkupRange)o).Write(sw, "commentRangeStart"); - else if (o is CT_CustomXmlRun) - ((CT_CustomXmlRun)o).Write(sw, "customXml"); - else if (o is CT_Markup) - ((CT_Markup)o).Write(sw, "customXmlDelRangeEnd"); - else if (o is CT_TrackChange) - ((CT_TrackChange)o).Write(sw, "customXmlDelRangeStart"); - else if (o is CT_Markup) - ((CT_Markup)o).Write(sw, "customXmlInsRangeEnd"); - else if (o is CT_TrackChange) - ((CT_TrackChange)o).Write(sw, "customXmlInsRangeStart"); - else if (o is CT_Markup) - ((CT_Markup)o).Write(sw, "customXmlMoveFromRangeEnd"); - else if (o is CT_TrackChange) - ((CT_TrackChange)o).Write(sw, "customXmlMoveFromRangeStart"); - else if (o is CT_Markup) - ((CT_Markup)o).Write(sw, "customXmlMoveToRangeEnd"); - else if (o is CT_TrackChange) - ((CT_TrackChange)o).Write(sw, "customXmlMoveToRangeStart"); - else if (o is CT_RunTrackChange) - ((CT_RunTrackChange)o).Write(sw, "del"); - else if (o is CT_SimpleField) - ((CT_SimpleField)o).Write(sw, "fldSimple"); - else if (o is CT_Hyperlink1) - ((CT_Hyperlink1)o).Write(sw, "hyperlink"); - else if (o is CT_RunTrackChange) - ((CT_RunTrackChange)o).Write(sw, "ins"); - else if (o is CT_RunTrackChange) - ((CT_RunTrackChange)o).Write(sw, "moveFrom"); - else if (o is CT_Bookmark) - ((CT_Bookmark)o).Write(sw, "bookmarkStart"); - else if (o is CT_MoveBookmark) - ((CT_MoveBookmark)o).Write(sw, "moveFromRangeStart"); - else if (o is CT_RunTrackChange) - ((CT_RunTrackChange)o).Write(sw, "moveTo"); - else if (o is CT_Perm) - ((CT_Perm)o).Write(sw, "permEnd"); - else if (o is CT_OMath) - ((CT_OMath)o).Write(sw, "oMath"); - else if (o is CT_ProofErr) - ((CT_ProofErr)o).Write(sw, "proofErr"); - else if (o is CT_R) - ((CT_R)o).Write(sw, "r"); - else if (o is CT_SdtRun) - ((CT_SdtRun)o).Write(sw, "sdt"); - else if (o is CT_SmartTagRun) - ((CT_SmartTagRun)o).Write(sw, "smartTag"); - else if (o is CT_Rel) - ((CT_Rel)o).Write(sw, "subDoc"); - else if (o is CT_MarkupRange) - ((CT_MarkupRange)o).Write(sw, "moveFromRangeEnd"); - else if (o is CT_OMathPara) - ((CT_OMathPara)o).Write(sw, "oMathPara"); - else if (o is CT_MarkupRange) - ((CT_MarkupRange)o).Write(sw, "bookmarkEnd"); + if (o is CT_PermStart start) + start.Write(sw, "permStart"); + else if (o is CT_MarkupRange range) + range.Write(sw, "moveToRangeEnd"); + else if (o is CT_MoveBookmark bookmark) + bookmark.Write(sw, "moveToRangeStart"); + else if (o is CT_MarkupRange markupRange) + markupRange.Write(sw, "commentRangeEnd"); + else if (o is CT_MarkupRange ctMarkupRange) + ctMarkupRange.Write(sw, "commentRangeStart"); + else if (o is CT_CustomXmlRun run) + run.Write(sw, "customXml"); + else if (o is CT_Markup markup) + markup.Write(sw, "customXmlDelRangeEnd"); + else if (o is CT_TrackChange change) + change.Write(sw, "customXmlDelRangeStart"); + else if (o is CT_Markup ctMarkup) + ctMarkup.Write(sw, "customXmlInsRangeEnd"); + else if (o is CT_TrackChange trackChange) + trackChange.Write(sw, "customXmlInsRangeStart"); + else if (o is CT_Markup markup1) + markup1.Write(sw, "customXmlMoveFromRangeEnd"); + else if (o is CT_TrackChange ctTrackChange) + ctTrackChange.Write(sw, "customXmlMoveFromRangeStart"); + else if (o is CT_Markup ctMarkup1) + ctMarkup1.Write(sw, "customXmlMoveToRangeEnd"); + else if (o is CT_TrackChange change1) + change1.Write(sw, "customXmlMoveToRangeStart"); + else if (o is CT_RunTrackChange runTrackChange) + runTrackChange.Write(sw, "del"); + else if (o is CT_SimpleField field) + field.Write(sw, "fldSimple"); + else if (o is CT_Hyperlink1 hyperlink1) + hyperlink1.Write(sw, "hyperlink"); + else if (o is CT_RunTrackChange ctRunTrackChange) + ctRunTrackChange.Write(sw, "ins"); + else if (o is CT_RunTrackChange trackChange1) + trackChange1.Write(sw, "moveFrom"); + else if (o is CT_Bookmark ctBookmark) + ctBookmark.Write(sw, "bookmarkStart"); + else if (o is CT_MoveBookmark moveBookmark) + moveBookmark.Write(sw, "moveFromRangeStart"); + else if (o is CT_RunTrackChange runTrackChange1) + runTrackChange1.Write(sw, "moveTo"); + else if (o is CT_Perm perm) + perm.Write(sw, "permEnd"); + else if (o is CT_OMath math) + math.Write(sw, "oMath"); + else if (o is CT_ProofErr err) + err.Write(sw, "proofErr"); + else if (o is CT_R r) + r.Write(sw, "r"); + else if (o is CT_SdtRun sdtRun) + sdtRun.Write(sw, "sdt"); + else if (o is CT_SmartTagRun tagRun) + tagRun.Write(sw, "smartTag"); + else if (o is CT_Rel rel) + rel.Write(sw, "subDoc"); + else if (o is CT_MarkupRange range1) + range1.Write(sw, "moveFromRangeEnd"); + else if (o is CT_OMathPara para) + para.Write(sw, "oMathPara"); + else if (o is CT_MarkupRange markupRange1) + markupRange1.Write(sw, "bookmarkEnd"); } sw.WriteEndW(nodeName); } diff --git a/OpenXmlFormats/Wordprocessing/Table.cs b/OpenXmlFormats/Wordprocessing/Table.cs index 2e609e03f..9d3241851 100644 --- a/OpenXmlFormats/Wordprocessing/Table.cs +++ b/OpenXmlFormats/Wordprocessing/Table.cs @@ -282,39 +282,39 @@ internal void Write(StreamWriter sw, string nodeName) sw.Write(">"); foreach (object o in this.Items) { - if (o is CT_Markup) - ((CT_Markup)o).Write(sw, "customXmlMoveToRangeEnd"); - - else if (o is CT_MarkupRange) - ((CT_MarkupRange)o).Write(sw, "moveToRangeEnd"); - else if (o is CT_MoveBookmark) - ((CT_MoveBookmark)o).Write(sw, "moveToRangeStart"); - else if (o is CT_Markup) - ((CT_Markup)o).Write(sw, "customXmlDelRangeEnd"); - else if (o is CT_MoveBookmark) - ((CT_MoveBookmark)o).Write(sw, "moveFromRangeStart"); - else if (o is CT_MarkupRange) - ((CT_MarkupRange)o).Write(sw, "bookmarkEnd"); - else if (o is CT_Bookmark) - ((CT_Bookmark)o).Write(sw, "bookmarkStart"); - else if (o is CT_MarkupRange) - ((CT_MarkupRange)o).Write(sw, "commentRangeEnd"); - else if (o is CT_MarkupRange) - ((CT_MarkupRange)o).Write(sw, "commentRangeStart"); - else if (o is CT_TrackChange) - ((CT_TrackChange)o).Write(sw, "customXmlMoveToRangeStart"); - else if (o is CT_Markup) - ((CT_Markup)o).Write(sw, "customXmlInsRangeEnd"); - else if (o is CT_TrackChange) - ((CT_TrackChange)o).Write(sw, "customXmlInsRangeStart"); - else if (o is CT_TrackChange) - ((CT_TrackChange)o).Write(sw, "customXmlDelRangeStart"); - else if (o is CT_Markup) - ((CT_Markup)o).Write(sw, "customXmlMoveFromRangeEnd"); - else if (o is CT_TrackChange) - ((CT_TrackChange)o).Write(sw, "customXmlMoveFromRangeStart"); - else if (o is CT_MarkupRange) - ((CT_MarkupRange)o).Write(sw, "moveFromRangeEnd"); + if (o is CT_Markup markup) + markup.Write(sw, "customXmlMoveToRangeEnd"); + + else if (o is CT_MarkupRange range) + range.Write(sw, "moveToRangeEnd"); + else if (o is CT_MoveBookmark bookmark) + bookmark.Write(sw, "moveToRangeStart"); + else if (o is CT_Markup ctMarkup) + ctMarkup.Write(sw, "customXmlDelRangeEnd"); + else if (o is CT_MoveBookmark moveBookmark) + moveBookmark.Write(sw, "moveFromRangeStart"); + else if (o is CT_MarkupRange markupRange) + markupRange.Write(sw, "bookmarkEnd"); + else if (o is CT_Bookmark ctBookmark) + ctBookmark.Write(sw, "bookmarkStart"); + else if (o is CT_MarkupRange ctMarkupRange) + ctMarkupRange.Write(sw, "commentRangeEnd"); + else if (o is CT_MarkupRange range1) + range1.Write(sw, "commentRangeStart"); + else if (o is CT_TrackChange change) + change.Write(sw, "customXmlMoveToRangeStart"); + else if (o is CT_Markup markup1) + markup1.Write(sw, "customXmlInsRangeEnd"); + else if (o is CT_TrackChange trackChange) + trackChange.Write(sw, "customXmlInsRangeStart"); + else if (o is CT_TrackChange ctTrackChange) + ctTrackChange.Write(sw, "customXmlDelRangeStart"); + else if (o is CT_Markup ctMarkup1) + ctMarkup1.Write(sw, "customXmlMoveFromRangeEnd"); + else if (o is CT_TrackChange change1) + change1.Write(sw, "customXmlMoveFromRangeStart"); + else if (o is CT_MarkupRange markupRange1) + markupRange1.Write(sw, "moveFromRangeEnd"); } if (this.tblPr != null) this.tblPr.Write(sw, "tblPr"); @@ -322,62 +322,62 @@ internal void Write(StreamWriter sw, string nodeName) this.tblGrid.Write(sw, "tblGrid"); foreach (object o in this.Items1) { - if (o is CT_SdtRow) - ((CT_SdtRow)o).Write(sw, "sdt"); - else if (o is CT_CustomXmlRow) - ((CT_CustomXmlRow)o).Write(sw, "customXml"); - else if (o is CT_Markup) - ((CT_Markup)o).Write(sw, "customXmlInsRangeEnd"); - else if (o is CT_TrackChange) - ((CT_TrackChange)o).Write(sw, "customXmlInsRangeStart"); - else if (o is CT_Markup) - ((CT_Markup)o).Write(sw, "customXmlMoveFromRangeEnd"); - else if (o is CT_TrackChange) - ((CT_TrackChange)o).Write(sw, "customXmlMoveFromRangeStart"); - else if (o is CT_Markup) - ((CT_Markup)o).Write(sw, "customXmlMoveToRangeEnd"); - else if (o is CT_TrackChange) - ((CT_TrackChange)o).Write(sw, "customXmlMoveToRangeStart"); - else if (o is CT_RunTrackChange) - ((CT_RunTrackChange)o).Write(sw, "del"); - else if (o is CT_RunTrackChange) - ((CT_RunTrackChange)o).Write(sw, "ins"); - else if (o is CT_RunTrackChange) - ((CT_RunTrackChange)o).Write(sw, "moveFrom"); - else if (o is CT_MarkupRange) - ((CT_MarkupRange)o).Write(sw, "moveFromRangeEnd"); - else if (o is CT_MarkupRange) - ((CT_MarkupRange)o).Write(sw, "commentRangeStart"); - else if (o is CT_RunTrackChange) - ((CT_RunTrackChange)o).Write(sw, "moveTo"); - else if (o is CT_MarkupRange) - ((CT_MarkupRange)o).Write(sw, "moveToRangeEnd"); - else if (o is CT_MoveBookmark) - ((CT_MoveBookmark)o).Write(sw, "moveToRangeStart"); - else if (o is CT_Perm) - ((CT_Perm)o).Write(sw, "permEnd"); - else if (o is CT_PermStart) - ((CT_PermStart)o).Write(sw, "permStart"); - else if (o is CT_ProofErr) - ((CT_ProofErr)o).Write(sw, "proofErr"); - else if (o is CT_OMath) - ((CT_OMath)o).Write(sw, "oMath"); - else if (o is CT_Row) - ((CT_Row)o).Write(sw, "tr"); - else if (o is CT_MoveBookmark) - ((CT_MoveBookmark)o).Write(sw, "moveFromRangeStart"); - else if (o is CT_Markup) - ((CT_Markup)o).Write(sw, "customXmlDelRangeEnd"); - else if (o is CT_TrackChange) - ((CT_TrackChange)o).Write(sw, "customXmlDelRangeStart"); - else if (o is CT_OMathPara) - ((CT_OMathPara)o).Write(sw, "oMathPara"); - else if (o is CT_MarkupRange) - ((CT_MarkupRange)o).Write(sw, "bookmarkEnd"); - else if (o is CT_Bookmark) - ((CT_Bookmark)o).Write(sw, "bookmarkStart"); - else if (o is CT_MarkupRange) - ((CT_MarkupRange)o).Write(sw, "commentRangeEnd"); + if (o is CT_SdtRow row) + row.Write(sw, "sdt"); + else if (o is CT_CustomXmlRow xmlRow) + xmlRow.Write(sw, "customXml"); + else if (o is CT_Markup markup) + markup.Write(sw, "customXmlInsRangeEnd"); + else if (o is CT_TrackChange change) + change.Write(sw, "customXmlInsRangeStart"); + else if (o is CT_Markup ctMarkup) + ctMarkup.Write(sw, "customXmlMoveFromRangeEnd"); + else if (o is CT_TrackChange trackChange) + trackChange.Write(sw, "customXmlMoveFromRangeStart"); + else if (o is CT_Markup markup1) + markup1.Write(sw, "customXmlMoveToRangeEnd"); + else if (o is CT_TrackChange ctTrackChange) + ctTrackChange.Write(sw, "customXmlMoveToRangeStart"); + else if (o is CT_RunTrackChange runTrackChange) + runTrackChange.Write(sw, "del"); + else if (o is CT_RunTrackChange ctRunTrackChange) + ctRunTrackChange.Write(sw, "ins"); + else if (o is CT_RunTrackChange change1) + change1.Write(sw, "moveFrom"); + else if (o is CT_MarkupRange range) + range.Write(sw, "moveFromRangeEnd"); + else if (o is CT_MarkupRange markupRange) + markupRange.Write(sw, "commentRangeStart"); + else if (o is CT_RunTrackChange trackChange1) + trackChange1.Write(sw, "moveTo"); + else if (o is CT_MarkupRange ctMarkupRange) + ctMarkupRange.Write(sw, "moveToRangeEnd"); + else if (o is CT_MoveBookmark bookmark) + bookmark.Write(sw, "moveToRangeStart"); + else if (o is CT_Perm perm) + perm.Write(sw, "permEnd"); + else if (o is CT_PermStart start) + start.Write(sw, "permStart"); + else if (o is CT_ProofErr err) + err.Write(sw, "proofErr"); + else if (o is CT_OMath math) + math.Write(sw, "oMath"); + else if (o is CT_Row ctRow) + ctRow.Write(sw, "tr"); + else if (o is CT_MoveBookmark moveBookmark) + moveBookmark.Write(sw, "moveFromRangeStart"); + else if (o is CT_Markup ctMarkup1) + ctMarkup1.Write(sw, "customXmlDelRangeEnd"); + else if (o is CT_TrackChange ctTrackChange1) + ctTrackChange1.Write(sw, "customXmlDelRangeStart"); + else if (o is CT_OMathPara para) + para.Write(sw, "oMathPara"); + else if (o is CT_MarkupRange range1) + range1.Write(sw, "bookmarkEnd"); + else if (o is CT_Bookmark ctBookmark) + ctBookmark.Write(sw, "bookmarkStart"); + else if (o is CT_MarkupRange markupRange1) + markupRange1.Write(sw, "commentRangeEnd"); } sw.WriteEndW(nodeName); } @@ -3056,42 +3056,42 @@ internal void Write(StreamWriter sw, string nodeName) for (int i = 0; i < this.Items.Count; i++) { object o = this.Items[i]; - if (o is CT_DecimalNumber + if (o is CT_DecimalNumber number && this.ItemsElementName[i] == ItemsChoiceType2.gridBefore) - ((CT_DecimalNumber)o).Write(sw, "gridBefore"); - else if (o is CT_OnOff + number.Write(sw, "gridBefore"); + else if (o is CT_OnOff off && this.ItemsElementName[i] == ItemsChoiceType2.cantSplit) - ((CT_OnOff)o).Write(sw, "cantSplit"); - else if (o is CT_Cnf + off.Write(sw, "cantSplit"); + else if (o is CT_Cnf cnf && this.ItemsElementName[i] == ItemsChoiceType2.cnfStyle) - ((CT_Cnf)o).Write(sw, "cnfStyle"); - else if (o is CT_DecimalNumber + cnf.Write(sw, "cnfStyle"); + else if (o is CT_DecimalNumber decimalNumber && this.ItemsElementName[i] == ItemsChoiceType2.divId) - ((CT_DecimalNumber)o).Write(sw, "divId"); - else if (o is CT_DecimalNumber + decimalNumber.Write(sw, "divId"); + else if (o is CT_DecimalNumber ctDecimalNumber && this.ItemsElementName[i] == ItemsChoiceType2.gridAfter) - ((CT_DecimalNumber)o).Write(sw, "gridAfter"); - else if (o is CT_Height + ctDecimalNumber.Write(sw, "gridAfter"); + else if (o is CT_Height height && this.ItemsElementName[i] == ItemsChoiceType2.trHeight) - ((CT_Height)o).Write(sw, "trHeight"); - else if (o is CT_OnOff + height.Write(sw, "trHeight"); + else if (o is CT_OnOff onOff && this.ItemsElementName[i] == ItemsChoiceType2.hidden) - ((CT_OnOff)o).Write(sw, "hidden"); - else if (o is CT_TblWidth + onOff.Write(sw, "hidden"); + else if (o is CT_TblWidth width && this.ItemsElementName[i] == ItemsChoiceType2.tblCellSpacing) - ((CT_TblWidth)o).Write(sw, "tblCellSpacing"); - else if (o is CT_OnOff + width.Write(sw, "tblCellSpacing"); + else if (o is CT_OnOff ctOnOff && this.ItemsElementName[i] == ItemsChoiceType2.tblHeader) - ((CT_OnOff)o).Write(sw, "tblHeader"); - else if (o is CT_Jc + ctOnOff.Write(sw, "tblHeader"); + else if (o is CT_Jc jc && this.ItemsElementName[i] == ItemsChoiceType2.jc) - ((CT_Jc)o).Write(sw, "jc"); - else if (o is CT_TblWidth + jc.Write(sw, "jc"); + else if (o is CT_TblWidth tblWidth && this.ItemsElementName[i] == ItemsChoiceType2.wAfter) - ((CT_TblWidth)o).Write(sw, "wAfter"); - else if (o is CT_TblWidth + tblWidth.Write(sw, "wAfter"); + else if (o is CT_TblWidth ctTblWidth && this.ItemsElementName[i] == ItemsChoiceType2.wBefore) - ((CT_TblWidth)o).Write(sw, "wBefore"); + ctTblWidth.Write(sw, "wBefore"); } sw.WriteEndW(nodeName); } @@ -3543,66 +3543,66 @@ internal void Write(StreamWriter sw, string nodeName) this.tcPr.Write(sw, "tcPr"); foreach (object o in this.Items) { - if (o is CT_MarkupRange) - ((CT_MarkupRange)o).Write(sw, "commentRangeEnd"); - else if (o is CT_OMath) - ((CT_OMath)o).Write(sw, "oMath"); - else if (o is CT_OMathPara) - ((CT_OMathPara)o).Write(sw, "oMathPara"); - else if (o is CT_AltChunk) - ((CT_AltChunk)o).Write(sw, "altChunk"); - else if (o is CT_MarkupRange) - ((CT_MarkupRange)o).Write(sw, "bookmarkEnd"); - else if (o is CT_Bookmark) - ((CT_Bookmark)o).Write(sw, "bookmarkStart"); - else if (o is CT_MoveBookmark) - ((CT_MoveBookmark)o).Write(sw, "moveFromRangeStart"); - else if (o is CT_MarkupRange) - ((CT_MarkupRange)o).Write(sw, "commentRangeStart"); - else if (o is CT_CustomXmlBlock) - ((CT_CustomXmlBlock)o).Write(sw, "customXml"); - else if (o is CT_Markup) - ((CT_Markup)o).Write(sw, "customXmlDelRangeEnd"); - else if (o is CT_TrackChange) - ((CT_TrackChange)o).Write(sw, "customXmlDelRangeStart"); - else if (o is CT_Markup) - ((CT_Markup)o).Write(sw, "customXmlInsRangeEnd"); - else if (o is CT_TrackChange) - ((CT_TrackChange)o).Write(sw, "customXmlInsRangeStart"); - else if (o is CT_Markup) - ((CT_Markup)o).Write(sw, "customXmlMoveFromRangeEnd"); - else if (o is CT_TrackChange) - ((CT_TrackChange)o).Write(sw, "customXmlMoveFromRangeStart"); - else if (o is CT_Markup) - ((CT_Markup)o).Write(sw, "customXmlMoveToRangeEnd"); - else if (o is CT_TrackChange) - ((CT_TrackChange)o).Write(sw, "customXmlMoveToRangeStart"); - else if (o is CT_RunTrackChange) - ((CT_RunTrackChange)o).Write(sw, "del"); - else if (o is CT_RunTrackChange) - ((CT_RunTrackChange)o).Write(sw, "ins"); - else if (o is CT_RunTrackChange) - ((CT_RunTrackChange)o).Write(sw, "moveFrom"); - else if (o is CT_MarkupRange) - ((CT_MarkupRange)o).Write(sw, "moveFromRangeEnd"); - else if (o is CT_SdtBlock) - ((CT_SdtBlock)o).Write(sw, "sdt"); - else if (o is CT_RunTrackChange) - ((CT_RunTrackChange)o).Write(sw, "moveTo"); - else if (o is CT_MarkupRange) - ((CT_MarkupRange)o).Write(sw, "moveToRangeEnd"); - else if (o is CT_MoveBookmark) - ((CT_MoveBookmark)o).Write(sw, "moveToRangeStart"); - else if (o is CT_P) - ((CT_P)o).Write(sw, "p"); - else if (o is CT_Perm) - ((CT_Perm)o).Write(sw, "permEnd"); - else if (o is CT_ProofErr) - ((CT_ProofErr)o).Write(sw, "proofErr"); - else if (o is CT_PermStart) - ((CT_PermStart)o).Write(sw, "permStart"); - else if (o is CT_Tbl) - ((CT_Tbl)o).Write(sw, "tbl"); + if (o is CT_MarkupRange range) + range.Write(sw, "commentRangeEnd"); + else if (o is CT_OMath math) + math.Write(sw, "oMath"); + else if (o is CT_OMathPara para) + para.Write(sw, "oMathPara"); + else if (o is CT_AltChunk chunk) + chunk.Write(sw, "altChunk"); + else if (o is CT_MarkupRange markupRange) + markupRange.Write(sw, "bookmarkEnd"); + else if (o is CT_Bookmark bookmark) + bookmark.Write(sw, "bookmarkStart"); + else if (o is CT_MoveBookmark moveBookmark) + moveBookmark.Write(sw, "moveFromRangeStart"); + else if (o is CT_MarkupRange ctMarkupRange) + ctMarkupRange.Write(sw, "commentRangeStart"); + else if (o is CT_CustomXmlBlock block) + block.Write(sw, "customXml"); + else if (o is CT_Markup markup) + markup.Write(sw, "customXmlDelRangeEnd"); + else if (o is CT_TrackChange change) + change.Write(sw, "customXmlDelRangeStart"); + else if (o is CT_Markup ctMarkup) + ctMarkup.Write(sw, "customXmlInsRangeEnd"); + else if (o is CT_TrackChange trackChange) + trackChange.Write(sw, "customXmlInsRangeStart"); + else if (o is CT_Markup markup1) + markup1.Write(sw, "customXmlMoveFromRangeEnd"); + else if (o is CT_TrackChange ctTrackChange) + ctTrackChange.Write(sw, "customXmlMoveFromRangeStart"); + else if (o is CT_Markup ctMarkup1) + ctMarkup1.Write(sw, "customXmlMoveToRangeEnd"); + else if (o is CT_TrackChange change1) + change1.Write(sw, "customXmlMoveToRangeStart"); + else if (o is CT_RunTrackChange runTrackChange) + runTrackChange.Write(sw, "del"); + else if (o is CT_RunTrackChange ctRunTrackChange) + ctRunTrackChange.Write(sw, "ins"); + else if (o is CT_RunTrackChange trackChange1) + trackChange1.Write(sw, "moveFrom"); + else if (o is CT_MarkupRange range1) + range1.Write(sw, "moveFromRangeEnd"); + else if (o is CT_SdtBlock sdtBlock) + sdtBlock.Write(sw, "sdt"); + else if (o is CT_RunTrackChange runTrackChange1) + runTrackChange1.Write(sw, "moveTo"); + else if (o is CT_MarkupRange markupRange1) + markupRange1.Write(sw, "moveToRangeEnd"); + else if (o is CT_MoveBookmark ctMoveBookmark) + ctMoveBookmark.Write(sw, "moveToRangeStart"); + else if (o is CT_P p) + p.Write(sw, "p"); + else if (o is CT_Perm perm) + perm.Write(sw, "permEnd"); + else if (o is CT_ProofErr err) + err.Write(sw, "proofErr"); + else if (o is CT_PermStart start) + start.Write(sw, "permStart"); + else if (o is CT_Tbl tbl) + tbl.Write(sw, "tbl"); } sw.WriteEndW(nodeName); } @@ -4029,42 +4029,42 @@ public CT_TrPr() for (int i=0;i ChildContainers for (IEnumerator iterator = ChildRecords.GetEnumerator(); iterator.MoveNext(); ) { EscherRecord r = (EscherRecord)iterator.Current; - if (r is EscherContainerRecord) + if (r is EscherContainerRecord record) { - containers.Add((EscherContainerRecord)r); + containers.Add(record); } } return containers; @@ -379,10 +379,9 @@ public void GetRecordsById(short recordId, ref ArrayList out1) { Object er = it.Current; EscherRecord r = (EscherRecord)er; - if (r is EscherContainerRecord) + if (r is EscherContainerRecord record) { - EscherContainerRecord c = (EscherContainerRecord)r; - c.GetRecordsById(recordId, ref out1); + record.GetRecordsById(recordId, ref out1); } else if (r.RecordId == recordId) { diff --git a/main/DDF/EscherPropertyFactory.cs b/main/DDF/EscherPropertyFactory.cs index ec5ac3aa9..1327e3fa8 100644 --- a/main/DDF/EscherPropertyFactory.cs +++ b/main/DDF/EscherPropertyFactory.cs @@ -87,15 +87,15 @@ public List CreateProperties(byte[] data, int offset, short numP for (IEnumerator iterator = results.GetEnumerator(); iterator.MoveNext(); ) { EscherProperty p = (EscherProperty)iterator.Current; - if (p is EscherComplexProperty) + if (p is EscherComplexProperty property) { - if (p is EscherArrayProperty) + if (property is EscherArrayProperty arrayProperty) { - pos += ((EscherArrayProperty)p).SetArrayData(data, pos); + pos += arrayProperty.SetArrayData(data, pos); } else { - byte[] complexData = ((EscherComplexProperty)p).ComplexData; + byte[] complexData = property.ComplexData; int leftover = data.Length - pos; if (leftover < complexData.Length) { diff --git a/main/DDF/EscherSimpleProperty.cs b/main/DDF/EscherSimpleProperty.cs index a2a1d7833..f7d31bf06 100644 --- a/main/DDF/EscherSimpleProperty.cs +++ b/main/DDF/EscherSimpleProperty.cs @@ -101,9 +101,7 @@ public int PropertyValue public override bool Equals(Object o) { if (this == o) return true; - if (!(o is EscherSimpleProperty)) return false; - - EscherSimpleProperty escherSimpleProperty = (EscherSimpleProperty)o; + if (o is not EscherSimpleProperty escherSimpleProperty) return false; if (propertyValue != escherSimpleProperty.propertyValue) return false; if (Id != escherSimpleProperty.Id) return false; diff --git a/main/HPSF/CustomProperties.cs b/main/HPSF/CustomProperties.cs index b4b99b350..f59352d58 100644 --- a/main/HPSF/CustomProperties.cs +++ b/main/HPSF/CustomProperties.cs @@ -331,7 +331,7 @@ public bool ContainsKey(Object key) { //key is long - return (key is long && dictionary.ContainsKey((long) key)) + return (key is long l && dictionary.ContainsKey(l)) || dictionary.ContainsValue(key.ToString()); } diff --git a/main/HPSF/DocumentSummaryInformation.cs b/main/HPSF/DocumentSummaryInformation.cs index 96bd2f9b6..f59ef78b1 100644 --- a/main/HPSF/DocumentSummaryInformation.cs +++ b/main/HPSF/DocumentSummaryInformation.cs @@ -493,9 +493,9 @@ public byte[] VBADigitalSignature get { Object value = GetProperty(PropertyIDMap.PID_DIGSIG); - if(value != null && value is byte[]) + if(value != null && value is byte[] bytes) { - return (byte[]) value; + return bytes; } return null; } diff --git a/main/HPSF/Property.cs b/main/HPSF/Property.cs index 97a498883..368194e08 100644 --- a/main/HPSF/Property.cs +++ b/main/HPSF/Property.cs @@ -359,14 +359,14 @@ protected internal int GetSize() /// @see Object#equals(java.lang.Object) public override bool Equals(Object o) { - if(!(o is Property)) + if(o is not Property property) { return false; } - Property p = (Property)o; - Object pValue = p.Value; - long pId = p.ID; - if(id != pId || (id != 0 && !typesAreEqual(type, p.Type))) + + Object pValue = property.Value; + long pId = property.ID; + if(id != pId || (id != 0 && !typesAreEqual(type, property.Type))) { return false; } @@ -388,9 +388,9 @@ public override bool Equals(Object o) return false; } - if(_value is byte[]) + if(_value is byte[] bytes) { - return Arrays.Equals((byte[]) _value, (byte[]) pValue); + return Arrays.Equals(bytes, (byte[]) pValue); } return _value.Equals(pValue); @@ -439,10 +439,9 @@ public override String ToString() b.Append(Type); Object value = Value; b.Append(", value: "); - if(value is String) + if(value is String s) { - b.Append(value.ToString()); - String s = (String)value; + b.Append(s.ToString()); int l = s.Length; byte[] bytes = new byte[l * 2]; for(int i = 0; i < l; i++) @@ -461,9 +460,8 @@ public override String ToString() } b.Append("]"); } - else if(value is byte[]) + else if(value is byte[] bytes) { - byte[] bytes = (byte[])value; if(bytes.Length > 0) { String hex = HexDump.Dump(bytes, 0L, 0); diff --git a/main/HPSF/PropertySet.cs b/main/HPSF/PropertySet.cs index eb8d5caf1..76b2b7a90 100644 --- a/main/HPSF/PropertySet.cs +++ b/main/HPSF/PropertySet.cs @@ -653,28 +653,27 @@ public static String GetPropertyStringValue(Object propertyValue) { return null; } - if(propertyValue is String) + if(propertyValue is String value) { - return (String) propertyValue; + return value; } // Do our best with some edge cases - if(propertyValue is byte[]) + if(propertyValue is byte[] data) { - byte[] b = (byte[])propertyValue; - switch(b.Length) + switch(data.Length) { case 0: return ""; case 1: - return b[0].ToString(); + return data[0].ToString(); case 2: - return LittleEndian.GetUShort(b).ToString(); + return LittleEndian.GetUShort(data).ToString(); case 4: - return LittleEndian.GetUInt(b).ToString(); + return LittleEndian.GetUInt(data).ToString(); default: // Maybe it's a string? who knows! - return Encoding.ASCII.GetString(b); + return Encoding.ASCII.GetString(data); } } return propertyValue.ToString(); @@ -842,11 +841,11 @@ public Section SingleSection /// public override bool Equals(object o) { - if(o == null || !(o is PropertySet)) + if(o == null || o is not PropertySet ps) { return false; } - PropertySet ps = (PropertySet)o; + int byteOrder1 = ps.ByteOrder; int byteOrder2 = ByteOrder; ClassID classID1 = ps.ClassID; diff --git a/main/HPSF/Section.cs b/main/HPSF/Section.cs index 16cbae0cd..a5131d16c 100644 --- a/main/HPSF/Section.cs +++ b/main/HPSF/Section.cs @@ -454,25 +454,25 @@ public void SetProperty(Property p) /// public void SetProperty(int id, Object value) { - if(value is String) + if(value is String s) { - SetProperty(id, (String) value); + SetProperty(id, s); } - else if(value is long) + else if(value is long l) { - SetProperty(id, ((long) value)); + SetProperty(id, l); } - else if(value is int) + else if(value is int i) { - SetProperty(id, ((int) value)); + SetProperty(id, i); } - else if(value is short) + else if(value is short s1) { - SetProperty(id, ((short) value)); + SetProperty(id, s1); } - else if(value is Boolean) + else if(value is Boolean b) { - SetProperty(id, ((Boolean) value)); + SetProperty(id, b); } else if(value is Date) { @@ -702,12 +702,12 @@ public void SetCodepage(int codepage) /// public override bool Equals(Object o) { - if(o == null || !(o is Section)) + if(o == null || o is not Section section) { return false; } - Section s = (Section)o; - if(!s.FormatID.Equals(FormatID)) + + if(!section.FormatID.Equals(FormatID)) { return false; } @@ -715,9 +715,9 @@ public override bool Equals(Object o) /* Compare all properties except 0 and 1 as they must be handled * specially. */ Property[] pa1 = new Property[Properties.Length]; - Property[] pa2 = new Property[s.Properties.Length]; + Property[] pa2 = new Property[section.Properties.Length]; System.Array.Copy(Properties, 0, pa1, 0, pa1.Length); - System.Array.Copy(s.Properties, 0, pa2, 0, pa2.Length); + System.Array.Copy(section.Properties, 0, pa2, 0, pa2.Length); /* Extract properties 0 and 1 and remove them from the copy of the * arrays. */ @@ -876,7 +876,7 @@ public int Write(Stream out1) Object p1 = GetProperty(PropertyIDMap.PID_CODEPAGE); if(p1 != null) { - if(!(p1 is int)) + if(p1 is not int) { throw new IllegalPropertySetDataException ("The codepage property (ID = 1) must be an " + diff --git a/main/HPSF/VariantSupport.cs b/main/HPSF/VariantSupport.cs index 576b98432..c66969b2f 100644 --- a/main/HPSF/VariantSupport.cs +++ b/main/HPSF/VariantSupport.cs @@ -339,7 +339,7 @@ public static int Write(Stream out1, long type, break; case Variant.VT_I4: - if(!(value is int)) + if(value is not int) { throw new InvalidCastException("Could not cast an object to " + typeof(Int32).ToString() + ": " @@ -368,12 +368,11 @@ public static int Write(Stream out1, long type, default: /* The variant type is not supported yet. However, if the value * is a byte array we can write it nevertheless. */ - if(value is byte[]) + if(value is byte[] bytes) { - byte[] b = (byte[])value; - out1.Write(b, 0, b.Length); - length = b.Length; - WriteUnsupportedTypeMessage(new WritingNotSupportedException(type, value)); + out1.Write(bytes, 0, bytes.Length); + length = bytes.Length; + WriteUnsupportedTypeMessage(new WritingNotSupportedException(type, bytes)); } else { diff --git a/main/HSSF/EventUserModel/EventWorkbookBuilder.cs b/main/HSSF/EventUserModel/EventWorkbookBuilder.cs index f6269c0d7..44f64524c 100644 --- a/main/HSSF/EventUserModel/EventWorkbookBuilder.cs +++ b/main/HSSF/EventUserModel/EventWorkbookBuilder.cs @@ -214,9 +214,9 @@ public void ProcessRecordInternally(Record record) { externSheetRecords.Add(record); } - else if (record is SSTRecord) + else if (record is SSTRecord record1) { - sstRecord = (SSTRecord)record; + sstRecord = record1; } } } diff --git a/main/HSSF/EventUserModel/FormatTrackingHSSFListener.cs b/main/HSSF/EventUserModel/FormatTrackingHSSFListener.cs index 8df9ff86b..d0a93fe57 100644 --- a/main/HSSF/EventUserModel/FormatTrackingHSSFListener.cs +++ b/main/HSSF/EventUserModel/FormatTrackingHSSFListener.cs @@ -77,14 +77,12 @@ public void ProcessRecord(Record record) */ public void ProcessRecordInternally(Record record) { - if (record is FormatRecord) + if (record is FormatRecord fr) { - FormatRecord fr = (FormatRecord)record; customFormatRecords[fr.IndexCode] = fr; } - else if (record is ExtendedFormatRecord) + else if (record is ExtendedFormatRecord xr) { - ExtendedFormatRecord xr = (ExtendedFormatRecord)record; xfRecords.Add(xr); } } @@ -100,13 +98,13 @@ public void ProcessRecordInternally(Record record) public String FormatNumberDateCell(CellValueRecordInterface cell) { double value; - if (cell is NumberRecord) + if (cell is NumberRecord record) { - value = ((NumberRecord)cell).Value; + value = record.Value; } - else if (cell is FormulaRecord) + else if (cell is FormulaRecord formulaRecord) { - value = ((FormulaRecord)cell).Value; + value = formulaRecord.Value; } else { diff --git a/main/HSSF/EventUserModel/HSSFRecordStream.cs b/main/HSSF/EventUserModel/HSSFRecordStream.cs index a5cc649be..c32cb9108 100644 --- a/main/HSSF/EventUserModel/HSSFRecordStream.cs +++ b/main/HSSF/EventUserModel/HSSFRecordStream.cs @@ -203,11 +203,11 @@ private Record GetNextRecord() // Trigger them on the drawing record, now it's complete rec = lastDrawingRecord; } - else if ((lastRec is DrawingGroupRecord)) + else if ((lastRec is DrawingGroupRecord record)) { - ((DrawingGroupRecord)lastRec).ProcessContinueRecord(crec.Data); + record.ProcessContinueRecord(crec.Data); // Trigger them on the drawing record, now it's complete - rec = lastRec; + rec = record; } else { @@ -224,9 +224,9 @@ private Record GetNextRecord() // Update our tracking of the last record lastRec = rec; - if (rec is DrawingRecord) + if (rec is DrawingRecord drawingRecord) { - lastDrawingRecord = (DrawingRecord)rec; + lastDrawingRecord = drawingRecord; } } else diff --git a/main/HSSF/EventUserModel/HSSFRequest.cs b/main/HSSF/EventUserModel/HSSFRequest.cs index 587579550..78883847d 100644 --- a/main/HSSF/EventUserModel/HSSFRequest.cs +++ b/main/HSSF/EventUserModel/HSSFRequest.cs @@ -108,10 +108,9 @@ public short ProcessRecord(Record rec) for (int k = 0; k < listeners.Count; k++) { Object listenObj = listeners[k]; - if (listenObj is AbortableHSSFListener) + if (listenObj is AbortableHSSFListener hssfListener) { - AbortableHSSFListener listener = (AbortableHSSFListener)listenObj; - userCode = listener.AbortableProcessRecord(rec); + userCode = hssfListener.AbortableProcessRecord(rec); if (userCode != 0) break; } else diff --git a/main/HSSF/EventUserModel/MissingRecordAwareHSSFListener.cs b/main/HSSF/EventUserModel/MissingRecordAwareHSSFListener.cs index ad0a42968..4023d37d4 100644 --- a/main/HSSF/EventUserModel/MissingRecordAwareHSSFListener.cs +++ b/main/HSSF/EventUserModel/MissingRecordAwareHSSFListener.cs @@ -63,9 +63,8 @@ public void ProcessRecord(Record record) int thisColumn; CellValueRecordInterface[] expandedRecords = null; - if (record is CellValueRecordInterface) + if (record is CellValueRecordInterface valueRec) { - CellValueRecordInterface valueRec = (CellValueRecordInterface)record; thisRow = valueRec.Row; thisColumn = valueRec.Column; } diff --git a/main/HSSF/Extractor/OldExcelExtractor.cs b/main/HSSF/Extractor/OldExcelExtractor.cs index e42e83b58..fc7f2bcde 100644 --- a/main/HSSF/Extractor/OldExcelExtractor.cs +++ b/main/HSSF/Extractor/OldExcelExtractor.cs @@ -111,8 +111,8 @@ public OldExcelExtractor(DirectoryNode directory) private void Open(Stream biffStream) { - BufferedStream bis = (biffStream is BufferedStream) - ? (BufferedStream)biffStream + BufferedStream bis = (biffStream is BufferedStream stream) + ? stream : new BufferedStream(biffStream, 8); if (NPOIFSFileSystem.HasPOIFSHeader(bis)) diff --git a/main/HSSF/Model/ConvertAnchor.cs b/main/HSSF/Model/ConvertAnchor.cs index 753ff128c..a5e3416f6 100644 --- a/main/HSSF/Model/ConvertAnchor.cs +++ b/main/HSSF/Model/ConvertAnchor.cs @@ -30,23 +30,21 @@ public class ConvertAnchor /// public static EscherRecord CreateAnchor(HSSFAnchor userAnchor) { - if (userAnchor is HSSFClientAnchor) + if (userAnchor is HSSFClientAnchor clientAnchor) { - HSSFClientAnchor a = (HSSFClientAnchor)userAnchor; - EscherClientAnchorRecord anchor = new EscherClientAnchorRecord(); anchor.RecordId=EscherClientAnchorRecord.RECORD_ID; anchor.Options=(short)0x0000; - anchor.Flag=(short)a.AnchorType; - anchor.Col1=(short)Math.Min(a.Col1, a.Col2); - anchor.Dx1=(short)a.Dx1; - anchor.Row1=(short)Math.Min(a.Row1, a.Row2); - anchor.Dy1=(short)a.Dy1; + anchor.Flag=(short)clientAnchor.AnchorType; + anchor.Col1=(short)Math.Min(clientAnchor.Col1, clientAnchor.Col2); + anchor.Dx1=(short)clientAnchor.Dx1; + anchor.Row1=(short)Math.Min(clientAnchor.Row1, clientAnchor.Row2); + anchor.Dy1=(short)clientAnchor.Dy1; - anchor.Col2=(short)Math.Max(a.Col1, a.Col2); - anchor.Dx2=(short)a.Dx2; - anchor.Row2=(short)Math.Max(a.Row1, a.Row2); - anchor.Dy2=(short)a.Dy2; + anchor.Col2=(short)Math.Max(clientAnchor.Col1, clientAnchor.Col2); + anchor.Dx2=(short)clientAnchor.Dx2; + anchor.Row2=(short)Math.Max(clientAnchor.Row1, clientAnchor.Row2); + anchor.Dy2=(short)clientAnchor.Dy2; return anchor; } else diff --git a/main/HSSF/Model/InternalSheet.cs b/main/HSSF/Model/InternalSheet.cs index 73aff9c8a..e4c67e85c 100644 --- a/main/HSSF/Model/InternalSheet.cs +++ b/main/HSSF/Model/InternalSheet.cs @@ -136,9 +136,9 @@ public InternalSheet CloneSheet() for (int i = 0; i < this.records.Count; i++) { RecordBase rb = (RecordBase)this.records[i]; - if (rb is RecordAggregate) + if (rb is RecordAggregate aggregate) { - ((RecordAggregate)rb).VisitContainedRecords(new RecordCloner(clonedRecords)); + aggregate.VisitContainedRecords(new RecordCloner(clonedRecords)); continue; } @@ -1648,11 +1648,11 @@ public int FindFirstRecordLocBySid(short sid) for (int i = 0; i < max; i++) { Object rb = records[i]; - if (!(rb is Record)) + if (rb is not Record record) { continue; } - Record record = (Record)rb; + if (record.Sid == sid) { return i; @@ -2182,17 +2182,16 @@ public void VisitContainedRecords(RecordVisitor rv, int offset) for (int k = 0; k < records.Count; k++) { RecordBase record = records[k]; - if (record is RecordAggregate) + if (record is RecordAggregate agg) { - RecordAggregate agg = (RecordAggregate)record; agg.VisitContainedRecords(ptv); sheetOffset += agg.RecordSize; } else { - if (record is DefaultColWidthRecord) + if (record is DefaultColWidthRecord widthRecord) { - ((DefaultColWidthRecord)record).offsetForFilePointer = sheetOffset; + widthRecord.offsetForFilePointer = sheetOffset; } ptv.VisitRecord((Record)record); sheetOffset += record.RecordSize; @@ -2316,9 +2315,9 @@ public NoteRecord[] GetNoteRecords() for (int i = records.Count - 1; i >= 0; i--) { RecordBase rec = records[i]; - if (rec is NoteRecord) + if (rec is NoteRecord record) { - temp.Add((NoteRecord)rec); + temp.Add(record); } } if (temp.Count < 1) diff --git a/main/HSSF/Model/InternalWorkbook.cs b/main/HSSF/Model/InternalWorkbook.cs index 8fc5b9991..049e0b9ea 100644 --- a/main/HSSF/Model/InternalWorkbook.cs +++ b/main/HSSF/Model/InternalWorkbook.cs @@ -553,17 +553,16 @@ public void CloneDrawings(InternalSheet sheet) for (IEnumerator it = escherContainer.ChildRecords.GetEnumerator(); it.MoveNext(); ) { Object er = it.Current; - if (er is EscherDgRecord) + if (er is EscherDgRecord record) { - dg = (EscherDgRecord)er; + dg = record; //update id of the drawing in the cloned sheet dg.Options = ((short)(dgId << 4)); } - else if (er is EscherContainerRecord) + else if (er is EscherContainerRecord cp) { //recursively find shape records and re-generate shapeId ArrayList spRecords = new ArrayList(); - EscherContainerRecord cp = (EscherContainerRecord)er; for (IEnumerator spIt = cp.ChildRecords.GetEnumerator(); spIt.MoveNext(); ) { EscherContainerRecord shapeContainer = (EscherContainerRecord)spIt.Current; @@ -1019,9 +1018,8 @@ public StyleRecord GetStyleRecord(int xfIndex) if (r is ExtendedFormatRecord) { } - else if (r is StyleRecord) + else if (r is StyleRecord sr) { - StyleRecord sr = (StyleRecord)r; if (sr.XFIndex == xfIndex) { return sr; @@ -1177,9 +1175,9 @@ public int Serialize(int offset, byte[] data) if (record.Sid != RecalcIdRecord.sid || ((RecalcIdRecord)record).IsNeeded) { int len = 0; - if (record is SSTRecord) + if (record is SSTRecord sstRecord) { - sst = (SSTRecord)record; + sst = sstRecord; sstPos = pos; } if (record.Sid == ExtSSTRecord.sid && sst != null) @@ -1244,8 +1242,8 @@ public int Size // Let's skip RECALCID records, as they are only use for optimization if (record.Sid != RecalcIdRecord.sid || ((RecalcIdRecord)record).IsNeeded) { - if (record is SSTRecord) - sst = (SSTRecord)record; + if (record is SSTRecord sstRecord) + sst = sstRecord; if (record.Sid == ExtSSTRecord.sid && sst != null) retval += sst.CalcExtSSTRecordSize(); else @@ -2653,9 +2651,9 @@ public PaletteRecord CustomPalette if (palettePos != -1) { Record rec = records[palettePos]; - if (rec is PaletteRecord) + if (rec is PaletteRecord record) { - palette = (PaletteRecord)rec; + palette = record; } else throw new Exception("InternalError: Expected PaletteRecord but got a '" + rec + "'"); } @@ -2687,9 +2685,8 @@ public DrawingManager2 FindDrawingGroup() { Record r = (Record)rit.Current; - if (r is DrawingGroupRecord) + if (r is DrawingGroupRecord dg) { - DrawingGroupRecord dg = (DrawingGroupRecord)r; dg.ProcessChildRecords(); EscherContainerRecord cr = @@ -2704,9 +2701,9 @@ public DrawingManager2 FindDrawingGroup() for (IEnumerator it = cr.ChildRecords.GetEnumerator(); it.MoveNext(); ) { EscherRecord er = (EscherRecord)it.Current; - if (er is EscherDggRecord) + if (er is EscherDggRecord record) { - dgg = (EscherDggRecord)er; + dgg = record; } else if (er.RecordId == EscherContainerRecord.BSTORE_CONTAINER) { @@ -2721,8 +2718,8 @@ public DrawingManager2 FindDrawingGroup() { foreach (EscherRecord bs in bStore.ChildRecords) { - if (bs is EscherBSERecord) - escherBSERecords.Add((EscherBSERecord)bs); + if (bs is EscherBSERecord record) + escherBSERecords.Add(record); } } return drawingManager; @@ -2744,9 +2741,9 @@ public DrawingManager2 FindDrawingGroup() for (IEnumerator it = dg.EscherRecords.GetEnumerator(); it.MoveNext(); ) { EscherRecord er = (EscherRecord)it.Current; - if (er is EscherDggRecord) + if (er is EscherDggRecord record) { - dgg = (EscherDggRecord)er; + dgg = record; } else if (er.RecordId == EscherContainerRecord.BSTORE_CONTAINER) { @@ -2761,8 +2758,8 @@ public DrawingManager2 FindDrawingGroup() { foreach (EscherRecord bs in bStore.ChildRecords) { - if (bs is EscherBSERecord) - escherBSERecords.Add((EscherBSERecord)bs); + if (bs is EscherBSERecord record) + escherBSERecords.Add(record); } } } @@ -2939,7 +2936,7 @@ public WriteProtectRecord WriteProtect this.writeProtect = new WriteProtectRecord(); int i = 0; for (i = 0; - i < records.Count && !(records[i] is BOFRecord); + i < records.Count && records[i] is not BOFRecord; i++) { } @@ -2958,7 +2955,7 @@ public WriteAccessRecord WriteAccess this.writeAccess = (WriteAccessRecord)CreateWriteAccess(); int i = 0; for (i = 0; - i < records.Count && !(records[i] is InterfaceEndRecord); + i < records.Count && records[i] is not InterfaceEndRecord; i++) { } @@ -2977,7 +2974,7 @@ public FileSharingRecord FileSharing this.fileShare = new FileSharingRecord(); int i = 0; for (i = 0; - i < records.Count && !(records[i] is WriteAccessRecord); + i < records.Count && records[i] is not WriteAccessRecord; i++) { } @@ -3049,15 +3046,15 @@ public NameRecord CloneFilter(int filterDbNameIndex, int newSheetIndex) for (int i = 0; i < ptgs.Length; i++) { Ptg ptg = ptgs[i]; - if (ptg is Area3DPtg) + if (ptg is Area3DPtg area3DPtg) { - Area3DPtg a3p = (Area3DPtg)((OperandPtg)ptg).Copy(); + Area3DPtg a3p = (Area3DPtg)area3DPtg.Copy(); a3p.ExternSheetIndex = (newExtSheetIx); ptgs[i] = a3p; } - else if (ptg is Ref3DPtg) + else if (ptg is Ref3DPtg ref3DPtg) { - Ref3DPtg r3p = (Ref3DPtg)((OperandPtg)ptg).Copy(); + Ref3DPtg r3p = (Ref3DPtg)ref3DPtg.Copy(); r3p.ExternSheetIndex = (newExtSheetIx); ptgs[i] = r3p; } diff --git a/main/HSSF/Model/LinkTable.cs b/main/HSSF/Model/LinkTable.cs index 307445a03..ebf5324f7 100644 --- a/main/HSSF/Model/LinkTable.cs +++ b/main/HSSF/Model/LinkTable.cs @@ -498,9 +498,9 @@ public NameXPtg AddNameXPtg(String name) for (IEnumerator iterator = _workbookRecordList.GetEnumerator(); iterator.MoveNext(); supLinkIndex++) { Record record = (Record)iterator.Current; - if (record is SupBookRecord) + if (record is SupBookRecord bookRecord) { - if (((SupBookRecord)record).IsAddInFunctions) break; + if (bookRecord.IsAddInFunctions) break; } } int numberOfNames = extBlock.NumberOfNames; diff --git a/main/HSSF/Model/ParseNode.cs b/main/HSSF/Model/ParseNode.cs index 13c280533..8e9c68559 100644 --- a/main/HSSF/Model/ParseNode.cs +++ b/main/HSSF/Model/ParseNode.cs @@ -151,9 +151,8 @@ private void CollectIfPtgs(TokenCollector temp) private static bool IsIf(Ptg token) { - if (token is FuncVarPtg) + if (token is FuncVarPtg func) { - FuncVarPtg func = (FuncVarPtg)token; if (FunctionMetadataRegistry.FUNCTION_NAME_IF.Equals(func.Name)) { return true; diff --git a/main/HSSF/Model/RecordOrderer.cs b/main/HSSF/Model/RecordOrderer.cs index fbf825966..69d311612 100644 --- a/main/HSSF/Model/RecordOrderer.cs +++ b/main/HSSF/Model/RecordOrderer.cs @@ -129,9 +129,8 @@ private static bool IsProtectionSubsequentRecord(Object rb) { return true; // oo COLINFO } - if (rb is Record) + if (rb is Record record) { - Record record = (Record)rb; switch (record.Sid) { case DefaultColWidthRecord.sid: @@ -158,9 +157,8 @@ private static int GetPageBreakRecordInsertPos(List records) } private static bool IsPageBreakPriorRecord(RecordBase rb) { - if (rb is Record) + if (rb is Record record) { - Record record = (Record)rb; switch (record.Sid) { case BOFRecord.sid: @@ -231,13 +229,13 @@ private static int FindInsertPosForNewMergedRecordTable(List records for (int i = records.Count - 2; i >= 0; i--) { // -2 to skip EOF record Object rb = records[i]; - if (!(rb is Record)) + if (rb is not Record rec) { // DataValidityTable, ConditionalFormattingTable, // even PageSettingsBlock (which doesn't normally appear after 'View Settings') continue; } - Record rec = (Record)rb; + switch (rec.Sid) { // 'View Settings' (4 records) @@ -277,7 +275,7 @@ private static int FindInsertPosForNewMergedRecordTable(List records private static int FindDataValidationTableInsertPos(List records) { int i = records.Count - 1; - if (!(records[i] is EOFRecord)) + if (records[i] is not EOFRecord) { throw new InvalidOperationException("Last sheet record should be EOFRecord"); } @@ -381,9 +379,8 @@ private static int GetGutsRecordInsertPos(List records) private static bool IsGutsPriorRecord(RecordBase rb) { - if (rb is Record) + if (rb is Record record) { - Record record = (Record)rb; switch (record.Sid) { case BOFRecord.sid: diff --git a/main/HSSF/Model/RowBlocksReader.cs b/main/HSSF/Model/RowBlocksReader.cs index 94182a984..7b7fac1c7 100644 --- a/main/HSSF/Model/RowBlocksReader.cs +++ b/main/HSSF/Model/RowBlocksReader.cs @@ -72,11 +72,11 @@ public RowBlocksReader(RecordStream rs) break; case SharedFormulaRecord.sid: dest = shFrmRecords; - if (!(prevRec is FormulaRecord)) + if (prevRec is not FormulaRecord fr) { throw new Exception("Shared formula record should follow a FormulaRecord"); } - FormulaRecord fr = (FormulaRecord)prevRec; + firstCellRefs.Add(new CellReference(fr.Row, fr.Column)); break; diff --git a/main/HSSF/Record/AbstractEscherHolderRecord.cs b/main/HSSF/Record/AbstractEscherHolderRecord.cs index 64029d975..b0fd8cd05 100644 --- a/main/HSSF/Record/AbstractEscherHolderRecord.cs +++ b/main/HSSF/Record/AbstractEscherHolderRecord.cs @@ -236,9 +236,9 @@ public EscherContainerRecord GetEscherContainer() for (IEnumerator it = escherRecords.GetEnumerator(); it.MoveNext(); ) { Object er = it.Current; - if (er is EscherContainerRecord) + if (er is EscherContainerRecord record) { - return (EscherContainerRecord)er; + return record; } } return null; diff --git a/main/HSSF/Record/Aggregates/CFRecordsAggregate.cs b/main/HSSF/Record/Aggregates/CFRecordsAggregate.cs index 5a920d968..0264bcdf5 100644 --- a/main/HSSF/Record/Aggregates/CFRecordsAggregate.cs +++ b/main/HSSF/Record/Aggregates/CFRecordsAggregate.cs @@ -156,9 +156,9 @@ public static CFRecordsAggregate CreateCFAggregate(IList recs, int pOffset) break; } rec = (Record)recs[offset]; - if (rec is CFRuleRecord) + if (rec is CFRuleRecord record) { - rules[countFound] = (CFRuleRecord)rec; + rules[countFound] = record; countFound++; } else @@ -318,9 +318,8 @@ public bool UpdateFormulasAfterCellShift(FormulaShifter shifter, int currentExte { rule.ParsedExpression2 = (ptgs); } - if (rule is CFRule12Record) + if (rule is CFRule12Record rule12) { - CFRule12Record rule12 = (CFRule12Record)rule; ptgs = rule12.ParsedExpressionScale; if (ptgs != null && shifter.AdjustFormula(ptgs, currentExternSheetIx)) { @@ -341,9 +340,8 @@ private static CellRangeAddress ShiftRange(FormulaShifter shifter, CellRangeAddr return cra; } Ptg ptg0 = ptgs[0]; - if (ptg0 is AreaPtg) + if (ptg0 is AreaPtg bptg) { - AreaPtg bptg = (AreaPtg)ptg0; return new CellRangeAddress(bptg.FirstRow, bptg.LastRow, bptg.FirstColumn, bptg.LastColumn); } if (ptg0 is AreaErrPtg) diff --git a/main/HSSF/Record/Aggregates/Chart/ChartSheetAggregate.cs b/main/HSSF/Record/Aggregates/Chart/ChartSheetAggregate.cs index 32a9fd02f..aad45bcd5 100644 --- a/main/HSSF/Record/Aggregates/Chart/ChartSheetAggregate.cs +++ b/main/HSSF/Record/Aggregates/Chart/ChartSheetAggregate.cs @@ -82,7 +82,7 @@ public ChartSheetAggregate(RecordStream rs, ChartRecordAggregate container) } _recs = temp; Record eof = rs.GetNext(); // no need to save EOF in field - if (!(eof is EOFRecord)) + if (eof is not EOFRecord) { throw new InvalidOperationException("Bad chart EOF"); } @@ -99,9 +99,9 @@ public override void VisitContainedRecords(RecordVisitor rv) for (int i = 0; i < _recs.Count; i++) { RecordBase rb = _recs[i]; - if (rb is RecordAggregate) + if (rb is RecordAggregate aggregate) { - ((RecordAggregate)rb).VisitContainedRecords(rv); + aggregate.VisitContainedRecords(rv); } else { diff --git a/main/HSSF/Record/Aggregates/ChartSubstreamRecordAggregate.cs b/main/HSSF/Record/Aggregates/ChartSubstreamRecordAggregate.cs index b0c8234f1..15ba966c5 100644 --- a/main/HSSF/Record/Aggregates/ChartSubstreamRecordAggregate.cs +++ b/main/HSSF/Record/Aggregates/ChartSubstreamRecordAggregate.cs @@ -68,7 +68,7 @@ public ChartSubstreamRecordAggregate(RecordStream rs) } _recs = temp; Record eof = rs.GetNext(); // no need to save EOF in field - if (!(eof is EOFRecord)) + if (eof is not EOFRecord) { throw new InvalidOperationException("Bad chart EOF"); } @@ -84,9 +84,9 @@ public override void VisitContainedRecords(RecordVisitor rv) for (int i = 0; i < _recs.Count; i++) { RecordBase rb = _recs[i]; - if (rb is RecordAggregate) + if (rb is RecordAggregate aggregate) { - ((RecordAggregate)rb).VisitContainedRecords(rv); + aggregate.VisitContainedRecords(rv); } else { diff --git a/main/HSSF/Record/Aggregates/CustomViewSettingsRecordAggregate.cs b/main/HSSF/Record/Aggregates/CustomViewSettingsRecordAggregate.cs index 69309894b..e33d24470 100644 --- a/main/HSSF/Record/Aggregates/CustomViewSettingsRecordAggregate.cs +++ b/main/HSSF/Record/Aggregates/CustomViewSettingsRecordAggregate.cs @@ -86,9 +86,9 @@ public override void VisitContainedRecords(RecordVisitor rv) for (int i = 0; i < _recs.Count; i++) { RecordBase rb = _recs[i]; - if (rb is RecordAggregate) + if (rb is RecordAggregate aggregate) { - ((RecordAggregate)rb).VisitContainedRecords(rv); + aggregate.VisitContainedRecords(rv); } else { diff --git a/main/HSSF/Record/Aggregates/PageSettingsBlock.cs b/main/HSSF/Record/Aggregates/PageSettingsBlock.cs index 3a867778d..d1b5bcc54 100644 --- a/main/HSSF/Record/Aggregates/PageSettingsBlock.cs +++ b/main/HSSF/Record/Aggregates/PageSettingsBlock.cs @@ -661,9 +661,8 @@ public void PositionRecords(List sheetRecords) { foreach (RecordBase rb in sheetRecords) { - if (rb is CustomViewSettingsRecordAggregate) + if (rb is CustomViewSettingsRecordAggregate cv) { - CustomViewSettingsRecordAggregate cv = (CustomViewSettingsRecordAggregate)rb; cv.VisitContainedRecords(new CustomRecordVisitor1(cv,hf,_sviewHeaderFooters,hfGuidMap)); } } diff --git a/main/HSSF/Record/Aggregates/RowRecordsAggregate.cs b/main/HSSF/Record/Aggregates/RowRecordsAggregate.cs index 1b44e725e..1377855b2 100644 --- a/main/HSSF/Record/Aggregates/RowRecordsAggregate.cs +++ b/main/HSSF/Record/Aggregates/RowRecordsAggregate.cs @@ -166,10 +166,10 @@ public RowRecordsAggregate(RecordStream rs, SharedValueManager svm) // ignore DBCELL records because POI generates them upon re-serialization continue; } - if (rec is UnknownRecord) + if (rec is UnknownRecord record) { // might need to keep track of where exactly these belong - AddUnknownRecord((UnknownRecord)rec); + AddUnknownRecord(record); while (rs.PeekNextSid() == ContinueRecord.sid) { @@ -177,12 +177,12 @@ public RowRecordsAggregate(RecordStream rs, SharedValueManager svm) } continue; } - if (rec is MulBlankRecord) { - _valuesAgg.AddMultipleBlanks((MulBlankRecord) rec); + if (rec is MulBlankRecord blankRecord) { + _valuesAgg.AddMultipleBlanks(blankRecord); continue; } - if (!(rec is CellValueRecordInterface)) + if (rec is not CellValueRecordInterface @interface) { //TODO: correct it, SeriesIndexRecord will appear in a separate chart sheet that contains a single chart // rule SERIESDATA = Dimensions 3(SIIndex *(Number / BoolErr / Blank / Label)) @@ -194,7 +194,7 @@ public RowRecordsAggregate(RecordStream rs, SharedValueManager svm) throw new InvalidOperationException("Unexpected record type (" + rec.GetType().Name + ")"); } - _valuesAgg.Construct((CellValueRecordInterface)rec, rs, svm); + _valuesAgg.Construct(@interface, rs, svm); } } /** @@ -253,9 +253,9 @@ public void InsertCell(CellValueRecordInterface cvRec) } public void RemoveCell(CellValueRecordInterface cvRec) { - if (cvRec is FormulaRecordAggregate) + if (cvRec is FormulaRecordAggregate aggregate) { - ((FormulaRecordAggregate)cvRec).NotifyFormulaChanging(); + aggregate.NotifyFormulaChanging(); } _valuesAgg.RemoveCell(cvRec); } diff --git a/main/HSSF/Record/Aggregates/ValueRecordsAggregate.cs b/main/HSSF/Record/Aggregates/ValueRecordsAggregate.cs index 6930b12fe..2192ab823 100644 --- a/main/HSSF/Record/Aggregates/ValueRecordsAggregate.cs +++ b/main/HSSF/Record/Aggregates/ValueRecordsAggregate.cs @@ -213,9 +213,8 @@ private MulBlankRecord CreateMBR(CellValueRecordInterface[] cellValues, int star public void Construct(CellValueRecordInterface rec, RecordStream rs, SharedValueManager sfh) { - if (rec is FormulaRecord) + if (rec is FormulaRecord formulaRec) { - FormulaRecord formulaRec = (FormulaRecord) rec; // read optional cached text value StringRecord cachedText = null; Type nextClass = rs.PeekNextClass(); @@ -304,11 +303,10 @@ public void UpdateFormulasAfterRowShift(FormulaShifter shifter, int currentExter for (int j = 0; j < rowCells.Length; j++) { CellValueRecordInterface cell = rowCells[j]; - if (cell is FormulaRecordAggregate) + if (cell is FormulaRecordAggregate fra) { - FormulaRecordAggregate fra = (FormulaRecordAggregate) cell; Ptg[] ptgs = fra.FormulaTokens; // needs clone() inside this getter? - Ptg[] ptgs2 = ((FormulaRecordAggregate) cell).FormulaRecord + Ptg[] ptgs2 = fra.FormulaRecord .ParsedExpression; // needs clone() inside this getter? if (shifter.AdjustFormula(ptgs, currentExternSheetIndex)) @@ -343,9 +341,8 @@ public void VisitCellsForRow(int rowIndex, RecordVisitor rv) rv.VisitRecord(CreateMBR(rowCells, i, nBlank)); i += nBlank - 1; } - else if (cvr is RecordAggregate) + else if (cvr is RecordAggregate agg) { - RecordAggregate agg = (RecordAggregate) cvr; agg.VisitContainedRecords(rv); } else @@ -361,7 +358,7 @@ static int CountBlanks(CellValueRecordInterface[] rowCellValues, int startIx) while (i < rowCellValues.Length) { CellValueRecordInterface cvr = rowCellValues[i]; - if (!(cvr is BlankRecord)) + if (cvr is not BlankRecord) { break; } diff --git a/main/HSSF/Record/CellRecord.cs b/main/HSSF/Record/CellRecord.cs index af5a23500..f2cb141d3 100644 --- a/main/HSSF/Record/CellRecord.cs +++ b/main/HSSF/Record/CellRecord.cs @@ -173,14 +173,13 @@ protected void CopyBaseFields(CellRecord rec) public override bool Equals(object obj) { - if (!(obj is CellValueRecordInterface)) + if (obj is not CellValueRecordInterface loc) { return false; } - CellValueRecordInterface loc = (CellValueRecordInterface)obj; if ((this.Row == loc.Row) - && (this.Column == loc.Column)) + && (this.Column == loc.Column)) { return true; } diff --git a/main/HSSF/Record/Common/UnicodeString.cs b/main/HSSF/Record/Common/UnicodeString.cs index adb07473c..aee78fb80 100644 --- a/main/HSSF/Record/Common/UnicodeString.cs +++ b/main/HSSF/Record/Common/UnicodeString.cs @@ -79,11 +79,10 @@ public short FontIndex public override bool Equals(Object o) { - if (!(o is FormatRun)) + if (o is not FormatRun other) { return false; } - FormatRun other = (FormatRun)o; return _character == other._character && _fontIndex == other._fontIndex; } @@ -275,11 +274,11 @@ internal void Serialize(ContinuableRecordOutput out1) public override bool Equals(Object obj) { - if (!(obj is ExtRst)) + if (obj is not ExtRst other) { return false; } - ExtRst other = (ExtRst)obj; + return (CompareTo(other) == 0); } public override string ToString() @@ -435,11 +434,10 @@ public override int GetHashCode() */ public override bool Equals(Object o) { - if (!(o is UnicodeString)) + if (o is not UnicodeString other) { return false; } - UnicodeString other = (UnicodeString)o; //OK lets do this in stages to return a quickly, first check the actual string if (field_1_charCount != other.field_1_charCount diff --git a/main/HSSF/Record/Cont/UnknownLengthRecordOutput.cs b/main/HSSF/Record/Cont/UnknownLengthRecordOutput.cs index a3efbd90f..7d50bcc0a 100644 --- a/main/HSSF/Record/Cont/UnknownLengthRecordOutput.cs +++ b/main/HSSF/Record/Cont/UnknownLengthRecordOutput.cs @@ -42,13 +42,12 @@ public UnknownLengthRecordOutput(ILittleEndianOutput out1, int sid) { _originalOut = out1; out1.WriteShort(sid); - if (out1 is IDelayableLittleEndianOutput) + if (out1 is IDelayableLittleEndianOutput dleo) { // optimisation - IDelayableLittleEndianOutput dleo = (IDelayableLittleEndianOutput)out1; _dataSizeOutput = dleo.CreateDelayedOutput(2); _byteBuffer = null; - _out = out1; + _out = dleo; } else { diff --git a/main/HSSF/Record/Crypto/Biff8DecryptingStream.cs b/main/HSSF/Record/Crypto/Biff8DecryptingStream.cs index c7c2f4bc8..994ff061e 100644 --- a/main/HSSF/Record/Crypto/Biff8DecryptingStream.cs +++ b/main/HSSF/Record/Crypto/Biff8DecryptingStream.cs @@ -37,10 +37,10 @@ public Biff8DecryptingStream(Stream in1, int InitialOffSet, Biff8EncryptionKey k { _rc4 = new Biff8RC4(InitialOffSet, key); - if (in1 is ILittleEndianInput) + if (in1 is ILittleEndianInput input) { // accessing directly is an optimisation - _le = (ILittleEndianInput)in1; + _le = input; } else { diff --git a/main/HSSF/Record/DVRecord.cs b/main/HSSF/Record/DVRecord.cs index c115de31b..108cbf656 100644 --- a/main/HSSF/Record/DVRecord.cs +++ b/main/HSSF/Record/DVRecord.cs @@ -205,33 +205,32 @@ public int DataType public override bool Equals(object obj) { - if (obj == null || !(obj is DVRecord)) + if (obj == null || obj is not DVRecord dv) { return false; } - DVRecord dv = (DVRecord)obj; return DataType == dv.DataType - && ErrorStyle == dv.ErrorStyle - && EmptyCellAllowed == dv.EmptyCellAllowed - && ShowErrorOnInvalidValue == dv.ShowErrorOnInvalidValue - && ShowPromptOnCellSelected == dv.ShowPromptOnCellSelected - && SuppressDropdownArrow == dv.SuppressDropdownArrow - && ListExplicitFormula == dv.ListExplicitFormula - && ConditionOperator == dv.ConditionOperator - && PromptTitle == dv.PromptTitle - && PromptText == dv.PromptText - && ErrorTitle == dv.ErrorTitle - && ErrorText == dv.ErrorText - && ((Formula1 == null && dv.Formula1 == null) - || Formula1 != null && dv.Formula1 != null - && Formula1.ToString() == dv.Formula1.ToString()) - && ((Formula2 == null && dv.Formula2 == null) - || Formula2 != null && dv.Formula2 != null - && Formula2.ToString() == dv.Formula2.ToString()) - && (CellRangeAddress == null && dv.CellRangeAddress == null - || CellRangeAddress != null && dv.CellRangeAddress != null - && CellRangeAddress.ToString() == dv.CellRangeAddress.ToString()); + && ErrorStyle == dv.ErrorStyle + && EmptyCellAllowed == dv.EmptyCellAllowed + && ShowErrorOnInvalidValue == dv.ShowErrorOnInvalidValue + && ShowPromptOnCellSelected == dv.ShowPromptOnCellSelected + && SuppressDropdownArrow == dv.SuppressDropdownArrow + && ListExplicitFormula == dv.ListExplicitFormula + && ConditionOperator == dv.ConditionOperator + && PromptTitle == dv.PromptTitle + && PromptText == dv.PromptText + && ErrorTitle == dv.ErrorTitle + && ErrorText == dv.ErrorText + && ((Formula1 == null && dv.Formula1 == null) + || Formula1 != null && dv.Formula1 != null + && Formula1.ToString() == dv.Formula1.ToString()) + && ((Formula2 == null && dv.Formula2 == null) + || Formula2 != null && dv.Formula2 != null + && Formula2.ToString() == dv.Formula2.ToString()) + && (CellRangeAddress == null && dv.CellRangeAddress == null + || CellRangeAddress != null && dv.CellRangeAddress != null + && CellRangeAddress.ToString() == dv.CellRangeAddress.ToString()); } /** diff --git a/main/HSSF/Record/EscherAggregate.cs b/main/HSSF/Record/EscherAggregate.cs index 97bfb4f99..e07731bec 100644 --- a/main/HSSF/Record/EscherAggregate.cs +++ b/main/HSSF/Record/EscherAggregate.cs @@ -666,9 +666,9 @@ private int GetEscherRecordSize(List records) private static short GetSid(List records, int loc) { RecordBase record = records[(loc)]; - if (record is Record) + if (record is Record record1) { - return ((Record)record).Sid; + return record1.Sid; } else { diff --git a/main/HSSF/Record/ExtendedFormatRecord.cs b/main/HSSF/Record/ExtendedFormatRecord.cs index 193997b45..ddfa44e3e 100644 --- a/main/HSSF/Record/ExtendedFormatRecord.cs +++ b/main/HSSF/Record/ExtendedFormatRecord.cs @@ -1018,9 +1018,8 @@ public override bool Equals(Object obj) return true; if (obj == null) return false; - if (obj is ExtendedFormatRecord) + if (obj is ExtendedFormatRecord other) { - ExtendedFormatRecord other = (ExtendedFormatRecord)obj; if (field_1_font_index != other.field_1_font_index) return false; if (field_2_format_index != other.field_2_format_index) diff --git a/main/HSSF/Record/FilePassRecord.cs b/main/HSSF/Record/FilePassRecord.cs index 76901c0c7..d6bd0ba97 100644 --- a/main/HSSF/Record/FilePassRecord.cs +++ b/main/HSSF/Record/FilePassRecord.cs @@ -281,15 +281,15 @@ protected override int DataSize public Rc4KeyData GetRc4KeyData() { - return (_keyData is Rc4KeyData) - ? (Rc4KeyData)_keyData + return (_keyData is Rc4KeyData data) + ? data : null; } public XorKeyData GetXorKeyData() { - return (_keyData is XorKeyData) - ? (XorKeyData)_keyData + return (_keyData is XorKeyData data) + ? data : null; } diff --git a/main/HSSF/Record/FormulaRecord.cs b/main/HSSF/Record/FormulaRecord.cs index efbf93142..5a7c88655 100644 --- a/main/HSSF/Record/FormulaRecord.cs +++ b/main/HSSF/Record/FormulaRecord.cs @@ -431,14 +431,13 @@ public NPOI.SS.UserModel.CellType CachedResultType public override bool Equals(Object obj) { - if (!(obj is CellValueRecordInterface)) + if (obj is not CellValueRecordInterface loc) { return false; } - CellValueRecordInterface loc = (CellValueRecordInterface)obj; if ((this.Row == loc.Row) - && (this.Column == loc.Column)) + && (this.Column == loc.Column)) { return true; } diff --git a/main/HSSF/Record/RecordFactory.cs b/main/HSSF/Record/RecordFactory.cs index 3ce87ad84..8626b1649 100644 --- a/main/HSSF/Record/RecordFactory.cs +++ b/main/HSSF/Record/RecordFactory.cs @@ -487,13 +487,13 @@ public static Record[] CreateRecord(RecordInputStream in1) // Not needed by POI. Regenerated from scratch by POI when spreadsheet is written return new Record[] { null, }; } - if (record is RKRecord) + if (record is RKRecord rkRecord) { - return new Record[] { ConvertToNumberRecord((RKRecord)record), }; + return new Record[] { ConvertToNumberRecord(rkRecord), }; } - if (record is MulRKRecord) + if (record is MulRKRecord mulRkRecord) { - return ConvertRKRecords((MulRKRecord)record); + return ConvertRKRecords(mulRkRecord); } return new Record[] { record, }; } diff --git a/main/HSSF/Record/RecordFactoryInputStream.cs b/main/HSSF/Record/RecordFactoryInputStream.cs index 7322339bb..344ef63c7 100644 --- a/main/HSSF/Record/RecordFactoryInputStream.cs +++ b/main/HSSF/Record/RecordFactoryInputStream.cs @@ -80,9 +80,9 @@ public StreamEncryptionInfo(RecordInputStream rs, List outputRecs) } // If it's a FILEPASS, track it specifically but // don't include it in the main stream - if (rec is FilePassRecord) + if (rec is FilePassRecord record) { - fpr = (FilePassRecord)rec; + fpr = record; outputRecs.RemoveAt(outputRecs.Count - 1); // TODO - add fpr not Added to outPutRecs rec = outputRecs[0]; @@ -340,14 +340,14 @@ private Record ReadNextRecord() return null; } - if (record is RKRecord) + if (record is RKRecord rkRecord) { - return RecordFactory.ConvertToNumberRecord((RKRecord)record); + return RecordFactory.ConvertToNumberRecord(rkRecord); } - if (record is MulRKRecord) + if (record is MulRKRecord mulRkRecord) { - Record[] records = RecordFactory.ConvertRKRecords((MulRKRecord)record); + Record[] records = RecordFactory.ConvertRKRecords(mulRkRecord); _unreadRecordBuffer = records; _unreadRecordIndex = 1; @@ -355,10 +355,9 @@ private Record ReadNextRecord() } if (record.Sid == DrawingGroupRecord.sid - && _lastRecord is DrawingGroupRecord) + && _lastRecord is DrawingGroupRecord lastDgRecord) { - DrawingGroupRecord lastDGRecord = (DrawingGroupRecord)_lastRecord; - lastDGRecord.Join((AbstractEscherHolderRecord)record); + lastDgRecord.Join((AbstractEscherHolderRecord)record); return null; } if (record.Sid == ContinueRecord.sid) @@ -378,9 +377,9 @@ private Record ReadNextRecord() } return null; } - if (_lastRecord is DrawingGroupRecord) + if (_lastRecord is DrawingGroupRecord groupRecord) { - ((DrawingGroupRecord)_lastRecord).ProcessContinueRecord(contRec.Data); + groupRecord.ProcessContinueRecord(contRec.Data); return null; } if (_lastRecord is DrawingRecord) @@ -412,9 +411,9 @@ private Record ReadNextRecord() throw new RecordFormatException("Unhandled Continue Record"); } _lastRecord = record; - if (record is DrawingRecord) + if (record is DrawingRecord drawingRecord) { - _lastDrawingRecord = (DrawingRecord)record; + _lastDrawingRecord = drawingRecord; } return record; } diff --git a/main/HSSF/Record/RecordInputStream.cs b/main/HSSF/Record/RecordInputStream.cs index 9d6fe1b6a..02e15c047 100644 --- a/main/HSSF/Record/RecordInputStream.cs +++ b/main/HSSF/Record/RecordInputStream.cs @@ -57,10 +57,10 @@ internal sealed class SimpleHeaderInput : BiffHeaderInput internal static ILittleEndianInput GetLEI(Stream in1) { - if (in1 is ILittleEndianInput) + if (in1 is ILittleEndianInput input) { // accessing directly is an optimisation - return (ILittleEndianInput)in1; + return input; } // less optimal, but should work OK just the same. Often occurs in junit tests. return new LittleEndianInputStream(in1); diff --git a/main/HSSF/Record/RowRecord.cs b/main/HSSF/Record/RowRecord.cs index 86a189bd2..2f1dbb955 100644 --- a/main/HSSF/Record/RowRecord.cs +++ b/main/HSSF/Record/RowRecord.cs @@ -401,11 +401,10 @@ public int CompareTo(Object obj) public override bool Equals(Object obj) { - if (!(obj is RowRecord)) + if (obj is not RowRecord loc) { return false; } - RowRecord loc = (RowRecord)obj; if (this.RowNumber == loc.RowNumber) { diff --git a/main/HSSF/UserModel/HSSFAutoFilter.cs b/main/HSSF/UserModel/HSSFAutoFilter.cs index 28efd7040..439e5aa56 100644 --- a/main/HSSF/UserModel/HSSFAutoFilter.cs +++ b/main/HSSF/UserModel/HSSFAutoFilter.cs @@ -26,7 +26,7 @@ public HSSFAutoFilter(string formula,HSSFWorkbook workbook) //this.workbook = workbook; Ptg[] ptgs = HSSFFormulaParser.Parse(formula, workbook); - if (!(ptgs[0] is Area3DPtg)) + if (ptgs[0] is not Area3DPtg) throw new ArgumentException("incorrect formula"); Area3DPtg ptg = (Area3DPtg)ptgs[0]; diff --git a/main/HSSF/UserModel/HSSFCell.cs b/main/HSSF/UserModel/HSSFCell.cs index bd8a545c7..25c4559a7 100644 --- a/main/HSSF/UserModel/HSSFCell.cs +++ b/main/HSSF/UserModel/HSSFCell.cs @@ -647,9 +647,9 @@ public ICell SetCellValue(IRichTextString value) */ private void NotifyFormulaChanging() { - if (_record is FormulaRecordAggregate) + if (_record is FormulaRecordAggregate aggregate) { - ((FormulaRecordAggregate)_record).NotifyFormulaChanging(); + aggregate.NotifyFormulaChanging(); } } @@ -661,10 +661,10 @@ public String CellFormula { get { - if (!(_record is FormulaRecordAggregate)) + if (_record is not FormulaRecordAggregate aggregate) throw TypeMismatch(CellType.Formula, cellType, true); - return HSSFFormulaParser.ToFormulaString(book, ((FormulaRecordAggregate)_record).FormulaTokens); + return HSSFFormulaParser.ToFormulaString(book, aggregate.FormulaTokens); } set { @@ -1361,12 +1361,11 @@ public void RemoveHyperlink() for (IEnumerator it = _sheet.Sheet.Records.GetEnumerator(); it.MoveNext(); ) { RecordBase rec = it.Current; - if (rec is HyperlinkRecord) + if (rec is HyperlinkRecord link) { - HyperlinkRecord link = (HyperlinkRecord)rec; if (link.FirstColumn == _record.Column && link.FirstRow == _record.Row) { - toRemove = rec; + toRemove = link; break; //it.Remove(); //return; diff --git a/main/HSSF/UserModel/HSSFCellStyle.cs b/main/HSSF/UserModel/HSSFCellStyle.cs index 210a4f860..25676d9ac 100644 --- a/main/HSSF/UserModel/HSSFCellStyle.cs +++ b/main/HSSF/UserModel/HSSFCellStyle.cs @@ -577,9 +577,9 @@ private void CheckDefaultBackgroundFills() */ public void CloneStyleFrom(ICellStyle source) { - if (source is HSSFCellStyle) + if (source is HSSFCellStyle style) { - this.CloneStyleFrom((HSSFCellStyle)source); + this.CloneStyleFrom(style); } else { @@ -766,9 +766,8 @@ public override bool Equals(Object obj) { if (this == obj) return true; if (obj == null) return false; - if (obj is HSSFCellStyle) + if (obj is HSSFCellStyle other) { - HSSFCellStyle other = (HSSFCellStyle)obj; if (_format == null) { if (other._format != null) diff --git a/main/HSSF/UserModel/HSSFChart.cs b/main/HSSF/UserModel/HSSFChart.cs index 4c491a811..cd7968d17 100644 --- a/main/HSSF/UserModel/HSSFChart.cs +++ b/main/HSSF/UserModel/HSSFChart.cs @@ -151,35 +151,34 @@ public static HSSFChart[] GetSheetCharts(HSSFSheet sheet) foreach (RecordBase r in records) { - if (r is ChartRecord) + if (r is ChartRecord record1) { lastSeries = null; - lastChart = new HSSFChart(sheet, (ChartRecord)r); + lastChart = new HSSFChart(sheet, record1); charts.Add(lastChart); } - else if (r is LegendRecord) + else if (r is LegendRecord legendRecord1) { - lastChart.legendRecord = (LegendRecord)r; + lastChart.legendRecord = legendRecord1; } - else if (r is SeriesRecord) + else if (r is SeriesRecord seriesRecord) { - HSSFSeries series = new HSSFSeries((SeriesRecord)r); + HSSFSeries series = new HSSFSeries(seriesRecord); lastChart.series.Add(series); lastSeries = series; } - else if (r is AlRunsRecord) + else if (r is AlRunsRecord runsRecord) { lastChart.chartTitleFormat = - (AlRunsRecord)r; + runsRecord; } - else if (r is SeriesTextRecord) + else if (r is SeriesTextRecord str) { // Applies to a series, unless we've seen // a legend already - SeriesTextRecord str = (SeriesTextRecord)r; if (lastChart.legendRecord == null && - lastChart.series.Count > 0) + lastChart.series.Count > 0) { HSSFSeries series = (HSSFSeries) lastChart.series[lastChart.series.Count - 1]; @@ -190,23 +189,21 @@ public static HSSFChart[] GetSheetCharts(HSSFSheet sheet) lastChart.chartTitleText = str; } } - else if (r is LinkedDataRecord) + else if (r is LinkedDataRecord linkedDataRecord) { - LinkedDataRecord linkedDataRecord = (LinkedDataRecord)r; if (lastSeries != null) { lastSeries.InsertData(linkedDataRecord); } } - else if (r is ValueRangeRecord) + else if (r is ValueRangeRecord rangeRecord) { - lastChart.valueRanges.Add((ValueRangeRecord)r); + lastChart.valueRanges.Add(rangeRecord); } - else if (r is Record) + else if (r is Record record) { if (lastChart != null) { - Record record = (Record)r; foreach (int type in Enum.GetValues(typeof(HSSFChartType))) { if (type == 0) @@ -1126,10 +1123,8 @@ private CellRangeAddressBase GetCellRange(LinkedDataRecord linkedDataRecord) foreach (Ptg ptg in linkedDataRecord.FormulaOfLink) { - if (ptg is AreaPtgBase) + if (ptg is AreaPtgBase areaPtg) { - AreaPtgBase areaPtg = (AreaPtgBase)ptg; - firstRow = areaPtg.FirstRow; lastRow = areaPtg.LastRow; @@ -1166,10 +1161,8 @@ private int SetVerticalCellRange(LinkedDataRecord linkedDataRecord, foreach (Ptg ptg in linkedDataRecord.FormulaOfLink) { - if (ptg is AreaPtgBase) + if (ptg is AreaPtgBase areaPtg) { - AreaPtgBase areaPtg = (AreaPtgBase)ptg; - areaPtg.FirstRow = range.FirstRow; areaPtg.LastRow = range.LastRow; @@ -1293,42 +1286,42 @@ public HSSFSeries CreateSeries() { newRecord = new EndRecord(); } - else if (record is SeriesRecord) + else if (record is SeriesRecord record1) { - SeriesRecord seriesRecord = (SeriesRecord)((SeriesRecord)record).Clone(); + SeriesRecord seriesRecord = (SeriesRecord)record1.Clone(); newSeries = new HSSFSeries(seriesRecord); newRecord = seriesRecord; } - else if (record is LinkedDataRecord) + else if (record is LinkedDataRecord dataRecord) { - LinkedDataRecord linkedDataRecord = (LinkedDataRecord)((LinkedDataRecord)record).Clone(); + LinkedDataRecord linkedDataRecord = (LinkedDataRecord)dataRecord.Clone(); if (newSeries != null) { newSeries.InsertData(linkedDataRecord); } newRecord = linkedDataRecord; } - else if (record is DataFormatRecord) + else if (record is DataFormatRecord formatRecord) { - DataFormatRecord dataFormatRecord = (DataFormatRecord)((DataFormatRecord)record).Clone(); + DataFormatRecord dataFormatRecord = (DataFormatRecord)formatRecord.Clone(); dataFormatRecord.SeriesIndex = ((short)seriesIdx); dataFormatRecord.SeriesNumber = ((short)seriesIdx); newRecord = dataFormatRecord; } - else if (record is SeriesTextRecord) + else if (record is SeriesTextRecord textRecord) { - SeriesTextRecord seriesTextRecord = (SeriesTextRecord)((SeriesTextRecord)record).Clone(); + SeriesTextRecord seriesTextRecord = (SeriesTextRecord)textRecord.Clone(); if (newSeries != null) { newSeries.SetSeriesTitleText(seriesTextRecord); } newRecord = seriesTextRecord; } - else if (record is Record) + else if (record is Record record2) { - newRecord = (Record)((Record)record).Clone(); + newRecord = (Record)record2.Clone(); } if (newRecord != null) @@ -1421,11 +1414,10 @@ public bool RemoveSeries(HSSFSeries series) } } } - else if (record is DataFormatRecord) + else if (record is DataFormatRecord dataFormatRecord) { if (chartEntered && !RemoveSeries) { - DataFormatRecord dataFormatRecord = (DataFormatRecord)record; dataFormatRecord.SeriesIndex = ((short)seriesIdx); dataFormatRecord.SeriesNumber = ((short)seriesIdx); } diff --git a/main/HSSF/UserModel/HSSFComment.cs b/main/HSSF/UserModel/HSSFComment.cs index 9ab571a68..af527d106 100644 --- a/main/HSSF/UserModel/HSSFComment.cs +++ b/main/HSSF/UserModel/HSSFComment.cs @@ -252,9 +252,9 @@ public IClientAnchor ClientAnchor get { HSSFAnchor ha = base.Anchor as HSSFAnchor; - if (ha is IClientAnchor) + if (ha is IClientAnchor clientAnchor) { - return (IClientAnchor)ha; + return clientAnchor; } throw new InvalidCastException("Anchor can not be changed in " @@ -330,11 +330,11 @@ private void SetHidden(bool value) } public override bool Equals(Object obj) { - if (!(obj is HSSFComment)) + if (obj is not HSSFComment other) { return false; } - HSSFComment other = (HSSFComment)obj; + return NoteRecord.Equals(other.NoteRecord); } public override int GetHashCode() diff --git a/main/HSSF/UserModel/HSSFEvaluationWorkbook.cs b/main/HSSF/UserModel/HSSFEvaluationWorkbook.cs index 23282dcda..0f0d6d8db 100644 --- a/main/HSSF/UserModel/HSSFEvaluationWorkbook.cs +++ b/main/HSSF/UserModel/HSSFEvaluationWorkbook.cs @@ -298,9 +298,9 @@ private int GetSheetExtIx(SheetIdentifier sheetIden) String firstSheetName = sheetIden.SheetId.Name; String lastSheetName = firstSheetName; - if (sheetIden is SheetRangeIdentifier) + if (sheetIden is SheetRangeIdentifier identifier) { - lastSheetName = ((SheetRangeIdentifier)sheetIden).LastSheetIdentifier.Name; + lastSheetName = identifier.LastSheetIdentifier.Name; } if (workbookName == null) diff --git a/main/HSSF/UserModel/HSSFFont.cs b/main/HSSF/UserModel/HSSFFont.cs index fe4e64777..f821c4332 100644 --- a/main/HSSF/UserModel/HSSFFont.cs +++ b/main/HSSF/UserModel/HSSFFont.cs @@ -239,9 +239,8 @@ public override bool Equals(Object obj) { if (this == obj) return true; if (obj == null) return false; - if (obj is HSSFFont) + if (obj is HSSFFont other) { - HSSFFont other = (HSSFFont)obj; if (font == null) { if (other.font != null) diff --git a/main/HSSF/UserModel/HSSFFormulaEvaluator.cs b/main/HSSF/UserModel/HSSFFormulaEvaluator.cs index 327510e49..055c6b538 100644 --- a/main/HSSF/UserModel/HSSFFormulaEvaluator.cs +++ b/main/HSSF/UserModel/HSSFFormulaEvaluator.cs @@ -158,24 +158,21 @@ public override void NotifySetFormula(ICell cell) protected override CellValue EvaluateFormulaCellValue(ICell cell) { ValueEval eval = _bookEvaluator.Evaluate(new HSSFEvaluationCell((HSSFCell)cell)); - if (eval is BoolEval) + if (eval is BoolEval be) { - BoolEval be = (BoolEval)eval; return CellValue.ValueOf(be.BooleanValue); } - if (eval is NumberEval) + if (eval is NumberEval numberEval) { - NumberEval ne = (NumberEval)eval; - return new CellValue(ne.NumberValue); + return new CellValue(numberEval.NumberValue); } - if (eval is StringEval) + if (eval is StringEval ne) { - StringEval ne = (StringEval)eval; return new CellValue(ne.StringValue); } - if (eval is ErrorEval) + if (eval is ErrorEval errorEval) { - return CellValue.GetError(((ErrorEval)eval).ErrorCode); + return CellValue.GetError(errorEval.ErrorCode); } throw new InvalidOperationException("Unexpected eval class (" + eval.GetType().Name + ")"); } diff --git a/main/HSSF/UserModel/HSSFHyperlink.cs b/main/HSSF/UserModel/HSSFHyperlink.cs index 4240a2eb7..7fd89ab4b 100644 --- a/main/HSSF/UserModel/HSSFHyperlink.cs +++ b/main/HSSF/UserModel/HSSFHyperlink.cs @@ -99,9 +99,8 @@ private HyperlinkType getType(HyperlinkRecord record) public HSSFHyperlink(IHyperlink other) { - if (other is HSSFHyperlink) + if (other is HSSFHyperlink hlink) { - HSSFHyperlink hlink = (HSSFHyperlink)other; record = hlink.record.Clone() as HyperlinkRecord; link_type = getType(record); } @@ -221,8 +220,7 @@ public HyperlinkType Type public override bool Equals(Object other) { if (this == other) return true; - if (!(other is HSSFHyperlink)) return false; - HSSFHyperlink otherLink = (HSSFHyperlink)other; + if (other is not HSSFHyperlink otherLink) return false; return record == otherLink.record; } diff --git a/main/HSSF/UserModel/HSSFObjectData.cs b/main/HSSF/UserModel/HSSFObjectData.cs index 1714a57dd..267171290 100644 --- a/main/HSSF/UserModel/HSSFObjectData.cs +++ b/main/HSSF/UserModel/HSSFObjectData.cs @@ -72,9 +72,9 @@ public DirectoryEntry GetDirectory() String streamName = "MBD" + HexDump.ToHex((int)streamId); Entry entry = _root.GetEntry(streamName); - if (entry is DirectoryEntry) + if (entry is DirectoryEntry directoryEntry) { - return (DirectoryEntry)entry; + return directoryEntry; } else { @@ -117,9 +117,9 @@ public EmbeddedObjectRefSubRecord FindObjectRecord() while (subRecordIter.MoveNext()) { Object subRecord = subRecordIter.Current; - if (subRecord is EmbeddedObjectRefSubRecord) + if (subRecord is EmbeddedObjectRefSubRecord record) { - return (EmbeddedObjectRefSubRecord)subRecord; + return record; } } diff --git a/main/HSSF/UserModel/HSSFPatriarch.cs b/main/HSSF/UserModel/HSSFPatriarch.cs index 3b739378f..d413c4171 100644 --- a/main/HSSF/UserModel/HSSFPatriarch.cs +++ b/main/HSSF/UserModel/HSSFPatriarch.cs @@ -73,9 +73,9 @@ public static HSSFPatriarch CreatePatriarch(HSSFPatriarch patriarch, HSSFSheet s foreach (HSSFShape shape in patriarch.Children) { HSSFShape newShape; - if (shape is HSSFShapeGroup) + if (shape is HSSFShapeGroup group) { - newShape = ((HSSFShapeGroup)shape).CloneShape(newPatriarch); + newShape = group.CloneShape(newPatriarch); } else { diff --git a/main/HSSF/UserModel/HSSFPicture.cs b/main/HSSF/UserModel/HSSFPicture.cs index ff9210f86..7d8176747 100644 --- a/main/HSSF/UserModel/HSSFPicture.cs +++ b/main/HSSF/UserModel/HSSFPicture.cs @@ -320,7 +320,7 @@ public IClientAnchor ClientAnchor get { HSSFAnchor a = Anchor as HSSFAnchor; - return (a is HSSFClientAnchor) ? (HSSFClientAnchor) a : null; + return (a is HSSFClientAnchor clientAnchor) ? clientAnchor : null; } } diff --git a/main/HSSF/UserModel/HSSFRichTextString.cs b/main/HSSF/UserModel/HSSFRichTextString.cs index 7ec46aa36..c201ade74 100644 --- a/main/HSSF/UserModel/HSSFRichTextString.cs +++ b/main/HSSF/UserModel/HSSFRichTextString.cs @@ -318,9 +318,9 @@ public int CompareTo(HSSFRichTextString other) /// public override bool Equals(Object o) { - if (o is HSSFRichTextString) + if (o is HSSFRichTextString textString) { - return _string.Equals(((HSSFRichTextString)o)._string); + return _string.Equals(textString._string); } return false; } diff --git a/main/HSSF/UserModel/HSSFRow.cs b/main/HSSF/UserModel/HSSFRow.cs index b8116aaaa..feb160ec7 100644 --- a/main/HSSF/UserModel/HSSFRow.cs +++ b/main/HSSF/UserModel/HSSFRow.cs @@ -766,11 +766,10 @@ public int CompareTo(HSSFRow other) /// public override bool Equals(Object obj) { - if (!(obj is HSSFRow)) + if (obj is not HSSFRow other) { return false; } - HSSFRow other = (HSSFRow)obj; return (this.RowNum == other.RowNum) && (this.Sheet == other.Sheet); diff --git a/main/HSSF/UserModel/HSSFShape.cs b/main/HSSF/UserModel/HSSFShape.cs index 6eff7e1d1..7331e3adc 100644 --- a/main/HSSF/UserModel/HSSFShape.cs +++ b/main/HSSF/UserModel/HSSFShape.cs @@ -458,8 +458,8 @@ public String ShapeName return null; } EscherProperty ep = eor.Lookup(EscherProperties.GROUPSHAPE__SHAPENAME); - if (ep is EscherComplexProperty) { - return StringUtil.GetFromUnicodeLE(((EscherComplexProperty)ep).ComplexData); + if (ep is EscherComplexProperty property) { + return StringUtil.GetFromUnicodeLE(property.ComplexData); } return null; } diff --git a/main/HSSF/UserModel/HSSFShapeGroup.cs b/main/HSSF/UserModel/HSSFShapeGroup.cs index 80795e080..127212cbb 100644 --- a/main/HSSF/UserModel/HSSFShapeGroup.cs +++ b/main/HSSF/UserModel/HSSFShapeGroup.cs @@ -410,9 +410,9 @@ internal HSSFShape CloneShape(HSSFPatriarch patriarch) foreach (HSSFShape shape in Children) { HSSFShape newShape; - if (shape is HSSFShapeGroup) + if (shape is HSSFShapeGroup shapeGroup) { - newShape = ((HSSFShapeGroup)shape).CloneShape(patriarch); + newShape = shapeGroup.CloneShape(patriarch); } else { diff --git a/main/HSSF/UserModel/HSSFSheet.cs b/main/HSSF/UserModel/HSSFSheet.cs index f5b939a43..19de41e98 100644 --- a/main/HSSF/UserModel/HSSFSheet.cs +++ b/main/HSSF/UserModel/HSSFSheet.cs @@ -504,11 +504,11 @@ public RecordVisitor1(List hssfValidations, IWorkbook workbook) private readonly HSSFEvaluationWorkbook book; public void VisitRecord(Record r) { - if (!(r is DVRecord)) + if (r is not DVRecord dvRecord) { return; } - DVRecord dvRecord = (DVRecord)r; + CellRangeAddressList regions = dvRecord.CellRangeAddress.Copy(); DVConstraint constraint = DVConstraint.CreateDVConstraint(dvRecord, book); HSSFDataValidation hssfDataValidation = new HSSFDataValidation(regions, constraint); @@ -1744,11 +1744,11 @@ private void moveCommentsForRowShift(int startRow, int endRow, int n) for (int i = lastChildIndex; i >= 0; i--) { HSSFShape shape = patriarch.Children[(i)]; - if (!(shape is HSSFComment)) + if (shape is not HSSFComment comment) { continue; } - HSSFComment comment = (HSSFComment)shape; + int r = comment.Row; if (startRow <= r && r <= endRow) { @@ -2221,12 +2221,12 @@ public ICellRange RemoveArrayFormula(ICell cell) throw new ArgumentException("Specified cell does not belong to this sheet."); } CellValueRecordInterface rec = ((HSSFCell)cell).CellValueRecord; - if (!(rec is FormulaRecordAggregate)) + if (rec is not FormulaRecordAggregate fra) { String ref1 = new CellReference(cell).FormatAsString(); throw new ArgumentException("Cell " + ref1 + " is not part of an array formula."); } - FormulaRecordAggregate fra = (FormulaRecordAggregate)rec; + CellRangeAddress range = fra.RemoveArrayFormula(cell.RowIndex, cell.ColumnIndex); ICellRange result = GetCellRange(range); @@ -2522,12 +2522,11 @@ public IHyperlink GetHyperlink(int row, int column) { foreach (RecordBase rec in _sheet.Records) { - if (rec is HyperlinkRecord) + if (rec is HyperlinkRecord record) { - HyperlinkRecord link = (HyperlinkRecord)rec; - if (link.FirstColumn == column && link.FirstRow == row) + if (record.FirstColumn == column && record.FirstRow == row) { - return new HSSFHyperlink(link); + return new HSSFHyperlink(record); } } else if (rec is RowRecordsAggregate rra) { @@ -2564,9 +2563,8 @@ public List GetHyperlinkList() List hyperlinkList = new List(); foreach (RecordBase rec in _sheet.Records) { - if (rec is HyperlinkRecord){ - HyperlinkRecord link = (HyperlinkRecord)rec; - hyperlinkList.Add(new HSSFHyperlink(link)); + if (rec is HyperlinkRecord record){ + hyperlinkList.Add(new HSSFHyperlink(record)); } else if (rec is RowRecordsAggregate rra) { foreach (var link in rra.HyperlinkRecordRecords) @@ -2600,9 +2598,8 @@ protected void RemoveHyperlink(HyperlinkRecord link) for (int i = 0; i < _sheet.Records.Count; i++) { RecordBase rec = _sheet.Records[i]; - if (rec is HyperlinkRecord) + if (rec is HyperlinkRecord recLink) { - HyperlinkRecord recLink = (HyperlinkRecord)rec; if (link == recLink) { _sheet.Records.RemoveAt(i); @@ -2740,18 +2737,17 @@ private HSSFComment LookForComment(HSSFShapeContainer container, int row, int co foreach (Object obj in container.Children) { HSSFShape shape = (HSSFShape)obj; - if (shape is HSSFShapeGroup) + if (shape is HSSFShapeGroup group) { - HSSFShape res = LookForComment((HSSFShapeContainer)shape, row, column); + HSSFShape res = LookForComment(group, row, column); if (null != res) { return (HSSFComment)res; } continue; } - if (shape is HSSFComment) + if (shape is HSSFComment comment) { - HSSFComment comment = (HSSFComment)shape; if (comment.HasPosition && comment.Column == column && comment.Row == row) { return comment; @@ -2789,14 +2785,13 @@ private void FindCellCommentLocations(HSSFShapeContainer container, Dictionary usedIds) { foreach (EscherRecord child in parent.ChildRecords) { - if (child is EscherOptRecord) + if (child is EscherOptRecord picOpts) { - EscherOptRecord picOpts = (EscherOptRecord)child; foreach (EscherProperty eprop in picOpts.EscherProperties) { if (eprop.PropertyNumber == EscherProperties.BLIP__BLIPTODISPLAY) @@ -3229,9 +3221,8 @@ private void ApplyEscherRemap(EscherRecord parent, Dictionary mappings) { foreach (EscherRecord child in parent.ChildRecords) { - if (child is EscherOptRecord) + if (child is EscherOptRecord picOpts) { - EscherOptRecord picOpts = (EscherOptRecord)child; foreach (EscherProperty eprop in picOpts.EscherProperties) { if (eprop.PropertyNumber == EscherProperties.BLIP__BLIPTODISPLAY) diff --git a/main/HSSF/UserModel/HSSFWorkbook.cs b/main/HSSF/UserModel/HSSFWorkbook.cs index d3da62d53..eb7e048e5 100644 --- a/main/HSSF/UserModel/HSSFWorkbook.cs +++ b/main/HSSF/UserModel/HSSFWorkbook.cs @@ -2027,9 +2027,9 @@ public IList GetAllPictures() List pictures = new List(); foreach (Record r in workbook.Records) { - if (r is AbstractEscherHolderRecord) { - ((AbstractEscherHolderRecord)r).Decode(); - IList escherRecords = ((AbstractEscherHolderRecord)r).EscherRecords; + if (r is AbstractEscherHolderRecord record) { + record.Decode(); + IList escherRecords = record.EscherRecords; SearchForPictures(escherRecords, pictures); } } @@ -2056,13 +2056,11 @@ private void SearchForPictures(IList escherRecords, List pictur while (recordIter.MoveNext()) { Object obj = recordIter.Current; - if (obj is EscherRecord) + if (obj is EscherRecord escherRecord) { - EscherRecord escherRecord = (EscherRecord)obj; - - if (escherRecord is EscherBSERecord) + if (escherRecord is EscherBSERecord record) { - EscherBlipRecord blip = ((EscherBSERecord)escherRecord).BlipRecord; + EscherBlipRecord blip = record.BlipRecord; if (blip != null) { // TODO: Some kind of structure. @@ -2225,10 +2223,10 @@ private void GetAllEmbeddedObjects(HSSFSheet sheet, List objects private void GetAllEmbeddedObjects(HSSFShapeContainer parent, List objects) { foreach (HSSFShape shape in parent.Children) { - if (shape is HSSFObjectData) { - objects.Add((HSSFObjectData) shape); - } else if (shape is HSSFShapeContainer) { - GetAllEmbeddedObjects((HSSFShapeContainer) shape, objects); + if (shape is HSSFObjectData data) { + objects.Add(data); + } else if (shape is HSSFShapeContainer container) { + GetAllEmbeddedObjects(container, objects); } } } diff --git a/main/HSSF/Util/GUID.cs b/main/HSSF/Util/GUID.cs index a90a11f86..b12780907 100644 --- a/main/HSSF/Util/GUID.cs +++ b/main/HSSF/Util/GUID.cs @@ -47,10 +47,9 @@ public void Serialize(ILittleEndianOutput out1) { public override bool Equals(Object obj) { - if (!(obj is GUID)) return false; - GUID other = (GUID) obj; + if (obj is not GUID other) return false; return _d1 == other._d1 && _d2 == other._d2 - && _d3 == other._d3 && _d4 == other._d4; + && _d3 == other._d3 && _d4 == other._d4; } public override int GetHashCode () diff --git a/main/HSSF/Util/HSSFColor.cs b/main/HSSF/Util/HSSFColor.cs index eeef0f96f..1f147580f 100644 --- a/main/HSSF/Util/HSSFColor.cs +++ b/main/HSSF/Util/HSSFColor.cs @@ -209,7 +209,7 @@ public virtual String GetHexString() public static HSSFColor ToHSSFColor(IColor color) { - if (color != null && !(color is HSSFColor)) { + if (color != null && color is not HSSFColor) { throw new ArgumentException("Only HSSFColor objects are supported"); } return (HSSFColor)color; diff --git a/main/POIDocument.cs b/main/POIDocument.cs index 760f0702f..911965a56 100644 --- a/main/POIDocument.cs +++ b/main/POIDocument.cs @@ -157,9 +157,9 @@ protected internal void ReadProperties() // DocumentSummaryInformation ps = GetPropertySet(DocumentSummaryInformation.DEFAULT_STREAM_NAME); - if (ps != null && ps is DocumentSummaryInformation) + if (ps != null && ps is DocumentSummaryInformation information) { - dsInf = (DocumentSummaryInformation)ps; + dsInf = information; } else if (ps != null) { @@ -171,9 +171,9 @@ protected internal void ReadProperties() } // SummaryInformation ps = GetPropertySet(SummaryInformation.DEFAULT_STREAM_NAME); - if (ps is SummaryInformation) + if (ps is SummaryInformation summaryInformation) { - sInf = (SummaryInformation)ps; + sInf = summaryInformation; } else if (ps != null) { diff --git a/main/POIFS/Crypt/Cipher.cs b/main/POIFS/Crypt/Cipher.cs index 73ea87892..71ad29458 100644 --- a/main/POIFS/Crypt/Cipher.cs +++ b/main/POIFS/Crypt/Cipher.cs @@ -39,14 +39,14 @@ public static Cipher GetInstance(string transformation, string provider) public void Init(int cipherMode, IKey key, AlgorithmParameterSpec aps) { ICipherParameters cp; - if (aps is RC2ParameterSpec) + if (aps is RC2ParameterSpec spec) { - cp = new RC2Parameters(key.GetEncoded(), (aps as RC2ParameterSpec).GetEffectiveKeyBits()); + cp = new RC2Parameters(key.GetEncoded(), spec.GetEffectiveKeyBits()); } - else if (aps is IvParameterSpec) + else if (aps is IvParameterSpec parameterSpec) { cp = new KeyParameter(key.GetEncoded()); - cp = new ParametersWithIV(cp, (aps as IvParameterSpec).GetIV()); + cp = new ParametersWithIV(cp, parameterSpec.GetIV()); } else { diff --git a/main/POIFS/Dev/POIFSLister.cs b/main/POIFS/Dev/POIFSLister.cs index 4837b4978..31fcda6f1 100644 --- a/main/POIFS/Dev/POIFSLister.cs +++ b/main/POIFS/Dev/POIFSLister.cs @@ -53,9 +53,9 @@ public static void DisplayDirectory(DirectoryNode dir, String indent) while (it.MoveNext()) { Object entry = it.Current; - if (entry is DirectoryNode) + if (entry is DirectoryNode node) { - DisplayDirectory((DirectoryNode)entry, newIndent); + DisplayDirectory(node, newIndent); } else { diff --git a/main/POIFS/Dev/POIFSViewEngine.cs b/main/POIFS/Dev/POIFSViewEngine.cs index 53151fec4..42eff92b8 100644 --- a/main/POIFS/Dev/POIFSViewEngine.cs +++ b/main/POIFS/Dev/POIFSViewEngine.cs @@ -54,9 +54,9 @@ public static IList InspectViewable(Object viewable, String indentString) { List objects = new List(); - if (viewable is DictionaryEntry) + if (viewable is DictionaryEntry entry) { - ProcessViewable(((DictionaryEntry)viewable).Value, drilldown, indentLevel, indentString, objects); + ProcessViewable(entry.Value, drilldown, indentLevel, indentString, objects); } else if (viewable is POIFSViewable) { diff --git a/main/POIFS/FileSystem/DocumentFactoryHelper.cs b/main/POIFS/FileSystem/DocumentFactoryHelper.cs index df4478991..b032b20bb 100644 --- a/main/POIFS/FileSystem/DocumentFactoryHelper.cs +++ b/main/POIFS/FileSystem/DocumentFactoryHelper.cs @@ -85,9 +85,8 @@ public static bool HasOOXMLHeader(Stream inp) int bytesRead = IOUtils.ReadFully(inp, header); // Wind back those 4 bytes - if (inp is PushbackStream) + if (inp is PushbackStream pin) { - PushbackStream pin = (PushbackStream)inp; pin.Position = pin.Position - 4; //pin.unread(header, 0, bytesRead); } diff --git a/main/POIFS/FileSystem/DocumentInputStream.cs b/main/POIFS/FileSystem/DocumentInputStream.cs index 25c9e602d..6a9ac9845 100644 --- a/main/POIFS/FileSystem/DocumentInputStream.cs +++ b/main/POIFS/FileSystem/DocumentInputStream.cs @@ -53,24 +53,24 @@ protected DocumentInputStream() { } /// public DocumentInputStream(DocumentEntry document) { - if (!(document is DocumentNode)) + if (document is not DocumentNode documentNode) { throw new IOException("Cannot open internal document storage"); } - DocumentNode documentNode = (DocumentNode)document; + DirectoryNode parentNode = (DirectoryNode)document.Parent; if (documentNode.Document != null) { - delegate1 = new ODocumentInputStream(document); + delegate1 = new ODocumentInputStream(documentNode); } else if (parentNode.OFileSystem != null) { - delegate1 = new ODocumentInputStream(document); + delegate1 = new ODocumentInputStream(documentNode); } else if (parentNode.NFileSystem != null) { - delegate1 = new NDocumentInputStream(document); + delegate1 = new NDocumentInputStream(documentNode); } else { diff --git a/main/POIFS/FileSystem/FilteringDirectoryNode.cs b/main/POIFS/FileSystem/FilteringDirectoryNode.cs index ee2d385a6..3941f3069 100644 --- a/main/POIFS/FileSystem/FilteringDirectoryNode.cs +++ b/main/POIFS/FileSystem/FilteringDirectoryNode.cs @@ -134,10 +134,10 @@ public Entry GetEntry(String name) private Entry WrapEntry(Entry entry) { String name = entry.Name; - if (childExcludes.ContainsKey(name) && entry is DirectoryEntry) + if (childExcludes.ContainsKey(name) && entry is DirectoryEntry directoryEntry) { return new FilteringDirectoryNode( - (DirectoryEntry)entry, childExcludes[name]); + directoryEntry, childExcludes[name]); } return entry; } diff --git a/main/POIFS/FileSystem/NDocumentInputStream.cs b/main/POIFS/FileSystem/NDocumentInputStream.cs index 33529ddee..3880eaf7a 100644 --- a/main/POIFS/FileSystem/NDocumentInputStream.cs +++ b/main/POIFS/FileSystem/NDocumentInputStream.cs @@ -59,7 +59,7 @@ public class NDocumentInputStream : DocumentInputStream//DocumentReader /// IOException if the DocumentEntry cannot be opened (like, maybe it has been deleted?) public NDocumentInputStream(DocumentEntry document) { - if (!(document is DocumentNode)) + if (document is not DocumentNode doc) { throw new IOException("Cannot open internal document storage, " + document + " not a Document Node"); } @@ -70,7 +70,6 @@ public NDocumentInputStream(DocumentEntry document) _document_size = document.Size; _closed = false; - DocumentNode doc = (DocumentNode)document; DocumentProperty property = (DocumentProperty)doc.Property; _document = new NPOIFSDocument( property, diff --git a/main/POIFS/FileSystem/NDocumentOutputStream.cs b/main/POIFS/FileSystem/NDocumentOutputStream.cs index 4afcb1d28..cf720d7b2 100644 --- a/main/POIFS/FileSystem/NDocumentOutputStream.cs +++ b/main/POIFS/FileSystem/NDocumentOutputStream.cs @@ -55,16 +55,16 @@ public class NDocumentOutputStream : MemoryStream */ public NDocumentOutputStream(DocumentEntry document) { - if (!(document is DocumentNode)) + if (document is not DocumentNode node) { throw new IOException("Cannot open internal document storage, " + document + " not a Document Node"); } _document_size = 0; _closed = false; - _property = (DocumentProperty)((DocumentNode)document).Property; + _property = (DocumentProperty)node.Property; - _document = new NPOIFSDocument((DocumentNode)document); + _document = new NPOIFSDocument(node); _document.Free(); } @@ -76,7 +76,7 @@ public NDocumentOutputStream(DocumentEntry document) */ public NDocumentOutputStream(DirectoryEntry parent, String name) { - if (!(parent is DirectoryNode)) + if (parent is not DirectoryNode) { throw new IOException("Cannot open internal directory storage, " + parent + " not a Directory Node"); } diff --git a/main/POIFS/FileSystem/NPOIFSFileSystem.cs b/main/POIFS/FileSystem/NPOIFSFileSystem.cs index c43f4e331..6379eefb5 100644 --- a/main/POIFS/FileSystem/NPOIFSFileSystem.cs +++ b/main/POIFS/FileSystem/NPOIFSFileSystem.cs @@ -367,8 +367,7 @@ public static bool HasPOIFSHeader(Stream inp) LongField signature = new LongField(HeaderBlockConstants._signature_offset, header); // Wind back those 8 bytes - if (inp is PushbackInputStream) { - PushbackInputStream pin = (PushbackInputStream)inp; + if (inp is PushbackInputStream pin) { pin.Unread(header, 0, bytesRead); } else { inp.Position = 0; @@ -790,8 +789,8 @@ public DocumentEntry CreateOrUpdateDocument(Stream stream, */ public bool IsInPlaceWriteable() { - if (_data is FileBackedDataSource) { - if (((FileBackedDataSource)_data).IsWriteable) + if (_data is FileBackedDataSource source) { + if (source.IsWriteable) { return true; } diff --git a/main/POIFS/FileSystem/ODocumentInputStream.cs b/main/POIFS/FileSystem/ODocumentInputStream.cs index bb5998d8a..b86ede834 100644 --- a/main/POIFS/FileSystem/ODocumentInputStream.cs +++ b/main/POIFS/FileSystem/ODocumentInputStream.cs @@ -58,11 +58,11 @@ public class ODocumentInputStream : DocumentInputStream//DocumentReader */ public ODocumentInputStream(DocumentEntry document) { - if (!(document is DocumentNode)) + if (document is not DocumentNode documentNode) { throw new IOException("Cannot open internal document storage"); } - DocumentNode documentNode = (DocumentNode)document; + if (documentNode.Document == null) { throw new IOException("Cannot open internal document storage"); diff --git a/main/POIFS/FileSystem/OPOIFSDocument.cs b/main/POIFS/FileSystem/OPOIFSDocument.cs index d09c690a4..d8855464e 100644 --- a/main/POIFS/FileSystem/OPOIFSDocument.cs +++ b/main/POIFS/FileSystem/OPOIFSDocument.cs @@ -85,8 +85,8 @@ private static DocumentBlock[] ConvertRawBlocksToBigBlocks(ListManagedBlock[] bl private static SmallDocumentBlock[] ConvertRawBlocksToSmallBlocks(ListManagedBlock[] blocks) { - if (blocks is SmallDocumentBlock[]) - return (SmallDocumentBlock[])blocks; + if (blocks is SmallDocumentBlock[] documentBlocks) + return documentBlocks; SmallDocumentBlock[] result = new SmallDocumentBlock[blocks.Length]; System.Array.Copy(blocks, 0, result, 0, blocks.Length); return result; diff --git a/main/POIFS/FileSystem/POIFSDocumentReader.cs b/main/POIFS/FileSystem/POIFSDocumentReader.cs index 35789d184..3607f006c 100644 --- a/main/POIFS/FileSystem/POIFSDocumentReader.cs +++ b/main/POIFS/FileSystem/POIFSDocumentReader.cs @@ -55,11 +55,11 @@ public POIFSDocumentReader(DocumentEntry document) this._document_size = document.Size; this._closed = false; this._tiny_buffer = null; - if (!(document is DocumentNode)) + if (document is not DocumentNode node) { throw new IOException("Cannot open internal document storage"); } - this._document = ((DocumentNode)document).Document; + this._document = node.Document; } /// /// Create an InputStream from the specified Document diff --git a/main/POIFS/Macros/VBAMacroReader.cs b/main/POIFS/Macros/VBAMacroReader.cs index 5e32ef7bf..1ee298702 100644 --- a/main/POIFS/Macros/VBAMacroReader.cs +++ b/main/POIFS/Macros/VBAMacroReader.cs @@ -200,9 +200,9 @@ protected void FindMacros(DirectoryNode dir, ModuleMap modules) // Check children foreach (Entry child in dir) { - if (child is DirectoryNode) + if (child is DirectoryNode node) { - FindMacros((DirectoryNode)child, modules); + FindMacros(node, modules); } } } @@ -347,10 +347,9 @@ protected void ReadMacros(DirectoryNode macroDir, ModuleMap modules) { foreach (Entry entry in macroDir) { - if (!(entry is DocumentNode)) { continue; } + if (entry is not DocumentNode document) { continue; } String name = entry.Name; - DocumentNode document = (DocumentNode)entry; DocumentInputStream dis = new DocumentInputStream(document); try { diff --git a/main/SS/Format/CellFormat.cs b/main/SS/Format/CellFormat.cs index 0a1d6b2f9..e2ef2919e 100644 --- a/main/SS/Format/CellFormat.cs +++ b/main/SS/Format/CellFormat.cs @@ -238,18 +238,18 @@ public virtual CellFormatResult Apply(Object value) return GetApplicableFormatPart(val).Apply(val); } } - else if (value is DateTime) + else if (value is DateTime time) { // Don't know (and can't get) the workbook date windowing (1900 or 1904) // so assume 1900 date windowing - Double numericValue = DateUtil.GetExcelDate((DateTime)value); + Double numericValue = DateUtil.GetExcelDate(time); if (DateUtil.IsValidExcelDate(numericValue)) { - return GetApplicableFormatPart(numericValue).Apply(value); + return GetApplicableFormatPart(numericValue).Apply(time); } else { - throw new ArgumentException("value " + numericValue + " of date " + value + " is not a valid Excel date"); + throw new ArgumentException("value " + numericValue + " of date " + time + " is not a valid Excel date"); } } else @@ -413,9 +413,8 @@ public override bool Equals(Object obj) { if (this == obj) return true; - if (obj is CellFormat) + if (obj is CellFormat that) { - CellFormat that = (CellFormat)obj; return format.Equals(that.format); } return false; diff --git a/main/SS/Formula/Atp/AnalysisToolPak.cs b/main/SS/Formula/Atp/AnalysisToolPak.cs index 9c04865bb..16b778e2b 100644 --- a/main/SS/Formula/Atp/AnalysisToolPak.cs +++ b/main/SS/Formula/Atp/AnalysisToolPak.cs @@ -233,7 +233,7 @@ public static ReadOnlyCollection GetSupportedFunctionNames() foreach (KeyValuePair me in AnalysisToolPak._functionsByName) { FreeRefFunction func = me.Value; - if (func != null && !(func is NotImplemented)) + if (func != null && func is not NotImplemented) { lst.Add(me.Key); } @@ -287,7 +287,7 @@ public static void RegisterFunction(String name, FreeRefFunction func) } } FreeRefFunction f = inst.FindFunction(name); - if (f != null && !(f is NotImplemented)) + if (f != null && f is not NotImplemented) { throw new ArgumentException("POI already implememts " + name + ". You cannot override POI's implementations of Excel functions"); diff --git a/main/SS/Formula/Atp/ArgumentsEvaluator.cs b/main/SS/Formula/Atp/ArgumentsEvaluator.cs index 005ac7e5d..5d146597a 100644 --- a/main/SS/Formula/Atp/ArgumentsEvaluator.cs +++ b/main/SS/Formula/Atp/ArgumentsEvaluator.cs @@ -49,9 +49,9 @@ public double EvaluateDateArg(ValueEval arg, int srcCellRow, int srcCellCol) { ValueEval ve = OperandResolver.GetSingleValue(arg, srcCellRow, (short)srcCellCol); - if (ve is StringEval) + if (ve is StringEval eval) { - String strVal = ((StringEval)ve).StringValue; + String strVal = eval.StringValue; Double dVal = OperandResolver.ParseDouble(strVal); if (!Double.IsNaN(dVal)) { @@ -83,10 +83,9 @@ public double[] EvaluateDatesArg(ValueEval arg, int srcCellRow, int srcCellCol) { return new double[] { EvaluateDateArg(arg, srcCellRow, srcCellCol) }; } - else if (arg is AreaEvalBase) + else if (arg is AreaEvalBase area) { List valuesList = new List(); - AreaEvalBase area = (AreaEvalBase)arg; for (int i = area.FirstRow; i <= area.LastRow; i++) { for (int j = area.FirstColumn; j <= area.LastColumn; j++) diff --git a/main/SS/Formula/Atp/Switch.cs b/main/SS/Formula/Atp/Switch.cs index 5073c987e..457d9bda0 100644 --- a/main/SS/Formula/Atp/Switch.cs +++ b/main/SS/Formula/Atp/Switch.cs @@ -39,9 +39,8 @@ public ValueEval Evaluate(ValueEval[] args, OperationEvaluationContext ec) ValueEval evaluate = (new EqualEval()).Evaluate(new ValueEval[] { expression, value }, ec.RowIndex, ec.ColumnIndex); - if (evaluate is BoolEval) + if (evaluate is BoolEval boolEval) { - BoolEval boolEval = (BoolEval)evaluate; bool booleanValue = boolEval.BooleanValue; if (booleanValue) { diff --git a/main/SS/Formula/Atp/TextJoinFunction.cs b/main/SS/Formula/Atp/TextJoinFunction.cs index 903ba13b5..45799a731 100644 --- a/main/SS/Formula/Atp/TextJoinFunction.cs +++ b/main/SS/Formula/Atp/TextJoinFunction.cs @@ -112,9 +112,8 @@ private String LaxValueToString(ValueEval eval) //this is why lastRowOnly is supported private List GetValues(ValueEval eval, int srcRowIndex, int srcColumnIndex, bool lastRowOnly) { - if (eval is AreaEval) + if (eval is AreaEval ae) { - AreaEval ae = (AreaEval)eval; List list = new List(); int startRow = lastRowOnly ? ae.LastRow : ae.FirstRow; for (int r = startRow; r <= ae.LastRow; r++) diff --git a/main/SS/Formula/Atp/XLookupFunction.cs b/main/SS/Formula/Atp/XLookupFunction.cs index 1ede95059..04aa9cfb0 100644 --- a/main/SS/Formula/Atp/XLookupFunction.cs +++ b/main/SS/Formula/Atp/XLookupFunction.cs @@ -117,8 +117,7 @@ private ValueEval evaluate(int srcRowIndex, int srcColumnIndex, ValueEval lookup { if (string.IsNullOrEmpty(notFound)) { - if (returnEval is AreaEval) { - AreaEval area = (AreaEval)returnEval; + if (returnEval is AreaEval area) { int width = area.Width; if (isSingleValue || width <= 1) { @@ -137,13 +136,12 @@ private ValueEval evaluate(int srcRowIndex, int srcColumnIndex, ValueEval lookup return e.GetErrorEval(); } } - if (returnEval is AreaEval) { - AreaEval area = (AreaEval)returnEval; + if (returnEval is AreaEval eval) { if (isSingleValue) { - return area.GetRelativeValue(matchedRow, 0); + return eval.GetRelativeValue(matchedRow, 0); } - return area.Offset(matchedRow, matchedRow, 0, area.Width - 1); + return eval.Offset(matchedRow, matchedRow, 0, eval.Width - 1); } else { return returnEval; diff --git a/main/SS/Formula/Atp/YearFrac.cs b/main/SS/Formula/Atp/YearFrac.cs index cfff61fbb..88d759ff7 100644 --- a/main/SS/Formula/Atp/YearFrac.cs +++ b/main/SS/Formula/Atp/YearFrac.cs @@ -87,9 +87,9 @@ private static double EvaluateDateArg(ValueEval arg, int srcCellRow, int srcCell { ValueEval ve = OperandResolver.GetSingleValue(arg, srcCellRow, (short)srcCellCol); - if (ve is StringEval) + if (ve is StringEval eval) { - String strVal = ((StringEval)ve).StringValue; + String strVal = eval.StringValue; Double dVal = OperandResolver.ParseDouble(strVal); if (!double.IsNaN(dVal)) { diff --git a/main/SS/Formula/CollaboratingWorkbooksEnvironment.cs b/main/SS/Formula/CollaboratingWorkbooksEnvironment.cs index 2a0ecd66d..1985ca87a 100644 --- a/main/SS/Formula/CollaboratingWorkbooksEnvironment.cs +++ b/main/SS/Formula/CollaboratingWorkbooksEnvironment.cs @@ -85,9 +85,9 @@ public static void SetupFormulaEvaluator(Dictionary e { string wbName = swb.Key; IFormulaEvaluator eval = swb.Value; - if (eval is IWorkbookEvaluatorProvider) + if (eval is IWorkbookEvaluatorProvider provider) { - evaluatorsByName.Add(wbName, ((IWorkbookEvaluatorProvider)eval).GetWorkbookEvaluator()); + evaluatorsByName.Add(wbName, provider.GetWorkbookEvaluator()); } else { diff --git a/main/SS/Formula/Constant/ConstantValueParser.cs b/main/SS/Formula/Constant/ConstantValueParser.cs index 7cb2bd8db..ae3c9b3a3 100644 --- a/main/SS/Formula/Constant/ConstantValueParser.cs +++ b/main/SS/Formula/Constant/ConstantValueParser.cs @@ -141,31 +141,27 @@ private static void EncodeSingleValue(ILittleEndianOutput out1, Object value) out1.WriteLong(0L); return; } - if (value is bool) + if (value is bool bVal) { - bool bVal = ((bool)value); out1.WriteByte(TYPE_BOOLEAN); long longVal = bVal ? 1L : 0L; out1.WriteLong(longVal); return; } - if (value is double) + if (value is double dVal) { - double dVal = (double)value; out1.WriteByte(TYPE_NUMBER); out1.WriteDouble(dVal); return; } - if (value is String) + if (value is String val) { - String val = (String)value; out1.WriteByte(TYPE_STRING); StringUtil.WriteUnicodeString(out1, val); return; } - if (value is ErrorConstant) + if (value is ErrorConstant ecVal) { - ErrorConstant ecVal = (ErrorConstant)value; out1.WriteByte(TYPE_ERROR_CODE); long longVal = ecVal.ErrorCode; out1.WriteLong(longVal); diff --git a/main/SS/Formula/Eval/ConcatEval.cs b/main/SS/Formula/Eval/ConcatEval.cs index 5f60bdc2c..30013910d 100644 --- a/main/SS/Formula/Eval/ConcatEval.cs +++ b/main/SS/Formula/Eval/ConcatEval.cs @@ -54,9 +54,8 @@ public override ValueEval Evaluate(int srcRowIndex, int srcColumnIndex, ValueEva private Object GetText(ValueEval ve) { - if (ve is StringValueEval) + if (ve is StringValueEval sve) { - StringValueEval sve = (StringValueEval)ve; return sve.StringValue; } if (ve == BlankEval.instance) diff --git a/main/SS/Formula/Eval/Forked/ForkedEvaluationWorkbook.cs b/main/SS/Formula/Eval/Forked/ForkedEvaluationWorkbook.cs index 54be7b599..59fdd5898 100644 --- a/main/SS/Formula/Eval/Forked/ForkedEvaluationWorkbook.cs +++ b/main/SS/Formula/Eval/Forked/ForkedEvaluationWorkbook.cs @@ -135,9 +135,8 @@ public ExternalName GetExternalName(String nameName, String sheetName, int exter } public int GetSheetIndex(IEvaluationSheet sheet) { - if (sheet is ForkedEvaluationSheet) + if (sheet is ForkedEvaluationSheet mes) { - ForkedEvaluationSheet mes = (ForkedEvaluationSheet)sheet; return mes.GetSheetIndex(_masterBook); } return _masterBook.GetSheetIndex(sheet); diff --git a/main/SS/Formula/Eval/Forked/ForkedEvaluator.cs b/main/SS/Formula/Eval/Forked/ForkedEvaluator.cs index ac6dfbc38..06436dbaa 100644 --- a/main/SS/Formula/Eval/Forked/ForkedEvaluator.cs +++ b/main/SS/Formula/Eval/Forked/ForkedEvaluator.cs @@ -49,9 +49,9 @@ private ForkedEvaluator(IEvaluationWorkbook masterWorkbook, IStabilityClassifier } private static IEvaluationWorkbook CreateEvaluationWorkbook(IWorkbook wb) { - if (wb is HSSFWorkbook) + if (wb is HSSFWorkbook workbook) { - return HSSFEvaluationWorkbook.Create((HSSFWorkbook)wb); + return HSSFEvaluationWorkbook.Create(workbook); } else { diff --git a/main/SS/Formula/Eval/FunctionEval.cs b/main/SS/Formula/Eval/FunctionEval.cs index 7bad14811..fb5713d6e 100644 --- a/main/SS/Formula/Eval/FunctionEval.cs +++ b/main/SS/Formula/Eval/FunctionEval.cs @@ -504,7 +504,7 @@ public static ReadOnlyCollection GetSupportedFunctionNames() { Function func = functions[i]; FunctionMetadata metaData = FunctionMetadataRegistry.GetFunctionByIndex(i); - if (func != null && !(func is NotImplementedFunction)) + if (func != null && func is not NotImplementedFunction) { lst.Add(metaData.Name); } diff --git a/main/SS/Formula/Eval/IntersectionEval.cs b/main/SS/Formula/Eval/IntersectionEval.cs index 1c05015b0..b51f60a66 100644 --- a/main/SS/Formula/Eval/IntersectionEval.cs +++ b/main/SS/Formula/Eval/IntersectionEval.cs @@ -96,17 +96,17 @@ private static AreaEval ResolveRange(AreaEval aeA, AreaEval aeB) private AreaEval EvaluateRef(ValueEval arg) { - if (arg is AreaEval) + if (arg is AreaEval eval) { - return (AreaEval)arg; + return eval; } - if (arg is RefEval) + if (arg is RefEval refEval) { - return ((RefEval)arg).Offset(0, 0, 0, 0); + return refEval.Offset(0, 0, 0, 0); } - if (arg is ErrorEval) + if (arg is ErrorEval errorEval) { - throw new EvaluationException((ErrorEval)arg); + throw new EvaluationException(errorEval); } throw new ArgumentException("Unexpected ref arg class (" + arg.GetType().Name + ")"); } diff --git a/main/SS/Formula/Eval/NumberEval.cs b/main/SS/Formula/Eval/NumberEval.cs index df7513cc7..c766b7169 100644 --- a/main/SS/Formula/Eval/NumberEval.cs +++ b/main/SS/Formula/Eval/NumberEval.cs @@ -41,13 +41,13 @@ public class NumberEval : NumericValueEval, StringValueEval public NumberEval(Ptg ptg) { - if (ptg is IntPtg) + if (ptg is IntPtg intPtg) { - this._value = ((IntPtg)ptg).Value; + this._value = intPtg.Value; } - else if (ptg is NumberPtg) + else if (ptg is NumberPtg numberPtg) { - this._value = ((NumberPtg)ptg).Value; + this._value = numberPtg.Value; } } diff --git a/main/SS/Formula/Eval/OperandResolver.cs b/main/SS/Formula/Eval/OperandResolver.cs index 992f2dbe1..b12c045ec 100644 --- a/main/SS/Formula/Eval/OperandResolver.cs +++ b/main/SS/Formula/Eval/OperandResolver.cs @@ -58,21 +58,21 @@ private OperandResolver() public static ValueEval GetSingleValue(ValueEval arg, int srcCellRow, int srcCellCol) { ValueEval result; - if (arg is RefEval) + if (arg is RefEval eval) { - result = ChooseSingleElementFromRef((RefEval)arg); + result = ChooseSingleElementFromRef(eval); } - else if (arg is AreaEval) + else if (arg is AreaEval areaEval) { - result = ChooseSingleElementFromArea((AreaEval)arg, srcCellRow, srcCellCol); + result = ChooseSingleElementFromArea(areaEval, srcCellRow, srcCellCol); } else { result = arg; } - if (result is ErrorEval) + if (result is ErrorEval errorEval) { - throw new EvaluationException((ErrorEval)result); + throw new EvaluationException(errorEval); } return result; } @@ -126,9 +126,9 @@ public static ValueEval ChooseSingleElementFromArea(AreaEval ae, { ValueEval result = ChooseSingleElementFromAreaInternal(ae, srcCellRow, srcCellCol); - if (result is ErrorEval) + if (result is ErrorEval eval) { - throw new EvaluationException((ErrorEval)result); + throw new EvaluationException(eval); } return result; @@ -236,14 +236,14 @@ public static double CoerceValueToDouble(ValueEval ev) { return 0.0; } - if (ev is NumericValueEval) + if (ev is NumericValueEval eval) { // this also handles bools - return ((NumericValueEval)ev).NumberValue; + return eval.NumberValue; } - if (ev is StringEval) + if (ev is StringEval stringEval) { - double dd = ParseDouble(((StringEval)ev).StringValue); + double dd = ParseDouble(stringEval.StringValue); if (double.IsNaN(dd)) { throw EvaluationException.InvalidValue(); @@ -324,9 +324,8 @@ public static double ParseDouble(String pText) */ public static String CoerceValueToString(ValueEval ve) { - if (ve is StringValueEval) + if (ve is StringValueEval sve) { - StringValueEval sve = (StringValueEval)ve; return sve.StringValue; } @@ -348,18 +347,18 @@ public static String CoerceValueToString(ValueEval ve) // TODO - remove 've == null' condition once AreaEval is fixed return null; } - if (ve is BoolEval) + if (ve is BoolEval eval) { - return ((BoolEval)ve).BooleanValue; + return eval.BooleanValue; } - if (ve is StringEval) + if (ve is StringEval stringEval) { if (stringsAreBlanks) { return null; } - String str = ((StringEval)ve).StringValue; + String str = stringEval.StringValue; if (str.Equals("true", StringComparison.OrdinalIgnoreCase)) { return true; @@ -372,9 +371,8 @@ public static String CoerceValueToString(ValueEval ve) throw new EvaluationException(ErrorEval.VALUE_INVALID); } - if (ve is NumericValueEval) + if (ve is NumericValueEval ne) { - NumericValueEval ne = (NumericValueEval)ve; double d = ne.NumberValue; if (Double.IsNaN(d)) { @@ -382,9 +380,9 @@ public static String CoerceValueToString(ValueEval ve) } return d != 0; } - if (ve is ErrorEval) + if (ve is ErrorEval errorEval) { - throw new EvaluationException((ErrorEval)ve); + throw new EvaluationException(errorEval); } throw new InvalidOperationException("Unexpected eval (" + ve.GetType().Name + ")"); } diff --git a/main/SS/Formula/Eval/RangeEval.cs b/main/SS/Formula/Eval/RangeEval.cs index 9699307ea..fae16d85a 100644 --- a/main/SS/Formula/Eval/RangeEval.cs +++ b/main/SS/Formula/Eval/RangeEval.cs @@ -62,17 +62,17 @@ private static AreaEval ResolveRange(AreaEval aeA, AreaEval aeB) private static AreaEval EvaluateRef(ValueEval arg) { - if (arg is AreaEval) + if (arg is AreaEval eval) { - return (AreaEval)arg; + return eval; } - if (arg is RefEval) + if (arg is RefEval refEval) { - return ((RefEval)arg).Offset(0, 0, 0, 0); + return refEval.Offset(0, 0, 0, 0); } - if (arg is ErrorEval) + if (arg is ErrorEval errorEval) { - throw new EvaluationException((ErrorEval)arg); + throw new EvaluationException(errorEval); } throw new ArgumentException("Unexpected ref arg class (" + arg.GetType().Name + ")"); } diff --git a/main/SS/Formula/Eval/RefListEval.cs b/main/SS/Formula/Eval/RefListEval.cs index cfe3dec60..a9e2bfeab 100644 --- a/main/SS/Formula/Eval/RefListEval.cs +++ b/main/SS/Formula/Eval/RefListEval.cs @@ -17,8 +17,8 @@ public RefListEval(ValueEval v1, ValueEval v2) private void Add(ValueEval v) { // flatten multiple nested RefListEval - if (v is RefListEval) { - list.AddRange(((RefListEval)v).list); + if (v is RefListEval eval) { + list.AddRange(eval.list); } else { list.Add(v); diff --git a/main/SS/Formula/Eval/RelationalOperationEval/RelationalOperationEval.cs b/main/SS/Formula/Eval/RelationalOperationEval/RelationalOperationEval.cs index 5fc3a3d38..6ce1ed892 100644 --- a/main/SS/Formula/Eval/RelationalOperationEval/RelationalOperationEval.cs +++ b/main/SS/Formula/Eval/RelationalOperationEval/RelationalOperationEval.cs @@ -49,12 +49,10 @@ private static int DoCompare(ValueEval va, ValueEval vb) return -CompareBlank(va); } - if (va is BoolEval) + if (va is BoolEval bA) { - if (vb is BoolEval) + if (vb is BoolEval bB) { - BoolEval bA = (BoolEval)va; - BoolEval bB = (BoolEval)vb; if (bA.BooleanValue == bB.BooleanValue) { return 0; @@ -67,12 +65,10 @@ private static int DoCompare(ValueEval va, ValueEval vb) { return -1; } - if (va is StringEval) + if (va is StringEval sA) { - if (vb is StringEval) + if (vb is StringEval sB) { - StringEval sA = (StringEval)va; - StringEval sB = (StringEval)vb; return string.Compare(sA.StringValue, sB.StringValue, StringComparison.OrdinalIgnoreCase); } return 1; @@ -81,12 +77,10 @@ private static int DoCompare(ValueEval va, ValueEval vb) { return -1; } - if (va is NumberEval) + if (va is NumberEval nA) { - if (vb is NumberEval) + if (vb is NumberEval nB) { - NumberEval nA = (NumberEval)va; - NumberEval nB = (NumberEval)vb; if (nA.NumberValue == nB.NumberValue) { // Excel considers -0.0 == 0.0 which is different to Double.compare() @@ -104,20 +98,17 @@ private static int CompareBlank(ValueEval v) { return 0; } - if (v is BoolEval) + if (v is BoolEval boolEval) { - BoolEval boolEval = (BoolEval)v; return boolEval.BooleanValue ? -1 : 0; } - if (v is NumberEval) + if (v is NumberEval ne) { - NumberEval ne = (NumberEval)v; //return ne.NumberValue.CompareTo(0.0); return NumberComparer.Compare(0.0, ne.NumberValue); } - if (v is StringEval) + if (v is StringEval se) { - StringEval se = (StringEval)v; return se.StringValue.Length < 1 ? 0 : -1; } throw new ArgumentException("bad value class (" + v.GetType().Name + ")"); @@ -148,17 +139,15 @@ public ValueEval EvaluateArray(ValueEval[] args, int srcRowIndex, int srcColumnI int w1, w2, h1, h2; int a1FirstCol = 0, a1FirstRow = 0; - if (arg0 is AreaEval) + if (arg0 is AreaEval eval) { - AreaEval ae = (AreaEval)arg0; - w1 = ae.Width; - h1 = ae.Height; - a1FirstCol = ae.FirstColumn; - a1FirstRow = ae.FirstRow; + w1 = eval.Width; + h1 = eval.Height; + a1FirstCol = eval.FirstColumn; + a1FirstRow = eval.FirstRow; } - else if (arg0 is RefEval) + else if (arg0 is RefEval ref1) { - RefEval ref1 = (RefEval)arg0; w1 = 1; h1 = 1; a1FirstCol = ref1.Column; @@ -170,17 +159,15 @@ public ValueEval EvaluateArray(ValueEval[] args, int srcRowIndex, int srcColumnI h1 = 1; } int a2FirstCol = 0, a2FirstRow = 0; - if (arg1 is AreaEval) + if (arg1 is AreaEval ae) { - AreaEval ae = (AreaEval)arg1; w2 = ae.Width; h2 = ae.Height; a2FirstCol = ae.FirstColumn; a2FirstRow = ae.FirstRow; } - else if (arg1 is RefEval) + else if (arg1 is RefEval ref1) { - RefEval ref1 = (RefEval)arg1; w2 = 1; h2 = 1; a2FirstCol = ref1.Column; diff --git a/main/SS/Formula/Eval/TwoOperandNumeric/TwoOperandNumericOperation.cs b/main/SS/Formula/Eval/TwoOperandNumeric/TwoOperandNumericOperation.cs index 590084c18..f1d7e58e6 100644 --- a/main/SS/Formula/Eval/TwoOperandNumeric/TwoOperandNumericOperation.cs +++ b/main/SS/Formula/Eval/TwoOperandNumeric/TwoOperandNumericOperation.cs @@ -32,7 +32,7 @@ public override ValueEval Evaluate(int srcRowIndex, int srcColumnIndex, ValueEva if (result == 0.0) { // this '==' matches +0.0 and -0.0 // Excel Converts -0.0 to +0.0 for '*', '/', '%', '+' and '^' - if (!(this is SubtractEval)) + if (this is not SS.Formula.Eval.SubtractEval) { return NumberEval.ZERO; } diff --git a/main/SS/Formula/EvaluationConditionalFormatRule.cs b/main/SS/Formula/EvaluationConditionalFormatRule.cs index 3b6da6aac..e96494e0f 100644 --- a/main/SS/Formula/EvaluationConditionalFormatRule.cs +++ b/main/SS/Formula/EvaluationConditionalFormatRule.cs @@ -31,18 +31,18 @@ public static bool IsValid(OperatorEnum @operator, object cellValue, object v1, case OperatorEnum.NO_COMPARISON: return false; case OperatorEnum.BETWEEN: - if (cellValue is Double) + if (cellValue is Double value) { // use zero for null double n1 = v1==null? 0:(double)v1; double n2 = v2 == null ? 0 : (double)v2; - return (double)cellValue - n1 >= 0 && (double)cellValue - n2 <= 0; + return value - n1 >= 0 && value - n2 <= 0; } - else if (cellValue is String) + else if (cellValue is String betweeenString) { String n1 = v1 == null ? "" : (String)v1; String n2 = v2 == null ? "" : (String)v2; - return string.Compare((String)cellValue, n1, true) >= 0 && string.Compare((String)cellValue, n2, true) <= 0; + return string.Compare(betweeenString, n1, true) >= 0 && string.Compare(betweeenString, n2, true) <= 0; } else if (cellValue is Boolean) return false; @@ -50,115 +50,115 @@ public static bool IsValid(OperatorEnum @operator, object cellValue, object v1, case OperatorEnum.EQUAL: if (v1 == null) return false; - if (cellValue is Double) + if (cellValue is Double d) { - return (double)cellValue >= 0; + return d >= 0; } - else if (cellValue is String) + else if (cellValue is String equalString) { - return string.Compare((String)cellValue, (String)v1, true) == 0; + return string.Compare(equalString, (String)v1, true) == 0; } - else if (cellValue is Boolean) + else if (cellValue is Boolean b) { bool n1 = (bool)v1; - return (bool)cellValue==n1; + return b==n1; } return false; case OperatorEnum.NOT_EQUAL: if (v1 == null) return true; - if (cellValue is String) + if (cellValue is String s) { String n1 = (String)v1; - return string.Compare((String)cellValue, n1, true) != 0; + return string.Compare(s, n1, true) != 0; } - else if (cellValue is Boolean) + else if (cellValue is Boolean b) { bool n1 = (bool)v1; - return (bool)cellValue != n1; + return b != n1; } return false; case OperatorEnum.GREATER_THAN: - if (cellValue is Double) + if (cellValue is Double value1) { // use zero for null double n1 = v1 == null ? 0 : (double)v1; - return (double)cellValue> n1; + return value1> n1; } - else if (cellValue is String) + else if (cellValue is String greaterThanString) { String n1 = v1 == null ? "" : (String)v1; - return string.Compare((String)cellValue, n1, true) > 0; + return string.Compare(greaterThanString, n1, true) > 0; } - else if (cellValue is Boolean) + else if (cellValue is Boolean b) { if (v1 == null) return true; bool n1 = (bool)v1; - return ((bool)cellValue).CompareTo(n1)>0; + return b.CompareTo(n1)>0; } return false; case OperatorEnum.LESS_THAN: - if (cellValue is Double) + if (cellValue is Double cellValue1) { // use zero for null double n1 = v1 == null ? 0 : (double)v1; - return (double)cellValue= n1; + return d1 >= n1; } - else if (cellValue is String) + else if (cellValue is String s1) { if (v1 == null) return true; - return string.Compare((String)cellValue, (String)v1, true) >= 0; + return string.Compare(s1, (String)v1, true) >= 0; } - else if (cellValue is Boolean) + else if (cellValue is Boolean b) { if (v1 == null) return false; bool n1 = (bool)v1; - return ((bool)cellValue).CompareTo(n1) >= 0; + return b.CompareTo(n1) >= 0; } return false; case OperatorEnum.LESS_OR_EQUAL: - if (cellValue is Double) + if (cellValue is Double value2) { // use zero for null double n1 = v1 == null ? 0 : (double)v1; - return (double)cellValue <= n1; + return value2 <= n1; } - else if (cellValue is String) + else if (cellValue is String s1) { if (v1 == null) return false; - return string.Compare((String)cellValue, (String)v1, true) <= 0; + return string.Compare(s1, (String)v1, true) <= 0; } - else if (cellValue is Boolean) + else if (cellValue is Boolean b) { if (v1 == null) return false; bool n1 = (bool)v1; - return ((bool)cellValue).CompareTo(n1) <= 0; + return b.CompareTo(n1) <= 0; } return false; } @@ -240,14 +240,14 @@ public override String ToString() public override bool Equals(Object obj) { - if (!(obj is ValueAndFormat)) + if (obj is not ValueAndFormat andFormat) { return false; } - ValueAndFormat o = (ValueAndFormat)obj; - return (value == o.value || value.Equals(o.value)) - && (format == o.format || format.Equals(o.format)) - && (str == o.str || str.Equals(o.str)); + + return (value == andFormat.value || value.Equals(andFormat.value)) + && (format == andFormat.format || format.Equals(andFormat.format)) + && (str == andFormat.str || str.Equals(andFormat.str)); } /** @@ -423,8 +423,7 @@ private ValueEval UnwrapEval(ValueEval eval) { ValueEval comp = eval; - while (comp is RefEval) { - RefEval reference = (RefEval)comp; + while (comp is RefEval reference) { comp = reference.GetInnerValueEval(reference.FirstSheetIndex); } return comp; @@ -482,13 +481,13 @@ private bool CheckFormula(CellReference reference, CellRangeAddress region) if (comp is ErrorEval) { return false; } - if (comp is BoolEval) { - return ((BoolEval)comp).BooleanValue; + if (comp is BoolEval eval) { + return eval.BooleanValue; } // empirically tested in Excel - 0=false, any other number = true/valid // see test file DataValidationEvaluations.xlsx - if (comp is NumberEval) { - return ((NumberEval)comp).NumberValue != 0; + if (comp is NumberEval numberEval) { + return numberEval.NumberValue != 0; } return false; // anything else is false, such as text } diff --git a/main/SS/Formula/FormulaParser.cs b/main/SS/Formula/FormulaParser.cs index b478e8c60..69ed4e6ae 100644 --- a/main/SS/Formula/FormulaParser.cs +++ b/main/SS/Formula/FormulaParser.cs @@ -156,7 +156,7 @@ public static Ptg[] Parse(String formula, IFormulaParsingWorkbook workbook, Form public static Area3DPxg ParseStructuredReference(String tableText, IFormulaParsingWorkbook workbook, int rowIndex) { Ptg[] arr = FormulaParser.Parse(tableText, workbook, 0, 0, rowIndex); - if (arr.Length != 1 || !(arr[0] is Area3DPxg) ) { + if (arr.Length != 1 || arr[0] is not Area3DPxg ) { throw new InvalidOperationException("Illegal structured reference"); } return (Area3DPxg)arr[0]; @@ -445,9 +445,8 @@ private bool IsValidRangeOperand(ParseNode a) } // next 2 are special cases of OperationPtg - if (tkn is AbstractFunctionPtg) + if (tkn is AbstractFunctionPtg afp) { - AbstractFunctionPtg afp = (AbstractFunctionPtg)tkn; byte returnClass = afp.DefaultOperandClass; return Ptg.CLASS_REF == returnClass; } @@ -1283,23 +1282,20 @@ private SimpleRangePart ParseSimpleRangePart() */ private static Ptg ReduceRangeExpression(Ptg ptgA, Ptg ptgB) { - if (!(ptgB is RefPtg)) + if (ptgB is not RefPtg refB) { // only when second ref is simple 2-D ref can the range // expression be converted To an area ref return null; } - RefPtg refB = (RefPtg)ptgB; - if (ptgA is RefPtg) + if (ptgA is RefPtg a) { - RefPtg refA = (RefPtg)ptgA; - return new AreaPtg(refA.Row, refB.Row, refA.Column, refB.Column, - refA.IsRowRelative, refB.IsRowRelative, refA.IsColRelative, refB.IsColRelative); + return new AreaPtg(a.Row, refB.Row, a.Column, refB.Column, + a.IsRowRelative, refB.IsRowRelative, a.IsColRelative, refB.IsColRelative); } - if (ptgA is Ref3DPtg) + if (ptgA is Ref3DPtg refA) { - Ref3DPtg refA = (Ref3DPtg)ptgA; return new Area3DPtg(refA.Row, refB.Row, refA.Column, refB.Column, refA.IsRowRelative, refB.IsRowRelative, refA.IsColRelative, refB.IsColRelative, refA.ExternSheetIndex); @@ -1921,22 +1917,22 @@ private ParseNode ParseUnary(bool isPlus) // + or - directly next to a number is parsed with the number Ptg token = factor.GetToken(); - if (token is NumberPtg) + if (token is NumberPtg ptg) { if (isPlus) { return factor; } - token = new NumberPtg(-((NumberPtg)token).Value); + token = new NumberPtg(-ptg.Value); return new ParseNode(token); } - if (token is IntPtg) + if (token is IntPtg intPtg) { if (isPlus) { return factor; } - int intVal = ((IntPtg)token).Value; + int intVal = intPtg.Value; // note - cannot use IntPtg for negatives token = new NumberPtg(-intVal); return new ParseNode(token); @@ -2048,13 +2044,13 @@ private Boolean ParseBooleanLiteral() private static Double ConvertArrayNumber(Ptg ptg, bool isPositive) { double value; - if (ptg is IntPtg) + if (ptg is IntPtg intPtg) { - value = ((IntPtg)ptg).Value; + value = intPtg.Value; } - else if (ptg is NumberPtg) + else if (ptg is NumberPtg numberPtg) { - value = ((NumberPtg)ptg).Value; + value = numberPtg.Value; } else { diff --git a/main/SS/Formula/FormulaRenderer.cs b/main/SS/Formula/FormulaRenderer.cs index 2c3d66a72..832868bda 100644 --- a/main/SS/Formula/FormulaRenderer.cs +++ b/main/SS/Formula/FormulaRenderer.cs @@ -66,9 +66,8 @@ public static String ToFormulaString(IFormulaRenderingWorkbook book, Ptg[] ptgs) stack.Push("(" + contents + ")"); continue; } - if (ptg is AttrPtg) + if (ptg is AttrPtg attrPtg) { - AttrPtg attrPtg = ((AttrPtg)ptg); if (attrPtg.IsOptimizedIf || attrPtg.IsOptimizedChoose || attrPtg.IsSkip) { continue; @@ -95,21 +94,19 @@ public static String ToFormulaString(IFormulaRenderingWorkbook book, Ptg[] ptgs) throw new Exception("Unexpected tAttr: " + attrPtg.ToString()); } - if (ptg is WorkbookDependentFormula) + if (ptg is WorkbookDependentFormula optg) { - WorkbookDependentFormula optg = (WorkbookDependentFormula)ptg; stack.Push(optg.ToFormulaString(book)); continue; } - if (!(ptg is OperationPtg)) + if (ptg is not OperationPtg operationPtg) { stack.Push(ptg.ToFormulaString()); continue; } - OperationPtg o = (OperationPtg)ptg; - String[] operands1 = GetOperands(stack, o.NumberOfOperands); - stack.Push(o.ToFormulaString(operands1)); + String[] operands1 = GetOperands(stack, operationPtg.NumberOfOperands); + stack.Push(operationPtg.ToFormulaString(operands1)); } if (stack.Count == 0) { diff --git a/main/SS/Formula/Functions/Areas.cs b/main/SS/Formula/Functions/Areas.cs index 757ea9a21..0b98684f2 100644 --- a/main/SS/Formula/Functions/Areas.cs +++ b/main/SS/Formula/Functions/Areas.cs @@ -18,8 +18,7 @@ public ValueEval Evaluate(ValueEval[] args, int srcRowIndex, int srcColumnIndex) { ValueEval valueEval = args[0]; int result = 1; - if (valueEval is RefListEval) { - RefListEval refListEval = (RefListEval)valueEval; + if (valueEval is RefListEval refListEval) { result = refListEval.GetList().Count; } NumberEval numberEval = new NumberEval(new NumberPtg(result)); diff --git a/main/SS/Formula/Functions/Averageifs.cs b/main/SS/Formula/Functions/Averageifs.cs index 05536c204..1c859e50e 100644 --- a/main/SS/Formula/Functions/Averageifs.cs +++ b/main/SS/Formula/Functions/Averageifs.cs @@ -147,9 +147,9 @@ private static double GetAvgFromMatchingCells(AreaEval[] ranges, IMatchPredicate { ValueEval addend = aeSum.GetRelativeValue(relRowIndex, relColIndex); - if (addend is NumberEval) + if (addend is NumberEval eval) { - return ((NumberEval)addend).NumberValue; + return eval.NumberValue; } // everything else (including string and boolean values) dont count return null; @@ -157,13 +157,13 @@ private static double GetAvgFromMatchingCells(AreaEval[] ranges, IMatchPredicate private static AreaEval ConvertRangeArg(ValueEval eval) { - if (eval is AreaEval) + if (eval is AreaEval areaEval) { - return (AreaEval)eval; + return areaEval; } - if (eval is RefEval) + if (eval is RefEval refEval) { - return ((RefEval)eval).Offset(0, 0, 0, 0); + return refEval.Offset(0, 0, 0, 0); } throw new EvaluationException(ErrorEval.VALUE_INVALID); } diff --git a/main/SS/Formula/Functions/Baseifs.cs b/main/SS/Formula/Functions/Baseifs.cs index 6739cff63..cd9b839e7 100644 --- a/main/SS/Formula/Functions/Baseifs.cs +++ b/main/SS/Formula/Functions/Baseifs.cs @@ -125,10 +125,10 @@ protected internal static void ValidateCriteria(IMatchPredicate[] criteria) foreach(IMatchPredicate predicate in criteria) { // check for errors in predicate and return immediately using this error code - if(predicate is Countif.ErrorMatcher) + if(predicate is Countif.ErrorMatcher matcher) { throw new EvaluationException( - ErrorEval.ValueOf(((NPOI.SS.Formula.Functions.Countif.ErrorMatcher) predicate).Value)); + ErrorEval.ValueOf(matcher.Value)); } } } @@ -168,9 +168,9 @@ protected static ValueEval AggregateMatchingCells(IAggregator aggregator, AreaEv if(sumRange != null) { ValueEval value = sumRange.GetRelativeValue(r, c); - if(value is ErrorEval) + if(value is ErrorEval eval) { - throw new EvaluationException((ErrorEval) value); + throw new EvaluationException(eval); } aggregator.AddValue(value); } @@ -188,13 +188,13 @@ protected static ValueEval AggregateMatchingCells(IAggregator aggregator, AreaEv protected internal static AreaEval ConvertRangeArg(ValueEval eval) { - if(eval is AreaEval) + if(eval is AreaEval areaEval) { - return (AreaEval) eval; + return areaEval; } - if(eval is RefEval) + if(eval is RefEval refEval) { - return ((RefEval) eval).Offset(0, 0, 0, 0); + return refEval.Offset(0, 0, 0, 0); } throw new EvaluationException(ErrorEval.VALUE_INVALID); } diff --git a/main/SS/Formula/Functions/Bin2Dec.cs b/main/SS/Formula/Functions/Bin2Dec.cs index ce1089ecf..e449abe8c 100644 --- a/main/SS/Formula/Functions/Bin2Dec.cs +++ b/main/SS/Formula/Functions/Bin2Dec.cs @@ -50,9 +50,8 @@ public class Bin2Dec : Fixed1ArgFunction, FreeRefFunction public override ValueEval Evaluate(int srcRowIndex, int srcColumnIndex, ValueEval numberVE) { String number; - if (numberVE is RefEval) + if (numberVE is RefEval re) { - RefEval re = (RefEval)numberVE; number = OperandResolver.CoerceValueToString(re.GetInnerValueEval(re.FirstSheetIndex)); } else diff --git a/main/SS/Formula/Functions/Boolean/BooleanFunction.cs b/main/SS/Formula/Functions/Boolean/BooleanFunction.cs index 41d76d4cd..18956cd7d 100644 --- a/main/SS/Formula/Functions/Boolean/BooleanFunction.cs +++ b/main/SS/Formula/Functions/Boolean/BooleanFunction.cs @@ -51,9 +51,8 @@ private bool Calculate(ValueEval[] args) foreach (ValueEval arg in args) { bool? tempVe; - if (arg is TwoDEval) + if (arg is TwoDEval ae) { - TwoDEval ae = (TwoDEval)arg; int height = ae.Height; int width = ae.Width; for (int rrIx = 0; rrIx < height; rrIx++) @@ -72,9 +71,8 @@ private bool Calculate(ValueEval[] args) continue; } - if (arg is RefEval) + if (arg is RefEval re) { - RefEval re = (RefEval)arg; int firstSheetIndex = re.FirstSheetIndex; int lastSheetIndex = re.LastSheetIndex; for (int sIx = firstSheetIndex; sIx <= lastSheetIndex; sIx++) diff --git a/main/SS/Formula/Functions/Cell.cs b/main/SS/Formula/Functions/Cell.cs index 3e1b85691..4fc576c44 100644 --- a/main/SS/Formula/Functions/Cell.cs +++ b/main/SS/Formula/Functions/Cell.cs @@ -23,13 +23,13 @@ public ValueEval Evaluate(int srcRowIndex, int srcColumnIndex, ValueEval arg0, V if(string.Equals(s0, "col", System.StringComparison.InvariantCultureIgnoreCase)) { // "col" - if(arg1 is AreaEval) + if(arg1 is AreaEval eval) { - rnum = ((AreaEval) arg1).FirstColumn; + rnum = eval.FirstColumn; } - else if(arg1 is RefEval) + else if(arg1 is RefEval refEval) { - rnum = ((RefEval) arg1).Column; + rnum = refEval.Column; } else { @@ -40,13 +40,13 @@ public ValueEval Evaluate(int srcRowIndex, int srcColumnIndex, ValueEval arg0, V else if(string.Equals(s0, "row", System.StringComparison.InvariantCultureIgnoreCase)) { // "row" - if(arg1 is AreaEval) + if(arg1 is AreaEval eval) { - rnum = ((AreaEval) arg1).FirstRow; + rnum = eval.FirstRow; } - else if(arg1 is RefEval) + else if(arg1 is RefEval refEval) { - rnum = ((RefEval) arg1).Row; + rnum = refEval.Row; } else { diff --git a/main/SS/Formula/Functions/Column.cs b/main/SS/Formula/Functions/Column.cs index c5a560d35..3416f71f0 100644 --- a/main/SS/Formula/Functions/Column.cs +++ b/main/SS/Formula/Functions/Column.cs @@ -32,13 +32,13 @@ public ValueEval Evaluate(int srcRowIndex, int srcColumnIndex, ValueEval arg0) { int rnum; - if (arg0 is AreaEval) + if (arg0 is AreaEval eval) { - rnum = ((AreaEval)arg0).FirstColumn; + rnum = eval.FirstColumn; } - else if (arg0 is RefEval) + else if (arg0 is RefEval refEval) { - rnum = ((RefEval)arg0).Column; + rnum = refEval.Column; } else { diff --git a/main/SS/Formula/Functions/Columns.cs b/main/SS/Formula/Functions/Columns.cs index 068cc7b3e..33a42bed3 100644 --- a/main/SS/Formula/Functions/Columns.cs +++ b/main/SS/Formula/Functions/Columns.cs @@ -31,9 +31,9 @@ public override ValueEval Evaluate(int srcRowIndex, int srcColumnIndex, ValueEva { int result; - if (arg0 is AreaEval) + if (arg0 is AreaEval eval) { - result = ((AreaEval)arg0).Width; + result = eval.Width; } else if (arg0 is RefEval) { diff --git a/main/SS/Formula/Functions/CountUtils.cs b/main/SS/Formula/Functions/CountUtils.cs index 6c8db0469..5c4bb6bb5 100644 --- a/main/SS/Formula/Functions/CountUtils.cs +++ b/main/SS/Formula/Functions/CountUtils.cs @@ -67,17 +67,17 @@ public static int CountArg(ValueEval eval, IMatchPredicate criteriaPredicate) { throw new ArgumentException("eval must not be null"); } - if (eval is ThreeDEval) + if (eval is ThreeDEval dEval) { - return CountUtils.CountMatchingCellsInArea((ThreeDEval)eval, criteriaPredicate); + return CountUtils.CountMatchingCellsInArea(dEval, criteriaPredicate); } if (eval is TwoDEval) { throw new ArgumentException("Count requires 3D Evals, 2D ones aren't supported"); } - if (eval is RefEval) + if (eval is RefEval refEval) { - return CountUtils.CountMatchingCellsInRef((RefEval)eval, criteriaPredicate); + return CountUtils.CountMatchingCellsInRef(refEval, criteriaPredicate); } return criteriaPredicate.Matches(eval) ? 1 : 0; } @@ -99,9 +99,8 @@ public static int CountMatchingCellsInArea(ThreeDEval areaEval, IMatchPredicate { ValueEval ve = areaEval.GetValue(sIx, rrIx, rcIx); - if (criteriaPredicate is I_MatchAreaPredicate) + if (criteriaPredicate is I_MatchAreaPredicate areaPredicate) { - I_MatchAreaPredicate areaPredicate = (I_MatchAreaPredicate)criteriaPredicate; if (!areaPredicate.Matches(areaEval, rrIx, rcIx)) continue; } diff --git a/main/SS/Formula/Functions/Countblank.cs b/main/SS/Formula/Functions/Countblank.cs index ac8a4e0c2..f8dd30502 100644 --- a/main/SS/Formula/Functions/Countblank.cs +++ b/main/SS/Formula/Functions/Countblank.cs @@ -37,13 +37,13 @@ public override ValueEval Evaluate(int srcRowIndex, int srcColumnIndex, ValueEva { double result; - if (arg0 is RefEval) + if (arg0 is RefEval eval) { - result = CountUtils.CountMatchingCellsInRef((RefEval)arg0, predicate); + result = CountUtils.CountMatchingCellsInRef(eval, predicate); } - else if (arg0 is ThreeDEval) + else if (arg0 is ThreeDEval dEval) { - result = CountUtils.CountMatchingCellsInArea((ThreeDEval)arg0, predicate); + result = CountUtils.CountMatchingCellsInArea(dEval, predicate); } else { @@ -62,7 +62,7 @@ public bool Matches(ValueEval valueEval) return valueEval == BlankEval.instance || // see https://support.office.com/en-us/article/COUNTBLANK-function-6a92d772-675c-4bee-b346-24af6bd3ac22 // "Cells with formulas that return "" (empty text) are also counted." - (valueEval is StringEval && "".Equals(((StringEval)valueEval).StringValue)); + (valueEval is StringEval eval && "".Equals(eval.StringValue)); } #endregion diff --git a/main/SS/Formula/Functions/Countif.cs b/main/SS/Formula/Functions/Countif.cs index 35bdac850..4a6a5a125 100644 --- a/main/SS/Formula/Functions/Countif.cs +++ b/main/SS/Formula/Functions/Countif.cs @@ -231,9 +231,9 @@ protected override String ValueText public override bool Matches(ValueEval x) { - if(x is ErrorEval) + if(x is ErrorEval eval) { - int testValue = ((ErrorEval)x).ErrorCode; + int testValue = eval.ErrorCode; return Evaluate(testValue - _value); } return false; @@ -261,7 +261,7 @@ public NumberMatcher(double value, CmpOp optr) public override bool Matches(ValueEval x) { double testValue; - if(x is StringEval) + if(x is StringEval se) { // if the target(x) is a string, but parses as a number // it may still count as a match, only for the equality operator @@ -279,7 +279,7 @@ public override bool Matches(ValueEval x) // for example '>5' does not match '6', return false; } - StringEval se = (StringEval)x; + Double val = OperandResolver.ParseDouble(se.StringValue); if(double.IsNaN(val)) { @@ -288,9 +288,8 @@ public override bool Matches(ValueEval x) } return _value == val; } - else if((x is NumberEval)) + else if((x is NumberEval ne)) { - NumberEval ne = (NumberEval)x; testValue = ne.NumberValue; } else if((x is BlankEval)) @@ -350,9 +349,8 @@ public override bool Matches(ValueEval x) // } // testValue = boolToInt(val.booleanValue()); } - else if(x is BoolEval) + else if(x is BoolEval be) { - BoolEval be = (BoolEval)x; testValue = BoolToInt(be.BooleanValue); } else if((x is BlankEval)) @@ -430,7 +428,7 @@ public override bool Matches(ValueEval x) // no other criteria matches a blank cell return false; } - if(!(x is StringEval)) + if(x is not StringEval eval) { if(_operator.Code==CmpOp.NE) return true; @@ -439,7 +437,7 @@ public override bool Matches(ValueEval x) // e.g. '4*7', NumberEval(4567) does not match return false; } - String testedValue = ((StringEval)x).StringValue; + String testedValue = eval.StringValue; if((testedValue.Length < 1 && _value.Length < 1)) { // odd case: criteria '=' behaves differently to criteria '' @@ -547,13 +545,13 @@ protected override string ValueText */ private double CountMatchingCellsInArea(ValueEval rangeArg, IMatchPredicate criteriaPredicate) { - if(rangeArg is RefEval) + if(rangeArg is RefEval arg) { - return CountUtils.CountMatchingCellsInRef((RefEval) rangeArg, criteriaPredicate); + return CountUtils.CountMatchingCellsInRef(arg, criteriaPredicate); } - else if(rangeArg is ThreeDEval) + else if(rangeArg is ThreeDEval eval) { - return CountUtils.CountMatchingCellsInArea((ThreeDEval) rangeArg, criteriaPredicate); + return CountUtils.CountMatchingCellsInArea(eval, criteriaPredicate); } else { @@ -615,22 +613,22 @@ public static IMatchPredicate CreateCriteriaPredicate(ValueEval arg, int srcRowI ValueEval evaluatedCriteriaArg = EvaluateCriteriaArg(arg, srcRowIndex, srcColumnIndex); - if(evaluatedCriteriaArg is NumberEval) + if(evaluatedCriteriaArg is NumberEval eval) { - return new NumberMatcher(((NumberEval) evaluatedCriteriaArg).NumberValue, CmpOp.OP_NONE); + return new NumberMatcher(eval.NumberValue, CmpOp.OP_NONE); } - if(evaluatedCriteriaArg is BoolEval) + if(evaluatedCriteriaArg is BoolEval boolEval) { - return new BooleanMatcher(((BoolEval) evaluatedCriteriaArg).BooleanValue, CmpOp.OP_NONE); + return new BooleanMatcher(boolEval.BooleanValue, CmpOp.OP_NONE); } - if(evaluatedCriteriaArg is StringEval) + if(evaluatedCriteriaArg is StringEval stringEval) { - return CreateGeneralMatchPredicate((StringEval) evaluatedCriteriaArg); + return CreateGeneralMatchPredicate(stringEval); } - if(evaluatedCriteriaArg is ErrorEval) + if(evaluatedCriteriaArg is ErrorEval errorEval) { - return new ErrorMatcher(((ErrorEval) evaluatedCriteriaArg).ErrorCode, CmpOp.OP_NONE); + return new ErrorMatcher(errorEval.ErrorCode, CmpOp.OP_NONE); } if(evaluatedCriteriaArg == BlankEval.instance) { diff --git a/main/SS/Formula/Functions/DAverage.cs b/main/SS/Formula/Functions/DAverage.cs index 4756cf10f..ab8abf513 100644 --- a/main/SS/Formula/Functions/DAverage.cs +++ b/main/SS/Formula/Functions/DAverage.cs @@ -31,10 +31,10 @@ public sealed class DAverage : IDStarAlgorithm private double total; public bool ProcessMatch(ValueEval eval) { - if(eval is NumericValueEval) + if(eval is NumericValueEval valueEval) { count++; - total += ((NumericValueEval) eval).NumberValue; + total += valueEval.NumberValue; } return true; } diff --git a/main/SS/Formula/Functions/DCountA.cs b/main/SS/Formula/Functions/DCountA.cs index ca777d42b..86e08a9ad 100644 --- a/main/SS/Formula/Functions/DCountA.cs +++ b/main/SS/Formula/Functions/DCountA.cs @@ -35,7 +35,7 @@ public sealed class DCountA : IDStarAlgorithm private long count; public bool ProcessMatch(ValueEval eval) { - if(!(eval is BlankEval)) + if(eval is not BlankEval) { count++; } diff --git a/main/SS/Formula/Functions/DGet.cs b/main/SS/Formula/Functions/DGet.cs index dea3e25d2..93aaac338 100644 --- a/main/SS/Formula/Functions/DGet.cs +++ b/main/SS/Formula/Functions/DGet.cs @@ -46,7 +46,7 @@ public bool ProcessMatch(ValueEval eval) else { // We have a previous filled result. - if(!(eval is BlankEval)) + if(eval is not BlankEval) { result = ErrorEval.NUM_ERROR; return false; diff --git a/main/SS/Formula/Functions/DMax.cs b/main/SS/Formula/Functions/DMax.cs index 88931bd09..4c8cb7fa2 100644 --- a/main/SS/Formula/Functions/DMax.cs +++ b/main/SS/Formula/Functions/DMax.cs @@ -44,19 +44,19 @@ public sealed class DMax : IDStarAlgorithm private ValueEval maximumValue; public bool ProcessMatch(ValueEval eval) { - if(eval is NumericValueEval) + if(eval is NumericValueEval valueEval) { if(maximumValue == null) { // First match, just Set the value. - maximumValue = eval; + maximumValue = valueEval; } else { // There was a previous match, find the new minimum. - double currentValue = ((NumericValueEval)eval).NumberValue; + double currentValue = valueEval.NumberValue; double oldValue = ((NumericValueEval)maximumValue).NumberValue; if(currentValue > oldValue) { - maximumValue = eval; + maximumValue = valueEval; } } } diff --git a/main/SS/Formula/Functions/DMin.cs b/main/SS/Formula/Functions/DMin.cs index 6083d525a..8f7b3a60a 100644 --- a/main/SS/Formula/Functions/DMin.cs +++ b/main/SS/Formula/Functions/DMin.cs @@ -33,19 +33,19 @@ public class DMin : IDStarAlgorithm public bool ProcessMatch(ValueEval eval) { - if (eval is NumericValueEval) + if (eval is NumericValueEval valueEval) { if (minimumValue == null) { // First match, just Set the value. - minimumValue = eval; + minimumValue = valueEval; } else { // There was a previous match, find the new minimum. - double currentValue = ((NumericValueEval)eval).NumberValue; + double currentValue = valueEval.NumberValue; double oldValue = ((NumericValueEval)minimumValue).NumberValue; if (currentValue < oldValue) { - minimumValue = eval; + minimumValue = valueEval; } } } diff --git a/main/SS/Formula/Functions/DProduct.cs b/main/SS/Formula/Functions/DProduct.cs index c471c4e4f..da053af4a 100644 --- a/main/SS/Formula/Functions/DProduct.cs +++ b/main/SS/Formula/Functions/DProduct.cs @@ -36,15 +36,15 @@ public sealed class DProduct : IDStarAlgorithm private bool initDone = false; public bool ProcessMatch(ValueEval eval) { - if(eval is NumericValueEval) + if(eval is NumericValueEval valueEval) { if(initDone) { - product *= ((NumericValueEval) eval).NumberValue; + product *= valueEval.NumberValue; } else { - product = ((NumericValueEval) eval).NumberValue; + product = valueEval.NumberValue; initDone = true; } } diff --git a/main/SS/Formula/Functions/DStarRunner.cs b/main/SS/Formula/Functions/DStarRunner.cs index 84d0d0cab..95ca6b99a 100644 --- a/main/SS/Formula/Functions/DStarRunner.cs +++ b/main/SS/Formula/Functions/DStarRunner.cs @@ -71,12 +71,10 @@ public ValueEval Evaluate(int srcRowIndex, int srcColumnIndex, ValueEval database, ValueEval filterColumn, ValueEval conditionDatabase) { // Input Processing and error Checks. - if (!(database is AreaEval) || !(conditionDatabase is AreaEval)) + if (database is not AreaEval db || conditionDatabase is not AreaEval cdb) { return ErrorEval.VALUE_INVALID; } - AreaEval db = (AreaEval)database; - AreaEval cdb = (AreaEval)conditionDatabase; // Create an algorithm runner. IDStarAlgorithm algorithm = null; @@ -134,10 +132,10 @@ public ValueEval Evaluate(int srcRowIndex, int srcColumnIndex, int fc; try { - if(filterColumn is NumericValueEval) + if(filterColumn is NumericValueEval eval) { //fc is zero based while Excel uses 1 based column numbering - fc = (int) Math.Round(((NumericValueEval) filterColumn).NumberValue) - 1; + fc = (int) Math.Round(eval.NumberValue) - 1; } else fc = GetColumnForName(filterColumn, db); @@ -170,7 +168,7 @@ public ValueEval Evaluate(int srcRowIndex, int srcColumnIndex, if (matches) { ValueEval currentValueEval = ResolveReference(db, row, fc); - if(fc < 0 && algorithm.AllowEmptyMatchField && !(currentValueEval is NumericValueEval)) + if(fc < 0 && algorithm.AllowEmptyMatchField && currentValueEval is not NumericValueEval) { currentValueEval = NumberEval.ZERO; } @@ -280,7 +278,7 @@ private static bool FullFillsConditions(AreaEval db, int row, AreaEval cdb) // The column in the DB to apply the condition to. ValueEval targetHeader = ResolveReference(cdb, 0, column); - if (!(targetHeader is StringValueEval)) + if (targetHeader is not StringValueEval) { throw new EvaluationException(ErrorEval.VALUE_INVALID); } @@ -328,8 +326,8 @@ private static bool FullFillsConditions(AreaEval db, int row, AreaEval cdb) */ private static bool testNormalCondition(ValueEval value, ValueEval condition) { - if (condition is StringEval) { - String conditionString = ((StringEval)condition).StringValue; + if (condition is StringEval eval) { + String conditionString = eval.StringValue; if (conditionString.StartsWith("<")) { // It's a values = new List(); public bool ProcessMatch(ValueEval eval) { - if(eval is NumericValueEval) + if(eval is NumericValueEval valueEval) { - values.Add((NumericValueEval) eval); + values.Add(valueEval); } return true; } diff --git a/main/SS/Formula/Functions/DStdevp.cs b/main/SS/Formula/Functions/DStdevp.cs index c951adad7..ec519ea24 100644 --- a/main/SS/Formula/Functions/DStdevp.cs +++ b/main/SS/Formula/Functions/DStdevp.cs @@ -36,9 +36,9 @@ public sealed class DStdevp : IDStarAlgorithm private List values = new List(); public bool ProcessMatch(ValueEval eval) { - if(eval is NumericValueEval) + if(eval is NumericValueEval valueEval) { - values.Add((NumericValueEval) eval); + values.Add(valueEval); } return true; } diff --git a/main/SS/Formula/Functions/DSum.cs b/main/SS/Formula/Functions/DSum.cs index f6cd3a2c0..c7b387d24 100644 --- a/main/SS/Formula/Functions/DSum.cs +++ b/main/SS/Formula/Functions/DSum.cs @@ -44,9 +44,9 @@ public sealed class DSum : IDStarAlgorithm private double totalValue = 0; public bool ProcessMatch(ValueEval eval) { - if(eval is NumericValueEval) + if(eval is NumericValueEval valueEval) { - double currentValue = ((NumericValueEval)eval).NumberValue; + double currentValue = valueEval.NumberValue; totalValue += currentValue; } diff --git a/main/SS/Formula/Functions/DVar.cs b/main/SS/Formula/Functions/DVar.cs index 6adfe6ac2..115a27b02 100644 --- a/main/SS/Formula/Functions/DVar.cs +++ b/main/SS/Formula/Functions/DVar.cs @@ -31,9 +31,9 @@ public sealed class DVar : IDStarAlgorithm private List values = new List(); public bool ProcessMatch(ValueEval eval) { - if(eval is NumericValueEval) + if(eval is NumericValueEval valueEval) { - values.Add((NumericValueEval) eval); + values.Add(valueEval); } return true; } diff --git a/main/SS/Formula/Functions/DVarp.cs b/main/SS/Formula/Functions/DVarp.cs index 0d3921ae1..327d46868 100644 --- a/main/SS/Formula/Functions/DVarp.cs +++ b/main/SS/Formula/Functions/DVarp.cs @@ -36,9 +36,9 @@ public sealed class DVarp : IDStarAlgorithm private List values = new List(); public bool ProcessMatch(ValueEval eval) { - if(eval is NumericValueEval) + if(eval is NumericValueEval valueEval) { - values.Add((NumericValueEval) eval); + values.Add(valueEval); } return true; } diff --git a/main/SS/Formula/Functions/EDate.cs b/main/SS/Formula/Functions/EDate.cs index 96cfbc764..3d245decc 100644 --- a/main/SS/Formula/Functions/EDate.cs +++ b/main/SS/Formula/Functions/EDate.cs @@ -82,17 +82,16 @@ public ValueEval Evaluate(ValueEval[] args, OperationEvaluationContext ec) } private double GetValue(ValueEval arg) { - if (arg is NumberEval) + if (arg is NumberEval eval) { - return ((NumberEval)arg).NumberValue; + return eval.NumberValue; } if (arg is BlankEval) { return 0; } - if (arg is RefEval) + if (arg is RefEval refEval) { - RefEval refEval = (RefEval)arg; if (refEval.NumberOfSheets > 1) { // Multi-Sheet references are not supported @@ -100,9 +99,9 @@ private double GetValue(ValueEval arg) } ValueEval innerValueEval = refEval.GetInnerValueEval(refEval.FirstSheetIndex); - if (innerValueEval is NumberEval) + if (innerValueEval is NumberEval numberEval) { - return ((NumberEval)innerValueEval).NumberValue; + return numberEval.NumberValue; } if (innerValueEval is BlankEval) { diff --git a/main/SS/Formula/Functions/Hex2Dec.cs b/main/SS/Formula/Functions/Hex2Dec.cs index 54667a73e..8cecb8c9f 100644 --- a/main/SS/Formula/Functions/Hex2Dec.cs +++ b/main/SS/Formula/Functions/Hex2Dec.cs @@ -48,9 +48,8 @@ public class Hex2Dec : Fixed1ArgFunction, FreeRefFunction public override ValueEval Evaluate(int srcRowIndex, int srcColumnIndex, ValueEval numberVE) { String hex; - if (numberVE is RefEval) + if (numberVE is RefEval re) { - RefEval re = (RefEval)numberVE; hex = OperandResolver.CoerceValueToString(re.GetInnerValueEval(re.FirstSheetIndex)); } else diff --git a/main/SS/Formula/Functions/Index.cs b/main/SS/Formula/Functions/Index.cs index 14d59cfb6..522fda6f7 100644 --- a/main/SS/Formula/Functions/Index.cs +++ b/main/SS/Formula/Functions/Index.cs @@ -126,14 +126,14 @@ public ValueEval Evaluate(int srcRowIndex, int srcColumnIndex, ValueEval arg0, V private static TwoDEval ConvertFirstArg(ValueEval arg0) { ValueEval firstArg = arg0; - if (firstArg is RefEval) + if (firstArg is RefEval eval) { // Convert to area ref for simpler code in getValueFromArea() - return ((RefEval)firstArg).Offset(0, 0, 0, 0); + return eval.Offset(0, 0, 0, 0); } - if ((firstArg is TwoDEval)) + if ((firstArg is TwoDEval arg)) { - return (TwoDEval)firstArg; + return arg; } // else the other variation of thIs function takes an array as the first argument // it seems like interface 'ArrayEval' does not even exIst yet diff --git a/main/SS/Formula/Functions/LinearRegressionFunction.cs b/main/SS/Formula/Functions/LinearRegressionFunction.cs index 91c1a508f..014d8fdc7 100644 --- a/main/SS/Formula/Functions/LinearRegressionFunction.cs +++ b/main/SS/Formula/Functions/LinearRegressionFunction.cs @@ -170,28 +170,26 @@ private double EvaluateInternal(ValueVector x, ValueVector y, int size) { ValueEval vx = x.GetItem(i); ValueEval vy = y.GetItem(i); - if (vx is ErrorEval) + if (vx is ErrorEval eval) { if (firstXerr == null) { - firstXerr = (ErrorEval)vx; + firstXerr = eval; continue; } } - if (vy is ErrorEval) + if (vy is ErrorEval errorEval) { if (firstYerr == null) { - firstYerr = (ErrorEval)vy; + firstYerr = errorEval; continue; } } // only count pairs if both elements are numbers - if (vx is NumberEval && vy is NumberEval) + if (vx is NumberEval nx && vy is NumberEval ny) { accumlatedSome = true; - NumberEval nx = (NumberEval)vx; - NumberEval ny = (NumberEval)vy; sumx += nx.NumberValue; sumy += ny.NumberValue; } @@ -210,28 +208,26 @@ private double EvaluateInternal(ValueVector x, ValueVector y, int size) ValueEval vx = x.GetItem(i); ValueEval vy = y.GetItem(i); - if (vx is ErrorEval) + if (vx is ErrorEval eval) { if (firstXerr == null) { - firstXerr = (ErrorEval)vx; + firstXerr = eval; continue; } } - if (vy is ErrorEval) + if (vy is ErrorEval errorEval) { if (firstYerr == null) { - firstYerr = (ErrorEval)vy; + firstYerr = errorEval; continue; } } // only count pairs if both elements are numbers - if (vx is NumberEval && vy is NumberEval) + if (vx is NumberEval nx && vy is NumberEval ny) { - NumberEval nx = (NumberEval)vx; - NumberEval ny = (NumberEval)vy; xxbar += (nx.NumberValue - xbar) * (nx.NumberValue - xbar); xybar += (nx.NumberValue - xbar) * (ny.NumberValue - ybar); } @@ -268,17 +264,17 @@ private double EvaluateInternal(ValueVector x, ValueVector y, int size) private ValueVector CreateValueVector(ValueEval arg) { - if (arg is ErrorEval) + if (arg is ErrorEval eval) { - throw new EvaluationException((ErrorEval)arg); + throw new EvaluationException(eval); } - if (arg is TwoDEval) + if (arg is TwoDEval dEval) { - return new AreaValueArray((TwoDEval)arg); + return new AreaValueArray(dEval); } - if (arg is RefEval) + if (arg is RefEval refEval) { - return new RefValueArray((RefEval)arg); + return new RefValueArray(refEval); } return new SingleCellValueArray(arg); } diff --git a/main/SS/Formula/Functions/Logical/Isnontext.cs b/main/SS/Formula/Functions/Logical/Isnontext.cs index 222e89946..e2506444a 100644 --- a/main/SS/Formula/Functions/Logical/Isnontext.cs +++ b/main/SS/Formula/Functions/Logical/Isnontext.cs @@ -30,7 +30,7 @@ public class Isnontext : LogicalFunction { protected override bool Evaluate(ValueEval arg) { - return !(arg is StringEval); + return arg is not StringEval; } } } \ No newline at end of file diff --git a/main/SS/Formula/Functions/LookupUtils.cs b/main/SS/Formula/Functions/LookupUtils.cs index 013d97339..3dce3304e 100644 --- a/main/SS/Formula/Functions/LookupUtils.cs +++ b/main/SS/Formula/Functions/LookupUtils.cs @@ -259,9 +259,9 @@ private sealed class TolerantStringLookupComparer : StringLookupComparer { static StringEval ConvertToStringEval(ValueEval eval) { - if (eval is StringEval) + if (eval is StringEval stringEval) { - return (StringEval)eval; + return stringEval; } String sv = OperandResolver.CoerceValueToString(eval); return new StringEval(sv); @@ -338,8 +338,7 @@ public static int ResolveRowOrColIndexArg(ValueEval rowColIndexArg, int srcCellR throw EvaluationException.InvalidRef(); } int oneBasedIndex; - if (veRowColIndexArg is StringEval) { - StringEval se = (StringEval)veRowColIndexArg; + if (veRowColIndexArg is StringEval se) { String strVal = se.StringValue; Double dVal = OperandResolver.ParseDouble(strVal); if (Double.IsNaN(dVal)) { @@ -366,13 +365,12 @@ public static int ResolveRowOrColIndexArg(ValueEval rowColIndexArg, int srcCellR */ public static AreaEval ResolveTableArrayArg(ValueEval eval) { - if (eval is AreaEval) + if (eval is AreaEval areaEval) { - return (AreaEval)eval; + return areaEval; } - if (eval is RefEval) { - RefEval refEval = (RefEval)eval; + if (eval is RefEval refEval) { // Make this cell ref look like a 1x1 area ref. // It doesn't matter if eval is a 2D or 3D ref, because that detail is never asked of AreaEval. @@ -406,16 +404,15 @@ public static bool ResolveRangeLookupArg(ValueEval rangeLookupArg, int srcCellRo // this does not Get the default value return false; } - if (valEval is BoolEval) + if (valEval is BoolEval boolEval) { // Happy day flow - BoolEval boolEval = (BoolEval)valEval; return boolEval.BooleanValue; } - if (valEval is StringEval) + if (valEval is StringEval eval) { - String stringValue = ((StringEval)valEval).StringValue; + String stringValue = eval.StringValue; if (stringValue.Length < 1) { // More trickiness: @@ -436,9 +433,8 @@ public static bool ResolveRangeLookupArg(ValueEval rangeLookupArg, int srcCellRo //// This Is in contrast to the code below,, where NumberEvals values (for //// example 0.01) *do* resolve to equivalent bool values. } - if (valEval is NumericValueEval) + if (valEval is NumericValueEval nve) { - NumericValueEval nve = (NumericValueEval)valEval; // zero Is FALSE, everything else Is TRUE return 0.0 != nve.NumberValue; } @@ -727,17 +723,17 @@ public static LookupValueComparer CreateLookupComparer(ValueEval lookupValue, bo // empty string in the lookup column/row can only be matched by explicit emtpty string return new NumberLookupComparer(NumberEval.ZERO); } - if (lookupValue is StringEval) + if (lookupValue is StringEval eval) { - return new StringLookupComparer((StringEval)lookupValue, matchExact, isMatchFunction); + return new StringLookupComparer(eval, matchExact, isMatchFunction); } - if (lookupValue is NumberEval) + if (lookupValue is NumberEval value) { - return new NumberLookupComparer((NumberEval)lookupValue); + return new NumberLookupComparer(value); } - if (lookupValue is BoolEval) + if (lookupValue is BoolEval boolEval) { - return new BooleanLookupComparer((BoolEval)lookupValue); + return new BooleanLookupComparer(boolEval); } throw new ArgumentException("Bad lookup value type (" + lookupValue.GetType().Name + ")"); } @@ -747,11 +743,11 @@ private static LookupValueComparer CreateTolerantLookupComparer(ValueEval lookup { return new TolerantStringLookupComparer(new StringEval(""), matchExact, isMatchFunction); } - if (lookupValue is BoolEval) { - return new BooleanLookupComparer((BoolEval)lookupValue); + if (lookupValue is BoolEval eval) { + return new BooleanLookupComparer(eval); } - if (matchExact && lookupValue is NumberEval) { - return new NumberLookupComparer((NumberEval)lookupValue); + if (matchExact && lookupValue is NumberEval value) { + return new NumberLookupComparer(value); } return new TolerantStringLookupComparer(lookupValue, matchExact, isMatchFunction); } diff --git a/main/SS/Formula/Functions/Match.cs b/main/SS/Formula/Functions/Match.cs index 346365fc6..674a63cc6 100644 --- a/main/SS/Formula/Functions/Match.cs +++ b/main/SS/Formula/Functions/Match.cs @@ -135,9 +135,8 @@ public ValueEval Evaluate(ValueEval[] args, int srcCellRow, int srcCellCol) private static ValueVector EvaluateLookupRange(ValueEval eval) { - if (eval is RefEval) + if (eval is RefEval re) { - RefEval re = (RefEval)eval; if (re.NumberOfSheets == 1) { return new SingleValueVector(re.GetInnerValueEval(re.FirstSheetIndex)); @@ -147,9 +146,9 @@ private static ValueVector EvaluateLookupRange(ValueEval eval) return LookupUtils.CreateVector(re); } } - if (eval is TwoDEval) + if (eval is TwoDEval dEval) { - ValueVector result = LookupUtils.CreateVector((TwoDEval)eval); + ValueVector result = LookupUtils.CreateVector(dEval); if (result == null) { throw new EvaluationException(ErrorEval.NA); @@ -162,9 +161,8 @@ private static ValueVector EvaluateLookupRange(ValueEval eval) { throw new EvaluationException(ErrorEval.NA); } - if (eval is StringEval) + if (eval is StringEval se) { - StringEval se = (StringEval)eval; double d = OperandResolver.ParseDouble(se.StringValue); if (double.IsNaN(d)) { @@ -183,18 +181,16 @@ private static double EvaluateMatchTypeArg(ValueEval arg, int srcCellRow, int sr { ValueEval match_type = OperandResolver.GetSingleValue(arg, srcCellRow, srcCellCol); - if (match_type is ErrorEval) + if (match_type is ErrorEval eval) { - throw new EvaluationException((ErrorEval)match_type); + throw new EvaluationException(eval); } - if (match_type is NumericValueEval) + if (match_type is NumericValueEval ne) { - NumericValueEval ne = (NumericValueEval)match_type; return ne.NumberValue; } - if (match_type is StringEval) + if (match_type is StringEval se) { - StringEval se = (StringEval)match_type; double d = OperandResolver.ParseDouble(se.StringValue); if (double.IsNaN(d)) { diff --git a/main/SS/Formula/Functions/Matrix/MatrixFunction.cs b/main/SS/Formula/Functions/Matrix/MatrixFunction.cs index 23921c223..ed1e2215f 100644 --- a/main/SS/Formula/Functions/Matrix/MatrixFunction.cs +++ b/main/SS/Formula/Functions/Matrix/MatrixFunction.cs @@ -79,7 +79,7 @@ protected OneArrayArg() public override ValueEval Evaluate(int srcRowIndex, int srcColumnIndex, ValueEval arg0) { - if (arg0 is AreaEval) + if (arg0 is AreaEval eval) { double[] result = null; double[,] resultArray; @@ -87,8 +87,8 @@ public override ValueEval Evaluate(int srcRowIndex, int srcColumnIndex, ValueEva try { - double[] values = CollectValues(arg0); - double[,] array = fillDoubleArray(values, ((AreaEval)arg0).Height, ((AreaEval)arg0).Width); + double[] values = CollectValues(eval); + double[,] array = fillDoubleArray(values, eval.Height, eval.Width); resultArray = Evaluate(array); width = resultArray.GetLength(1); height = resultArray.GetLength(0); @@ -115,9 +115,9 @@ public override ValueEval Evaluate(int srcRowIndex, int srcColumnIndex, ValueEva else { /* find a better solution */ - return new CacheAreaEval(((AreaEval)arg0).FirstRow, ((AreaEval)arg0).FirstColumn, - ((AreaEval)arg0).FirstRow + height - 1, - ((AreaEval)arg0).FirstColumn + width - 1, vals); + return new CacheAreaEval(eval.FirstRow, eval.FirstColumn, + eval.FirstRow + height - 1, + eval.FirstColumn + width - 1, vals); } } else @@ -159,12 +159,12 @@ public override ValueEval Evaluate(int srcRowIndex, int srcColumnIndex, ValueEva { double[,] array0, array1, resultArray; - if (arg0 is AreaEval) + if (arg0 is AreaEval eval) { try { - double[] values = CollectValues(arg0); - array0 = fillDoubleArray(values, ((AreaEval)arg0).Height, ((AreaEval)arg0).Width); + double[] values = CollectValues(eval); + array0 = fillDoubleArray(values, eval.Height, eval.Width); } catch (EvaluationException e) { @@ -184,12 +184,12 @@ public override ValueEval Evaluate(int srcRowIndex, int srcColumnIndex, ValueEva } } - if (arg1 is AreaEval) + if (arg1 is AreaEval areaEval) { try { - double[] values = CollectValues(arg1); - array1 = fillDoubleArray(values, ((AreaEval)arg1).Height, ((AreaEval)arg1).Width); + double[] values = CollectValues(areaEval); + array1 = fillDoubleArray(values, areaEval.Height, areaEval.Width); } catch (EvaluationException e) { diff --git a/main/SS/Formula/Functions/Maxifs.cs b/main/SS/Formula/Functions/Maxifs.cs index fc1beb7b1..3d9e37fb0 100644 --- a/main/SS/Formula/Functions/Maxifs.cs +++ b/main/SS/Formula/Functions/Maxifs.cs @@ -61,7 +61,7 @@ private sealed class MyAggregator : IAggregator public void AddValue(ValueEval value) { - double d = (value is NumberEval) ? ((NumberEval)value).NumberValue : 0.0; + double d = (value is NumberEval eval) ? eval.NumberValue : 0.0; if(accumulator == null || accumulator < d) { accumulator = d; diff --git a/main/SS/Formula/Functions/Minifs.cs b/main/SS/Formula/Functions/Minifs.cs index c1a6ead6e..ec386404b 100644 --- a/main/SS/Formula/Functions/Minifs.cs +++ b/main/SS/Formula/Functions/Minifs.cs @@ -60,7 +60,7 @@ private sealed class MyAggregator : IAggregator public void AddValue(ValueEval value) { - double d = (value is NumberEval) ? ((NumberEval)value).NumberValue : 0.0; + double d = (value is NumberEval eval) ? eval.NumberValue : 0.0; if(accumulator == null || accumulator > d) { accumulator = d; diff --git a/main/SS/Formula/Functions/Mode.cs b/main/SS/Formula/Functions/Mode.cs index 788c1b36b..fd96e47d4 100644 --- a/main/SS/Formula/Functions/Mode.cs +++ b/main/SS/Formula/Functions/Mode.cs @@ -97,9 +97,8 @@ public ValueEval Evaluate(ValueEval[] args, int srcCellRow, int srcCellCol) private static void CollectValues(ValueEval arg, IList temp) { - if (arg is TwoDEval) + if (arg is TwoDEval ae) { - TwoDEval ae = (TwoDEval)arg; int width = ae.Width; int height = ae.Height; for (int rrIx = 0; rrIx < height; rrIx++) @@ -112,9 +111,8 @@ private static void CollectValues(ValueEval arg, IList temp) } return; } - if (arg is RefEval) + if (arg is RefEval re) { - RefEval re = (RefEval)arg; int firstSheetIndex = re.FirstSheetIndex; int lastSheetIndex = re.LastSheetIndex; for (int sIx = firstSheetIndex; sIx <= lastSheetIndex; sIx++) @@ -129,9 +127,9 @@ private static void CollectValues(ValueEval arg, IList temp) private static void CollectValue(ValueEval arg, IList temp, bool mustBeNumber) { - if (arg is ErrorEval) + if (arg is ErrorEval eval) { - throw new EvaluationException((ErrorEval)arg); + throw new EvaluationException(eval); } if (arg == BlankEval.instance || arg is BoolEval || arg is StringEval) { @@ -141,9 +139,9 @@ private static void CollectValue(ValueEval arg, IList temp, bool mustBeNumber) } return; } - if (arg is NumberEval) + if (arg is NumberEval numberEval) { - temp.Add(((NumberEval)arg).NumberValue); + temp.Add(numberEval.NumberValue); return; } throw new InvalidOperationException("Unexpected value type (" + arg.GetType().Name + ")"); diff --git a/main/SS/Formula/Functions/MultiOperandNumericFunction.cs b/main/SS/Formula/Functions/MultiOperandNumericFunction.cs index 10ec1082f..256c07871 100644 --- a/main/SS/Formula/Functions/MultiOperandNumericFunction.cs +++ b/main/SS/Formula/Functions/MultiOperandNumericFunction.cs @@ -137,28 +137,26 @@ public virtual bool IsSubtotalCounted */ private void CollectValues(ValueEval operand, DoubleList temp) { - if (operand is ThreeDEval) + if (operand is ThreeDEval eval) { - ThreeDEval ae = (ThreeDEval)operand; - for (int sIx = ae.FirstSheetIndex; sIx <= ae.LastSheetIndex; sIx++) + for (int sIx = eval.FirstSheetIndex; sIx <= eval.LastSheetIndex; sIx++) { - int width = ae.Width; - int height = ae.Height; + int width = eval.Width; + int height = eval.Height; for (int rrIx = 0; rrIx < height; rrIx++) { for (int rcIx = 0; rcIx < width; rcIx++) { - ValueEval ve = ae.GetValue(sIx, rrIx, rcIx); - if (!IsSubtotalCounted && ae.IsSubTotal(rrIx, rcIx)) continue; + ValueEval ve = eval.GetValue(sIx, rrIx, rcIx); + if (!IsSubtotalCounted && eval.IsSubTotal(rrIx, rcIx)) continue; CollectValue(ve, true, temp); } } } return; } - if (operand is TwoDEval) + if (operand is TwoDEval ae) { - TwoDEval ae = (TwoDEval)operand; int width = ae.Width; int height = ae.Height; for (int rrIx = 0; rrIx < height; rrIx++) @@ -172,9 +170,8 @@ private void CollectValues(ValueEval operand, DoubleList temp) } return; } - if (operand is RefEval) + if (operand is RefEval re) { - RefEval re = (RefEval)operand; for (int sIx = re.FirstSheetIndex; sIx <= re.LastSheetIndex; sIx++) { CollectValue(re.GetInnerValueEval(sIx), true, temp); @@ -189,29 +186,27 @@ private void CollectValue(ValueEval ve, bool isViaReference, DoubleList temp) { throw new ArgumentException("ve must not be null"); } - if (ve is BoolEval) + if (ve is BoolEval boolEval) { if (!isViaReference || _isReferenceBoolCounted) { - BoolEval boolEval = (BoolEval)ve; temp.Add(boolEval.NumberValue); } return; } - if (ve is NumberEval) + if (ve is NumberEval ne) { - NumberEval ne = (NumberEval)ve; temp.Add(ne.NumberValue); return; } - if (ve is StringEval) + if (ve is StringEval eval) { if (isViaReference) { // ignore all ref strings return; } - String s = ((StringEval)ve).StringValue; + String s = eval.StringValue; Double d = OperandResolver.ParseDouble(s); if (double.IsNaN(d)) { @@ -220,9 +215,9 @@ private void CollectValue(ValueEval ve, bool isViaReference, DoubleList temp) temp.Add(d); return; } - if (ve is ErrorEval) + if (ve is ErrorEval errorEval) { - throw new EvaluationException((ErrorEval)ve); + throw new EvaluationException(errorEval); } if (ve == BlankEval.instance) { diff --git a/main/SS/Formula/Functions/Offset.cs b/main/SS/Formula/Functions/Offset.cs index b261e932c..02a8f90bd 100644 --- a/main/SS/Formula/Functions/Offset.cs +++ b/main/SS/Formula/Functions/Offset.cs @@ -244,17 +244,17 @@ public ValueEval Evaluate(ValueEval[] args, int srcCellRow, int srcCellCol) switch (args.Length) { case 5: - if (!(args[4] is MissingArgEval)) { + if (args[4] is not MissingArgEval) { width = EvaluateIntArg(args[4], srcCellRow, srcCellCol); } // fall-through to pick up height - if (!(args[3] is MissingArgEval)) + if (args[3] is not MissingArgEval) { height = EvaluateIntArg(args[3], srcCellRow, srcCellCol); } break; case 4: - if (!(args[3] is MissingArgEval)) { + if (args[3] is not MissingArgEval) { height = EvaluateIntArg(args[3], srcCellRow, srcCellCol); } break; @@ -300,17 +300,17 @@ private static AreaEval CreateOffset(BaseRef baseRef, private static BaseRef EvaluateBaseRef(ValueEval eval) { - if (eval is RefEval) + if (eval is RefEval refEval) { - return new BaseRef((RefEval)eval); + return new BaseRef(refEval); } - if (eval is AreaEval) + if (eval is AreaEval areaEval) { - return new BaseRef((AreaEval)eval); + return new BaseRef(areaEval); } - if (eval is ErrorEval) + if (eval is ErrorEval errorEval) { - throw new EvalEx((ErrorEval)eval); + throw new EvalEx(errorEval); } throw new EvalEx(ErrorEval.VALUE_INVALID); } @@ -343,13 +343,12 @@ private static double EvaluateDoubleArg(ValueEval eval, int srcCellRow, int srcC { ValueEval ve = OperandResolver.GetSingleValue(eval, srcCellRow, srcCellCol); - if (ve is NumericValueEval) + if (ve is NumericValueEval valueEval) { - return ((NumericValueEval)ve).NumberValue; + return valueEval.NumberValue; } - if (ve is StringEval) + if (ve is StringEval se) { - StringEval se = (StringEval)ve; double d = OperandResolver.ParseDouble(se.StringValue); if (double.IsNaN(d)) { @@ -357,10 +356,10 @@ private static double EvaluateDoubleArg(ValueEval eval, int srcCellRow, int srcC } return d; } - if (ve is BoolEval) + if (ve is BoolEval boolEval) { // in the context of OFFSet, bools resolve to 0 and 1. - if (((BoolEval)ve).BooleanValue) + if (boolEval.BooleanValue) { return 1; } diff --git a/main/SS/Formula/Functions/PercentRank.cs b/main/SS/Formula/Functions/PercentRank.cs index 04d6b7c7a..e5842d6d3 100644 --- a/main/SS/Formula/Functions/PercentRank.cs +++ b/main/SS/Formula/Functions/PercentRank.cs @@ -115,15 +115,14 @@ private ValueEval calculateRank(List numbers, double x, int significance else { ValueEval belowRank = calculateRank(numbers, closestMatchBelow, significance, false); - if (!(belowRank is NumberEval)) { + if (belowRank is not NumberEval below) { return belowRank; } ValueEval aboveRank = calculateRank(numbers, closestMatchAbove, significance, false); - if (!(aboveRank is NumberEval)) { + if (aboveRank is not NumberEval above) { return aboveRank; } - NumberEval below = (NumberEval)belowRank; - NumberEval above = (NumberEval)aboveRank; + double diff = closestMatchAbove - closestMatchBelow; double pos = x - closestMatchBelow; double rankDiff = above.NumberValue - below.NumberValue; @@ -133,9 +132,8 @@ private ValueEval calculateRank(List numbers, double x, int significance } private List getValues(ValueEval eval, int srcRowIndex, int srcColumnIndex) { - if (eval is AreaEval) + if (eval is AreaEval ae) { - AreaEval ae = (AreaEval)eval; List list = new List(); for (int r = ae.FirstRow; r <= ae.LastRow; r++) { diff --git a/main/SS/Formula/Functions/Rank.cs b/main/SS/Formula/Functions/Rank.cs index d85862c5f..0de198d86 100644 --- a/main/SS/Formula/Functions/Rank.cs +++ b/main/SS/Formula/Functions/Rank.cs @@ -53,9 +53,9 @@ public override ValueEval Evaluate(int srcRowIndex, int srcColumnIndex, ValueEva { throw new EvaluationException(ErrorEval.NUM_ERROR); } - if (arg1 is RefListEval) + if (arg1 is RefListEval listEval) { - return eval(result, ((RefListEval)arg1), true); + return eval(result, listEval, true); } aeRange = ConvertRangeArg(arg1); return eval(result, aeRange, true); @@ -91,9 +91,9 @@ public override ValueEval Evaluate(int srcRowIndex, int srcColumnIndex, ValueEva } else throw new EvaluationException(ErrorEval.NUM_ERROR); - if (arg1 is RefListEval) + if (arg1 is RefListEval listEval) { - return eval(result, ((RefListEval)arg1), order); + return eval(result, listEval, order); } AreaEval aeRange = ConvertRangeArg(arg1); return eval(result, aeRange, order); @@ -143,9 +143,9 @@ private static ValueEval eval(double arg0, RefListEval aeRange, bool descending_ aeRange.GetList()[index] = ((RefEval)targetVe).GetInnerValueEval(((RefEval)ve).FirstSheetIndex); } Double value; - if (ve is NumberEval) + if (ve is NumberEval numberEval) { - value = ((NumberEval)ve).NumberValue; + value = numberEval.NumberValue; } else { @@ -164,9 +164,9 @@ private static Double GetValue(AreaEval aeRange, int relRowIndex, int relColInde { ValueEval addend = aeRange.GetRelativeValue(relRowIndex, relColIndex); - if (addend is NumberEval) + if (addend is NumberEval numberEval) { - return ((NumberEval)addend).NumberValue; + return numberEval.NumberValue; } // everything else (including string and boolean values) counts as zero return Double.NaN; @@ -174,13 +174,13 @@ private static Double GetValue(AreaEval aeRange, int relRowIndex, int relColInde private static AreaEval ConvertRangeArg(ValueEval eval) { - if (eval is AreaEval) + if (eval is AreaEval areaEval) { - return (AreaEval)eval; + return areaEval; } - if (eval is RefEval) + if (eval is RefEval refEval) { - return ((RefEval)eval).Offset(0, 0, 0, 0); + return refEval.Offset(0, 0, 0, 0); } throw new EvaluationException(ErrorEval.VALUE_INVALID); } diff --git a/main/SS/Formula/Functions/Row.cs b/main/SS/Formula/Functions/Row.cs index 5b26a1c06..bf0dc1f79 100644 --- a/main/SS/Formula/Functions/Row.cs +++ b/main/SS/Formula/Functions/Row.cs @@ -33,13 +33,13 @@ public ValueEval Evaluate(int srcRowIndex, int srcColumnIndex, ValueEval arg0) { int rnum; - if (arg0 is AreaEval) + if (arg0 is AreaEval eval) { - rnum = ((AreaEval)arg0).FirstRow; + rnum = eval.FirstRow; } - else if (arg0 is RefEval) + else if (arg0 is RefEval refEval) { - rnum = ((RefEval)arg0).Row; + rnum = refEval.Row; } else { diff --git a/main/SS/Formula/Functions/Rows.cs b/main/SS/Formula/Functions/Rows.cs index baa906a12..99238918b 100644 --- a/main/SS/Formula/Functions/Rows.cs +++ b/main/SS/Formula/Functions/Rows.cs @@ -32,9 +32,9 @@ public override ValueEval Evaluate(int srcRowIndex, int srcColumnIndex, ValueEva { int result; - if (arg0 is TwoDEval) + if (arg0 is TwoDEval eval) { - result = ((TwoDEval)arg0).Height; + result = eval.Height; } else if (arg0 is RefEval) { diff --git a/main/SS/Formula/Functions/Subtotal.cs b/main/SS/Formula/Functions/Subtotal.cs index 8b7283020..aee3defb6 100644 --- a/main/SS/Formula/Functions/Subtotal.cs +++ b/main/SS/Formula/Functions/Subtotal.cs @@ -120,12 +120,11 @@ public ValueEval Evaluate(ValueEval[] args, int srcRowIndex, int srcColumnIndex) while (it.MoveNext()) { ValueEval eval = it.Current; - if (eval is LazyRefEval) + if (eval is LazyRefEval lazyRefEval) { - LazyRefEval lazyRefEval = (LazyRefEval)eval; if (lazyRefEval.IsSubTotal) { - toRemove.Add(eval); + toRemove.Add(lazyRefEval); } } } diff --git a/main/SS/Formula/Functions/Sumif.cs b/main/SS/Formula/Functions/Sumif.cs index 8c4dacf24..94288596c 100644 --- a/main/SS/Formula/Functions/Sumif.cs +++ b/main/SS/Formula/Functions/Sumif.cs @@ -117,13 +117,13 @@ private static double Accumulate(AreaEval aeRange, IMatchPredicate mp, AreaEval } ValueEval addend = aeSum.GetRelativeValue(relRowIndex, relColIndex); - if (addend is NumberEval) + if (addend is NumberEval eval) { - return ((NumberEval)addend).NumberValue; + return eval.NumberValue; } - else if (addend is ErrorEval) + else if (addend is ErrorEval errorEval) { - throw new EvaluationException((ErrorEval)addend); + throw new EvaluationException(errorEval); } else { @@ -141,13 +141,13 @@ private static double Accumulate(AreaEval aeRange, IMatchPredicate mp, AreaEval private static AreaEval CreateSumRange(ValueEval eval, AreaEval aeRange) { - if (eval is AreaEval) + if (eval is AreaEval areaEval) { - return ((AreaEval)eval).Offset(0, aeRange.Height - 1, 0, aeRange.Width - 1); + return areaEval.Offset(0, aeRange.Height - 1, 0, aeRange.Width - 1); } - if (eval is RefEval) + if (eval is RefEval refEval) { - return ((RefEval)eval).Offset(0, aeRange.Height - 1, 0, aeRange.Width - 1); + return refEval.Offset(0, aeRange.Height - 1, 0, aeRange.Width - 1); } throw new EvaluationException(ErrorEval.VALUE_INVALID); @@ -157,14 +157,14 @@ private static AreaEval CreateSumRange(ValueEval eval, AreaEval aeRange) private static AreaEval ConvertRangeArg(ValueEval eval) { - if (eval is AreaEval) + if (eval is AreaEval areaEval) { - return (AreaEval)eval; + return areaEval; } - if (eval is RefEval) + if (eval is RefEval refEval) { - return ((RefEval)eval).Offset(0, 0, 0, 0); + return refEval.Offset(0, 0, 0, 0); } throw new EvaluationException(ErrorEval.VALUE_INVALID); diff --git a/main/SS/Formula/Functions/Sumifs.cs b/main/SS/Formula/Functions/Sumifs.cs index f721954c1..35d022213 100644 --- a/main/SS/Formula/Functions/Sumifs.cs +++ b/main/SS/Formula/Functions/Sumifs.cs @@ -59,7 +59,7 @@ private sealed class MyAggregator : IAggregator public void AddValue(ValueEval value) { - accumulator += (value is NumberEval) ? ((NumberEval) value).NumberValue : 0.0; + accumulator += (value is NumberEval eval) ? eval.NumberValue : 0.0; } public ValueEval GetResult() diff --git a/main/SS/Formula/Functions/Sumproduct.cs b/main/SS/Formula/Functions/Sumproduct.cs index f5f8e9caa..a335cbbb4 100644 --- a/main/SS/Formula/Functions/Sumproduct.cs +++ b/main/SS/Formula/Functions/Sumproduct.cs @@ -70,9 +70,8 @@ public ValueEval Evaluate(ValueEval[] args, int srcCellRow, int srcCellCol) { return EvaluateSingleProduct(args); } - if (firstArg is TwoDEval) + if (firstArg is TwoDEval ae) { - TwoDEval ae = (TwoDEval)firstArg; if (ae.IsRow && ae.IsColumn) { return EvaluateSingleProduct(args); @@ -104,9 +103,8 @@ private static double GetScalarValue(ValueEval arg) { ValueEval eval; - if (arg is RefEval) + if (arg is RefEval re) { - RefEval re = (RefEval)arg; if (re.NumberOfSheets > 1) { throw new EvaluationException(ErrorEval.VALUE_INVALID); @@ -122,9 +120,8 @@ private static double GetScalarValue(ValueEval arg) { throw new ArgumentException("parameter may not be null"); } - if (eval is AreaEval) + if (eval is AreaEval ae) { - AreaEval ae = (AreaEval)eval; // an area ref can work as a scalar value if it is 1x1 if (!ae.IsColumn || !ae.IsRow) { @@ -133,13 +130,13 @@ private static double GetScalarValue(ValueEval arg) eval = ae.GetRelativeValue(0, 0); } - if (!(eval is ValueEval)) + if (!(eval is ValueEval valueEval)) { throw new ArgumentException("Unexpected value eval class (" + eval.GetType().Name + ")"); } - return GetProductTerm((ValueEval)eval, true); + return GetProductTerm(valueEval, true); } private ValueEval EvaluateAreaSumProduct(ValueEval[] evalArgs) { @@ -200,9 +197,9 @@ private static void ThrowFirstError(TwoDEval areaEval) for (int rcIx = 0; rcIx < width; rcIx++) { ValueEval ve = areaEval.GetValue(rrIx, rcIx); - if (ve is ErrorEval) + if (ve is ErrorEval eval) { - throw new EvaluationException((ErrorEval)ve); + throw new EvaluationException(eval); } } } @@ -248,9 +245,9 @@ private static double GetProductTerm(ValueEval ve, bool IsScalarProduct) return 0; } - if (ve is ErrorEval) + if (ve is ErrorEval eval) { - throw new EvaluationException((ErrorEval)ve); + throw new EvaluationException(eval); } if (ve is StringEval) { @@ -262,9 +259,8 @@ private static double GetProductTerm(ValueEval ve, bool IsScalarProduct) // even if they would Parse as valid numeric values return 0; } - if (ve is NumericValueEval) + if (ve is NumericValueEval nve) { - NumericValueEval nve = (NumericValueEval)ve; return nve.NumberValue; } throw new RuntimeException("Unexpected value eval class (" diff --git a/main/SS/Formula/Functions/T.cs b/main/SS/Formula/Functions/T.cs index 7c9fe047f..292736c1f 100644 --- a/main/SS/Formula/Functions/T.cs +++ b/main/SS/Formula/Functions/T.cs @@ -27,16 +27,15 @@ public class T : Fixed1ArgFunction public override ValueEval Evaluate(int srcRowIndex, int srcColumnIndex, ValueEval arg0) { ValueEval arg = arg0; - if (arg is RefEval) + if (arg is RefEval re) { // always use the first sheet - RefEval re = (RefEval)arg; arg = re.GetInnerValueEval(re.FirstSheetIndex); } - else if (arg is AreaEval) + else if (arg is AreaEval eval) { // when the arg is an area, choose the top left cell - arg = ((AreaEval)arg).GetRelativeValue(0, 0); + arg = eval.GetRelativeValue(0, 0); } if (arg is StringEval) diff --git a/main/SS/Formula/Functions/XYNumericFunction.cs b/main/SS/Formula/Functions/XYNumericFunction.cs index 63e0ff76b..434996df2 100644 --- a/main/SS/Formula/Functions/XYNumericFunction.cs +++ b/main/SS/Formula/Functions/XYNumericFunction.cs @@ -177,28 +177,26 @@ private double EvaluateInternal(ValueVector x, ValueVector y, int size) { ValueEval vx = x.GetItem(i); ValueEval vy = y.GetItem(i); - if (vx is ErrorEval) + if (vx is ErrorEval eval) { if (firstXerr == null) { - firstXerr = (ErrorEval)vx; + firstXerr = eval; continue; } } - if (vy is ErrorEval) + if (vy is ErrorEval errorEval) { if (firstYerr == null) { - firstYerr = (ErrorEval)vy; + firstYerr = errorEval; continue; } } // only count pairs if both elements are numbers - if (vx is NumberEval && vy is NumberEval) + if (vx is NumberEval nx && vy is NumberEval ny) { accumlatedSome = true; - NumberEval nx = (NumberEval)vx; - NumberEval ny = (NumberEval)vy; result += acc.Accumulate(nx.NumberValue, ny.NumberValue); } else @@ -277,17 +275,17 @@ private static double GetDoubleValue(Eval eval) private static ValueVector CreateValueVector(ValueEval arg) { - if (arg is ErrorEval) + if (arg is ErrorEval eval) { - throw new EvaluationException((ErrorEval)arg); + throw new EvaluationException(eval); } - if (arg is TwoDEval) + if (arg is TwoDEval dEval) { - return new AreaValueArray((TwoDEval)arg); + return new AreaValueArray(dEval); } - if (arg is RefEval) + if (arg is RefEval refEval) { - return new RefValueArray((RefEval)arg); + return new RefValueArray(refEval); } return new SingleCellValueArray(arg); } diff --git a/main/SS/Formula/OperandClassTransformer.cs b/main/SS/Formula/OperandClassTransformer.cs index 27f9f79bd..02b92b2e2 100644 --- a/main/SS/Formula/OperandClassTransformer.cs +++ b/main/SS/Formula/OperandClassTransformer.cs @@ -133,9 +133,9 @@ private void TransformNode(ParseNode node, byte desiredOperandClass, } return; } - if (token is AbstractFunctionPtg) + if (token is AbstractFunctionPtg ptg) { - TransformFunctionNode((AbstractFunctionPtg)token, children, desiredOperandClass, callerForceArrayFlag); + TransformFunctionNode(ptg, children, desiredOperandClass, callerForceArrayFlag); return; } if (children.Length > 0) @@ -158,18 +158,16 @@ private void TransformNode(ParseNode node, byte desiredOperandClass, } private static bool IsSingleArgSum(Ptg token) { - if (token is AttrPtg) + if (token is AttrPtg attrPtg) { - AttrPtg attrPtg = (AttrPtg)token; return attrPtg.IsSum; } return false; } private static bool IsSimpleValueFunction(Ptg token) { - if (token is AbstractFunctionPtg) + if (token is AbstractFunctionPtg aptg) { - AbstractFunctionPtg aptg = (AbstractFunctionPtg)token; if (aptg.DefaultOperandClass != Ptg.CLASS_VALUE) { return false; diff --git a/main/SS/Formula/OperationEvaluationContext.cs b/main/SS/Formula/OperationEvaluationContext.cs index a66622b6b..0d7d216bc 100644 --- a/main/SS/Formula/OperationEvaluationContext.cs +++ b/main/SS/Formula/OperationEvaluationContext.cs @@ -119,9 +119,9 @@ SheetRangeEvaluator CreateExternSheetRefEvaluator(ExternalSheet externalSheet) otherFirstSheetIndex = _workbook.GetSheetIndex(externalSheet.SheetName); } - if (externalSheet is ExternalSheetRange) + if (externalSheet is ExternalSheetRange range) { - String lastSheetName = ((ExternalSheetRange)externalSheet).LastSheetName; + String lastSheetName = range.LastSheetName; otherLastSheetIndex = _workbook.GetSheetIndex(lastSheetName); } } @@ -139,9 +139,9 @@ SheetRangeEvaluator CreateExternSheetRefEvaluator(ExternalSheet externalSheet) } otherFirstSheetIndex = targetEvaluator.GetSheetIndex(externalSheet.SheetName); - if (externalSheet is ExternalSheetRange) + if (externalSheet is ExternalSheetRange range) { - String lastSheetName = ((ExternalSheetRange)externalSheet).LastSheetName; + String lastSheetName = range.LastSheetName; otherLastSheetIndex = targetEvaluator.GetSheetIndex(lastSheetName); } @@ -416,17 +416,17 @@ private ValueEval convertObjectEval(Object token) { throw new ArgumentNullException("Array item cannot be null"); } - if (token is String) { - return new StringEval((String)token); + if (token is String s) { + return new StringEval(s); } - if (token is Double) { - return new NumberEval(((Double)token)); + if (token is Double d) { + return new NumberEval(d); } - if (token is Boolean) { - return BoolEval.ValueOf((Boolean)token); + if (token is Boolean b) { + return BoolEval.ValueOf(b); } - if (token is Constant.ErrorConstant) { - return ErrorEval.ValueOf(((Constant.ErrorConstant)token).ErrorCode); + if (token is Constant.ErrorConstant constant) { + return ErrorEval.ValueOf(constant.ErrorCode); } throw new ArgumentException("Unexpected constant class (" + token.GetType().Name + ")"); } @@ -545,24 +545,20 @@ private ValueEval GetExternalNameXEval(ExternalName externName, String workbookN refWorkbookEvaluator, refWorkbookEvaluator.Workbook, -1, -1, -1, _tracker); Ptg ptg = evaluationName.NameDefinition[0]; - if (ptg is Ref3DPtg) + if (ptg is Ref3DPtg rptg) { - Ref3DPtg ref3D = (Ref3DPtg)ptg; - return refWorkbookContext.GetRef3DEval(ref3D); + return refWorkbookContext.GetRef3DEval(rptg); } - else if (ptg is Ref3DPxg) + else if (ptg is Ref3DPxg ref3D) { - Ref3DPxg ref3D = (Ref3DPxg)ptg; return refWorkbookContext.GetRef3DEval(ref3D); } - else if (ptg is Area3DPtg) + else if (ptg is Area3DPtg aptg) { - Area3DPtg area3D = (Area3DPtg)ptg; - return refWorkbookContext.GetArea3DEval(area3D); + return refWorkbookContext.GetArea3DEval(aptg); } - else if (ptg is Area3DPxg) + else if (ptg is Area3DPxg area3D) { - Area3DPxg area3D = (Area3DPxg)ptg; return refWorkbookContext.GetArea3DEval(area3D); } diff --git a/main/SS/Formula/OperationEvaluatorFactory.cs b/main/SS/Formula/OperationEvaluatorFactory.cs index 80d9397c0..e532f5d86 100644 --- a/main/SS/Formula/OperationEvaluatorFactory.cs +++ b/main/SS/Formula/OperationEvaluatorFactory.cs @@ -96,9 +96,8 @@ public static ValueEval Evaluate(OperationPtg ptg, ValueEval[] args, FreeRefFunction udfFunc = null; if (result == null) { - if (ptg is AbstractFunctionPtg) + if (ptg is AbstractFunctionPtg fptg) { - AbstractFunctionPtg fptg = (AbstractFunctionPtg)ptg; int functionIndex = fptg.FunctionIndex; switch (functionIndex) { @@ -117,9 +116,8 @@ public static ValueEval Evaluate(OperationPtg ptg, ValueEval[] args, if (result != null) { - if (result is ArrayFunction) + if (result is ArrayFunction func) { - ArrayFunction func = (ArrayFunction)result; ValueEval eval = EvaluateArrayFunction(func, args, ec); if (eval != null) { diff --git a/main/SS/Formula/PTG/Area3DPxg.cs b/main/SS/Formula/PTG/Area3DPxg.cs index 515cc1d2f..7e907d8be 100644 --- a/main/SS/Formula/PTG/Area3DPxg.cs +++ b/main/SS/Formula/PTG/Area3DPxg.cs @@ -46,9 +46,9 @@ public Area3DPxg(int externalWorkbookNumber, SheetIdentifier sheetName, AreaRefe { this.externalWorkbookNumber = externalWorkbookNumber; this.firstSheetName = sheetName.SheetId.Name; - if (sheetName is SheetRangeIdentifier) + if (sheetName is SheetRangeIdentifier identifier) { - this.lastSheetName = ((SheetRangeIdentifier)sheetName).LastSheetIdentifier.Name; + this.lastSheetName = identifier.LastSheetIdentifier.Name; } else { diff --git a/main/SS/Formula/PTG/ArrayPtg.cs b/main/SS/Formula/PTG/ArrayPtg.cs index 752281c26..173542630 100644 --- a/main/SS/Formula/PTG/ArrayPtg.cs +++ b/main/SS/Formula/PTG/ArrayPtg.cs @@ -230,9 +230,9 @@ private static String GetConstantText(Object o) { return ""; // TODO - how is 'empty value' represented in formulas? } - if (o is String) + if (o is String s) { - return "\"" + (String)o + "\""; + return "\"" + s + "\""; } if (o is Double || o is double) { @@ -242,9 +242,9 @@ private static String GetConstantText(Object o) { return ((bool)o).ToString().ToUpper(); } - if (o is ErrorConstant) + if (o is ErrorConstant constant) { - return ((ErrorConstant)o).Text; + return constant.Text; } throw new ArgumentException("Unexpected constant class (" + o.GetType().Name + ")"); } diff --git a/main/SS/Formula/PTG/ExternSheetNameResolver.cs b/main/SS/Formula/PTG/ExternSheetNameResolver.cs index 3e08ac959..f2fbc6fe1 100644 --- a/main/SS/Formula/PTG/ExternSheetNameResolver.cs +++ b/main/SS/Formula/PTG/ExternSheetNameResolver.cs @@ -25,13 +25,12 @@ public static String PrependSheetName(IFormulaRenderingWorkbook book, int field_ sb = new StringBuilder(sheetName.Length + cellRefText.Length + 4); SheetNameFormatter.AppendFormat(sb, sheetName); } - if (externalSheet is ExternalSheetRange) + if (externalSheet is ExternalSheetRange range) { - ExternalSheetRange r = (ExternalSheetRange)externalSheet; - if (!r.FirstSheetName.Equals(r.LastSheetName)) + if (!range.FirstSheetName.Equals(range.LastSheetName)) { sb.Append(':'); - SheetNameFormatter.AppendFormat(sb, r.LastSheetName); + SheetNameFormatter.AppendFormat(sb, range.LastSheetName); } } } diff --git a/main/SS/Formula/PTG/Ref3DPxg.cs b/main/SS/Formula/PTG/Ref3DPxg.cs index 054b1d713..c1dd4d201 100644 --- a/main/SS/Formula/PTG/Ref3DPxg.cs +++ b/main/SS/Formula/PTG/Ref3DPxg.cs @@ -47,9 +47,9 @@ public Ref3DPxg(int externalWorkbookNumber, SheetIdentifier sheetName, CellRefer { this.externalWorkbookNumber = externalWorkbookNumber; this.firstSheetName = sheetName.SheetId.Name; - if (sheetName is SheetRangeIdentifier) + if (sheetName is SheetRangeIdentifier identifier) { - this.lastSheetName = ((SheetRangeIdentifier)sheetName).LastSheetIdentifier.Name; + this.lastSheetName = identifier.LastSheetIdentifier.Name; } else { diff --git a/main/SS/Formula/ParseNode.cs b/main/SS/Formula/ParseNode.cs index 69e7559b7..58f5ebfae 100644 --- a/main/SS/Formula/ParseNode.cs +++ b/main/SS/Formula/ParseNode.cs @@ -171,9 +171,8 @@ private void CollectIfPtgs(TokenCollector temp) private static bool IsIf(Ptg token) { - if (token is FuncVarPtg) + if (token is FuncVarPtg func) { - FuncVarPtg func = (FuncVarPtg)token; if (FunctionMetadataRegistry.FUNCTION_NAME_IF.Equals(func.Name)) { return true; diff --git a/main/SS/Formula/SharedFormula.cs b/main/SS/Formula/SharedFormula.cs index e9fb68004..d8b44147a 100644 --- a/main/SS/Formula/SharedFormula.cs +++ b/main/SS/Formula/SharedFormula.cs @@ -53,18 +53,16 @@ public Ptg[] ConvertSharedFormulas(Ptg[] ptgs, int formulaRow, int formulaColumn { originalOperandClass = ptg.PtgClass; } - if (ptg is RefPtgBase) + if (ptg is RefPtgBase refNPtg) { - RefPtgBase refNPtg = (RefPtgBase)ptg; ptg = new RefPtg(FixupRelativeRow(formulaRow, refNPtg.Row, refNPtg.IsRowRelative), FixupRelativeColumn(formulaColumn, refNPtg.Column, refNPtg.IsColRelative), refNPtg.IsRowRelative, refNPtg.IsColRelative); ptg.PtgClass = (originalOperandClass); } - else if (ptg is AreaPtgBase) + else if (ptg is AreaPtgBase areaNPtg) { - AreaPtgBase areaNPtg = (AreaPtgBase)ptg; ptg = new AreaPtg(FixupRelativeRow(formulaRow, areaNPtg.FirstRow, areaNPtg.IsFirstRowRelative), FixupRelativeRow(formulaRow, areaNPtg.LastRow, areaNPtg.IsLastRowRelative), FixupRelativeColumn(formulaColumn, areaNPtg.FirstColumn, areaNPtg.IsFirstColRelative), @@ -75,10 +73,10 @@ public Ptg[] ConvertSharedFormulas(Ptg[] ptgs, int formulaRow, int formulaColumn areaNPtg.IsLastColRelative); ptg.PtgClass = (originalOperandClass); } - else if (ptg is OperandPtg) + else if (ptg is OperandPtg operandPtg) { // Any subclass of OperandPtg is mutable, so it's safest to not share these instances. - ptg = ((OperandPtg)ptg).Copy(); + ptg = operandPtg.Copy(); } else { diff --git a/main/SS/Formula/SheetRefEvaluator.cs b/main/SS/Formula/SheetRefEvaluator.cs index 2d8cf28f1..004d1d561 100644 --- a/main/SS/Formula/SheetRefEvaluator.cs +++ b/main/SS/Formula/SheetRefEvaluator.cs @@ -85,10 +85,9 @@ public bool IsSubTotal(int rowIndex, int columnIndex) IEvaluationWorkbook wb = _bookEvaluator.Workbook; foreach (Ptg ptg in wb.GetFormulaTokens(cell)) { - if (ptg is FuncVarPtg) + if (ptg is FuncVarPtg varPtg) { - FuncVarPtg f = (FuncVarPtg)ptg; - if ("SUBTOTAL".Equals(f.Name)) + if ("SUBTOTAL".Equals(varPtg.Name)) { subtotal = true; break; diff --git a/main/SS/Formula/UserDefinedFunction.cs b/main/SS/Formula/UserDefinedFunction.cs index d9ddc3c23..8d1c08a4c 100644 --- a/main/SS/Formula/UserDefinedFunction.cs +++ b/main/SS/Formula/UserDefinedFunction.cs @@ -24,9 +24,9 @@ public ValueEval Evaluate(ValueEval[] args, OperationEvaluationContext ec) ValueEval nameArg = args[0]; String functionName = string.Empty ; - if (nameArg is FunctionNameEval) + if (nameArg is FunctionNameEval nameEval) { - functionName = ((FunctionNameEval)nameArg).FunctionName; + functionName = nameEval.FunctionName; } else { @@ -41,8 +41,7 @@ public ValueEval Evaluate(ValueEval[] args, OperationEvaluationContext ec) int nOutGoingArgs = nIncomingArgs - 1; ValueEval[] outGoingArgs = new ValueEval[nOutGoingArgs]; Array.Copy(args, 1, outGoingArgs, 0, nOutGoingArgs); - if (targetFunc is ArrayFunction) { - ArrayFunction func = (ArrayFunction)targetFunc; + if (targetFunc is ArrayFunction func) { ValueEval eval = OperationEvaluatorFactory.EvaluateArrayFunction(func, outGoingArgs, ec); if (eval != null) { diff --git a/main/SS/Formula/WorkbookEvaluator.cs b/main/SS/Formula/WorkbookEvaluator.cs index c9f9a2420..feaf68472 100644 --- a/main/SS/Formula/WorkbookEvaluator.cs +++ b/main/SS/Formula/WorkbookEvaluator.cs @@ -325,9 +325,8 @@ protected bool AdjustRegionRelativeReference(Ptg[] ptgs, CellReference target, C foreach(Ptg ptg in ptgs) { // base class for cell reference "things" - if (ptg is RefPtgBase) { - RefPtgBase reference = (RefPtgBase)ptg; - // re-calculate cell references + if (ptg is RefPtgBase reference) { + // re-calculate cell references SpreadsheetVersion version = _workbook.GetSpreadsheetVersion(); if (reference.IsRowRelative) { @@ -561,9 +560,8 @@ public ValueEval EvaluateFormula(OperationEvaluationContext ec, Ptg[] ptgs) { EVAL_LOG.Log(POILogger.INFO, dbgIndentStr + " * ptg " + i + ": " + ptg.ToString()+", stack:"+stack); } - if (ptg is AttrPtg) + if (ptg is AttrPtg attrPtg) { - AttrPtg attrPtg = (AttrPtg)ptg; if (attrPtg.IsSum) { // Excel prefers To encode 'SUM()' as a tAttr Token, but this evaluator @@ -630,10 +628,10 @@ public ValueEval EvaluateFormula(OperationEvaluationContext ec, Ptg[] ptgs) int dist = attrPtg.Data; i += CountTokensToBeSkipped(ptgs, i, dist); Ptg nextPtg = ptgs[i + 1]; - if (ptgs[i] is AttrPtg && nextPtg is FuncVarPtg && + if (ptgs[i] is AttrPtg && nextPtg is FuncVarPtg varPtg && // in order to verify that there is no third param, we need to check // if we really have the IF next or some other FuncVarPtg as third param, e.g. ROW()/COLUMN()! - ((FuncVarPtg)nextPtg).FunctionIndex == FunctionMetadataRegistry.FUNCTION_INDEX_IF) + varPtg.FunctionIndex == FunctionMetadataRegistry.FUNCTION_INDEX_IF) { // this is an if statement without a false param (as opposed to MissingArgPtg as the false param) //i++; @@ -678,10 +676,8 @@ public ValueEval EvaluateFormula(OperationEvaluationContext ec, Ptg[] ptgs) continue; } ValueEval opResult; - if (ptg is OperationPtg) + if (ptg is OperationPtg optg) { - OperationPtg optg = (OperationPtg)ptg; - if (optg is UnionPtg) { continue; } int numops = optg.NumberOfOperands; @@ -816,9 +812,9 @@ public static ValueEval DereferenceResult(ValueEval evaluationResult, OperationE IEvaluationSheet evalSheet = ec.GetWorkbook().GetSheet(ec.SheetIndex); IEvaluationCell evalCell = evalSheet.GetCell(ec.RowIndex, ec.ColumnIndex); - if (evalCell.IsPartOfArrayFormulaGroup && evaluationResult is AreaEval) + if (evalCell.IsPartOfArrayFormulaGroup && evaluationResult is AreaEval eval) { - value = OperandResolver.GetElementFromArray((AreaEval)evaluationResult, evalCell); + value = OperandResolver.GetElementFromArray(eval, evalCell); } else { @@ -837,42 +833,41 @@ private ValueEval GetEvalForPtg(Ptg ptg, OperationEvaluationContext ec) { // consider converting all these (ptg is XxxPtg) expressions To (ptg.GetType() == XxxPtg.class) - if (ptg is NamePtg) + if (ptg is NamePtg namePtg) { // Named ranges, macro functions - NamePtg namePtg = (NamePtg)ptg; IEvaluationName nameRecord = _workbook.GetName(namePtg); return GetEvalForNameRecord(nameRecord, ec); } - if (ptg is NameXPtg) + if (ptg is NameXPtg xPtg) { // Externally defined named ranges or macro functions - return ProcessNameEval(ec.GetNameXEval((NameXPtg)ptg), ec); + return ProcessNameEval(ec.GetNameXEval(xPtg), ec); } - if (ptg is NameXPxg) + if (ptg is NameXPxg pxg) { // Externally defined named ranges or macro functions - return ProcessNameEval(ec.GetNameXEval((NameXPxg)ptg), ec); + return ProcessNameEval(ec.GetNameXEval(pxg), ec); } - if (ptg is IntPtg) + if (ptg is IntPtg intPtg) { - return new NumberEval(((IntPtg)ptg).Value); + return new NumberEval(intPtg.Value); } - if (ptg is NumberPtg) + if (ptg is NumberPtg numberPtg) { - return new NumberEval(((NumberPtg)ptg).Value); + return new NumberEval(numberPtg.Value); } - if (ptg is StringPtg) + if (ptg is StringPtg stringPtg) { - return new StringEval(((StringPtg)ptg).Value); + return new StringEval(stringPtg.Value); } - if (ptg is BoolPtg) + if (ptg is BoolPtg boolPtg) { - return BoolEval.ValueOf(((BoolPtg)ptg).Value); + return BoolEval.ValueOf(boolPtg.Value); } - if (ptg is ErrPtg) + if (ptg is ErrPtg errPtg) { - return ErrorEval.ValueOf(((ErrPtg)ptg).ErrorCode); + return ErrorEval.ValueOf(errPtg.ErrorCode); } if (ptg is MissingArgPtg) { @@ -883,34 +878,31 @@ private ValueEval GetEvalForPtg(Ptg ptg, OperationEvaluationContext ec) { return ErrorEval.REF_INVALID; } - if (ptg is Ref3DPtg) + if (ptg is Ref3DPtg ref3DPtg) { - return ec.GetRef3DEval((Ref3DPtg)ptg); + return ec.GetRef3DEval(ref3DPtg); } - if (ptg is Ref3DPxg) + if (ptg is Ref3DPxg ref3DPxg) { - return ec.GetRef3DEval((Ref3DPxg)ptg); + return ec.GetRef3DEval(ref3DPxg); } - if (ptg is Area3DPtg) { - return ec.GetArea3DEval((Area3DPtg)ptg); + if (ptg is Area3DPtg area3DPtg) { + return ec.GetArea3DEval(area3DPtg); } - if (ptg is Area3DPxg) { - return ec.GetArea3DEval((Area3DPxg)ptg); + if (ptg is Area3DPxg area3DPxg) { + return ec.GetArea3DEval(area3DPxg); } - if (ptg is RefPtg) + if (ptg is RefPtg rptg) { - RefPtg rptg = (RefPtg)ptg; return ec.GetRefEval(rptg.Row, rptg.Column); } - if (ptg is AreaPtg) + if (ptg is AreaPtg areaPtg) { - AreaPtg aptg = (AreaPtg)ptg; - return ec.GetAreaEval(aptg.FirstRow, aptg.FirstColumn, aptg.LastRow, aptg.LastColumn); + return ec.GetAreaEval(areaPtg.FirstRow, areaPtg.FirstColumn, areaPtg.LastRow, areaPtg.LastColumn); } - if (ptg is ArrayPtg) { - ArrayPtg aptg = (ArrayPtg)ptg; + if (ptg is ArrayPtg aptg) { return ec.GetAreaValueEval(0, 0, aptg.RowCount - 1, aptg.ColumnCount - 1, aptg.GetTokenArrayValues()); } @@ -932,9 +924,9 @@ private ValueEval GetEvalForPtg(Ptg ptg, OperationEvaluationContext ec) private ValueEval ProcessNameEval(ValueEval eval, OperationEvaluationContext ec) { - if (eval is ExternalNameEval) + if (eval is ExternalNameEval nameEval) { - IEvaluationName name = ((ExternalNameEval)eval).Name; + IEvaluationName name = nameEval.Name; return GetEvalForNameRecord(name, ec); } return eval; diff --git a/main/SS/UserModel/ConditionType.cs b/main/SS/UserModel/ConditionType.cs index 566ece21d..7f31e57a6 100644 --- a/main/SS/UserModel/ConditionType.cs +++ b/main/SS/UserModel/ConditionType.cs @@ -63,9 +63,8 @@ public override int GetHashCode() public override bool Equals(object obj) { - if (obj == null || !(obj is ConditionType)) + if (obj == null || obj is not ConditionType other) return false; - ConditionType other = obj as ConditionType; return this.Id == other.Id && this.Type == other.Type; } diff --git a/main/SS/UserModel/ConditionalFormattingThreshold.cs b/main/SS/UserModel/ConditionalFormattingThreshold.cs index 8d739a456..7183c4ebd 100644 --- a/main/SS/UserModel/ConditionalFormattingThreshold.cs +++ b/main/SS/UserModel/ConditionalFormattingThreshold.cs @@ -120,11 +120,11 @@ public override string ToString() } public override bool Equals(object obj) { - if (obj == null || !(obj is RangeType)) + if (obj == null || obj is not RangeType other) { return false; } - RangeType other = obj as RangeType; + return this.id == other.id && this.name == other.name; } diff --git a/main/SS/UserModel/DataFormatter.cs b/main/SS/UserModel/DataFormatter.cs index 0481eecb1..ef3fee3c3 100644 --- a/main/SS/UserModel/DataFormatter.cs +++ b/main/SS/UserModel/DataFormatter.cs @@ -951,10 +951,10 @@ public string FormatRawCellContents(double value, int formatIndex, string format { FormatBase dateFormat = GetFormat(value, formatIndex, formatString); - if (dateFormat is ExcelStyleDateFormatter) + if (dateFormat is ExcelStyleDateFormatter formatter) { // Hint about the raw excel value - ((ExcelStyleDateFormatter)dateFormat).SetDateToBeFormatted(value); + formatter.SetDateToBeFormatted(value); } DateTime d = DateUtil.GetJavaDate(value, use1904Windowing); @@ -1150,8 +1150,7 @@ public void AddFormat(string excelformatStr, FormatBase format) */ public void Update(IObservable observable, object localeObj) { - if (localeObj is not CultureInfo) return; - CultureInfo newLocale = (CultureInfo)localeObj; + if (localeObj is not CultureInfo newLocale) return; if (newLocale.Equals(currentCulture)) return; currentCulture = newLocale; diff --git a/main/SS/UserModel/ExcelStyleDateFormatter.cs b/main/SS/UserModel/ExcelStyleDateFormatter.cs index 0da43fb23..89b9869ba 100644 --- a/main/SS/UserModel/ExcelStyleDateFormatter.cs +++ b/main/SS/UserModel/ExcelStyleDateFormatter.cs @@ -216,11 +216,10 @@ public StringBuilder Format(DateTime date, StringBuilder paramStringBuilder, Cul public override bool Equals(Object o) { - if (!(o is ExcelStyleDateFormatter)) { + if (o is not ExcelStyleDateFormatter other) { return false; } - ExcelStyleDateFormatter other = (ExcelStyleDateFormatter)o; return dateToBeFormatted == other.dateToBeFormatted; } diff --git a/main/SS/UserModel/Helpers/BaseRowColShifter.cs b/main/SS/UserModel/Helpers/BaseRowColShifter.cs index ed9b3fa11..973b229c5 100644 --- a/main/SS/UserModel/Helpers/BaseRowColShifter.cs +++ b/main/SS/UserModel/Helpers/BaseRowColShifter.cs @@ -57,9 +57,8 @@ public static CellRangeAddress ShiftRange(FormulaShifter Shifter, CellRangeAddre return cra; } Ptg ptg0 = ptgs[0]; - if (ptg0 is AreaPtg) + if (ptg0 is AreaPtg bptg) { - AreaPtg bptg = (AreaPtg)ptg0; return new CellRangeAddress(bptg.FirstRow, bptg.LastRow, bptg.FirstColumn, bptg.LastColumn); } if (ptg0 is AreaErrPtg) diff --git a/main/SS/Util/CellAddress.cs b/main/SS/Util/CellAddress.cs index 327a64a07..592868d9a 100644 --- a/main/SS/Util/CellAddress.cs +++ b/main/SS/Util/CellAddress.cs @@ -175,14 +175,13 @@ public override bool Equals(Object o) { return true; } - if (!(o is CellAddress)) + if (o is not CellAddress other) { return false; } - CellAddress other = (CellAddress)o; return _row == other._row - && _col == other._col + && _col == other._col ; } diff --git a/main/SS/Util/CellRangeAddressBase.cs b/main/SS/Util/CellRangeAddressBase.cs index ee63ae5c6..f0baafded 100644 --- a/main/SS/Util/CellRangeAddressBase.cs +++ b/main/SS/Util/CellRangeAddressBase.cs @@ -250,12 +250,11 @@ public int MaxColumn public override bool Equals(Object other) { - if (other is CellRangeAddressBase) { - CellRangeAddressBase o = (CellRangeAddressBase)other; - return ((MinRow == o.MinRow) && - (MaxRow == o.MaxRow) && - (MinColumn == o.MinColumn) && - (MaxColumn == o.MaxColumn)); + if (other is CellRangeAddressBase @base) { + return ((MinRow == @base.MinRow) && + (MaxRow == @base.MaxRow) && + (MinColumn == @base.MinColumn) && + (MaxColumn == @base.MaxColumn)); } return false; } diff --git a/main/SS/Util/CellReference.cs b/main/SS/Util/CellReference.cs index 0546e8255..370220227 100644 --- a/main/SS/Util/CellReference.cs +++ b/main/SS/Util/CellReference.cs @@ -602,18 +602,18 @@ public override bool Equals(Object o) { if (object.ReferenceEquals(this, o)) return true; - if (!(o is CellReference)) + if (o is not CellReference cr) { return false; } - CellReference cr = (CellReference)o; + return _rowIndex == cr._rowIndex - && _colIndex == cr._colIndex - && _isRowAbs == cr._isRowAbs - && _isColAbs == cr._isColAbs - && ((_sheetName == null) - ? (cr._sheetName == null) - : _sheetName.Equals(cr._sheetName)); + && _colIndex == cr._colIndex + && _isRowAbs == cr._isRowAbs + && _isColAbs == cr._isColAbs + && ((_sheetName == null) + ? (cr._sheetName == null) + : _sheetName.Equals(cr._sheetName)); } public override int GetHashCode () diff --git a/main/SS/Util/CellUtil.cs b/main/SS/Util/CellUtil.cs index a64dcba76..881489745 100644 --- a/main/SS/Util/CellUtil.cs +++ b/main/SS/Util/CellUtil.cs @@ -669,9 +669,9 @@ private static BorderStyle GetBorderStyle(Dictionary properties, { Object value = properties[name]; BorderStyle border; - if (value is BorderStyle) + if (value is BorderStyle style) { - border = (BorderStyle)value; + border = style; } // @deprecated 3.15 beta 2. getBorderStyle will only work on BorderStyle enums instead of codes in the future. else if (value is short || value is int) @@ -707,19 +707,18 @@ private static FillPattern GetFillPattern(Dictionary properties, { Object value = properties[name]; FillPattern pattern; - if (value is FillPattern) + if (value is FillPattern fillPattern) { - pattern = (FillPattern)value; + pattern = fillPattern; } // @deprecated 3.15 beta 2. getFillPattern will only work on FillPattern enums instead of codes in the future. - else if (value is short) + else if (value is short code) { //if (log.check(POILogger.WARN)) //{ // log.log(POILogger.WARN, "Deprecation warning: CellUtil properties map uses Short values for " // + name + ". Should use FillPattern enums instead."); //} - short code = (short)value; pattern = (FillPattern)code; } else if (value == null) @@ -745,19 +744,18 @@ private static HorizontalAlignment GetHorizontalAlignment(Dictionary { Object value = properties[name]; VerticalAlignment align; - if (value is VerticalAlignment) + if (value is VerticalAlignment alignment) { - align = (VerticalAlignment)value; + align = alignment; } // @deprecated 3.15 beta 2. getVerticalAlignment will only work on VerticalAlignment enums instead of codes in the future. - else if (value is short) + else if (value is short code) { //if (log.check(POILogger.WARN)) //{ // log.log(POILogger.WARN, "Deprecation warning: CellUtil properties map used a Short value for " // + name + ". Should use VerticalAlignment enums instead."); //} - short code = (short)value; align = (VerticalAlignment)code; } else if (value == null) diff --git a/main/SS/Util/PropertyTemplate.cs b/main/SS/Util/PropertyTemplate.cs index 8b484c11f..7e0c59e6c 100644 --- a/main/SS/Util/PropertyTemplate.cs +++ b/main/SS/Util/PropertyTemplate.cs @@ -989,9 +989,9 @@ public BorderStyle GetBorderStyle(CellAddress cell, String property) if(cellProperties != null) { object obj = cellProperties.TryGetValue(property, out object cellProperty) ? cellProperty : null; - if(obj is BorderStyle) + if(obj is BorderStyle style) { - value = (BorderStyle) obj; + value = style; } } return value; @@ -1047,9 +1047,9 @@ public short GetTemplateProperty(int row, int col, String property) /// short value, or 0 if not a short private static short Getshort(object value) { - if(value is short) + if(value is short s) { - return (short) value; + return s; } return 0; } diff --git a/main/SS/Util/SheetBuilder.cs b/main/SS/Util/SheetBuilder.cs index f418dbc2d..f08901bb3 100644 --- a/main/SS/Util/SheetBuilder.cs +++ b/main/SS/Util/SheetBuilder.cs @@ -137,9 +137,9 @@ private void SetCellValue(ICell cell, Object value) double.TryParse(value.ToString(), out val); cell.SetCellValue(val); } - else if (value is DateTime) + else if (value is DateTime time) { - cell.SetCellValue((DateTime)value); + cell.SetCellValue(time); //} else if (value is Calendar) { // cell.SetCellValue((Calendar) value); } @@ -155,16 +155,15 @@ private void SetCellValue(ICell cell, Object value) private bool IsFormulaDefinition(Object obj) { - if (obj is String) + if (obj is String str) { - String str = (String)obj; if (str.Length < 2) { return false; } else { - return ((String)obj)[0] == '='; + return str[0] == '='; } } else diff --git a/main/Util/Arrays.cs b/main/Util/Arrays.cs index 0a70bf058..d068faaf9 100644 --- a/main/Util/Arrays.cs +++ b/main/Util/Arrays.cs @@ -608,24 +608,24 @@ public static int DeepHashCode(Object[] a) { foreach (Object element in a) { int elementHash = 0; - if (element is Object[]) - elementHash = DeepHashCode((Object[]) element); - else if (element is byte[]) - elementHash = HashCode((byte[]) element); - else if (element is short[]) - elementHash = HashCode((short[]) element); - else if (element is int[]) - elementHash = HashCode((int[]) element); - else if (element is long[]) - elementHash = HashCode((long[]) element); - else if (element is char[]) - elementHash = HashCode((char[]) element); - else if (element is float[]) - elementHash = HashCode((float[]) element); - else if (element is double[]) - elementHash = HashCode((double[]) element); - else if (element is bool[]) - elementHash = HashCode((bool[]) element); + if (element is Object[] objects) + elementHash = DeepHashCode(objects); + else if (element is byte[] bytes) + elementHash = HashCode(bytes); + else if (element is short[] shorts) + elementHash = HashCode(shorts); + else if (element is int[] ints) + elementHash = HashCode(ints); + else if (element is long[] longs) + elementHash = HashCode(longs); + else if (element is char[] chars) + elementHash = HashCode(chars); + else if (element is float[] floats) + elementHash = HashCode(floats); + else if (element is double[] doubles) + elementHash = HashCode(doubles); + else if (element is bool[] bools) + elementHash = HashCode(bools); else if (element != null) elementHash = element.GetHashCode(); @@ -699,24 +699,24 @@ public static bool DeepEquals(Object[] a1, Object[] a2) { static bool DeepEquals0(Object e1, Object e2) { bool eq; - if (e1 is Object[] && e2 is Object[]) - eq = DeepEquals ((Object[]) e1, (Object[]) e2); - else if (e1 is byte[] && e2 is byte[]) - eq = Equals((byte[]) e1, (byte[]) e2); - else if (e1 is short[] && e2 is short[]) - eq = Equals((short[]) e1, (short[]) e2); - else if (e1 is int[] && e2 is int[]) - eq = Equals((int[]) e1, (int[]) e2); - else if (e1 is long[] && e2 is long[]) - eq = Equals((long[]) e1, (long[]) e2); - else if (e1 is char[] && e2 is char[]) - eq = Equals((char[]) e1, (char[]) e2); - else if (e1 is float[] && e2 is float[]) - eq = Equals((float[]) e1, (float[]) e2); - else if (e1 is double[] && e2 is double[]) - eq = Equals((double[]) e1, (double[]) e2); - else if (e1 is bool[] && e2 is bool[]) - eq = Equals((bool[]) e1, (bool[]) e2); + if (e1 is Object[] objects && e2 is Object[] e3) + eq = DeepEquals (objects, e3); + else if (e1 is byte[] bytes && e2 is byte[] bytes1) + eq = Equals(bytes, bytes1); + else if (e1 is short[] shorts && e2 is short[] shorts1) + eq = Equals(shorts, shorts1); + else if (e1 is int[] ints && e2 is int[] ints1) + eq = Equals(ints, ints1); + else if (e1 is long[] longs && e2 is long[] longs1) + eq = Equals(longs, longs1); + else if (e1 is char[] chars && e2 is char[] chars1) + eq = Equals(chars, chars1); + else if (e1 is float[] floats && e2 is float[] floats1) + eq = Equals(floats, floats1); + else if (e1 is double[] doubles && e2 is double[] doubles1) + eq = Equals(doubles, doubles1); + else if (e1 is bool[] bools && e2 is bool[] bools1) + eq = Equals(bools, bools1); else eq = e1.Equals(e2); return eq; diff --git a/main/Util/BigInteger.cs b/main/Util/BigInteger.cs index f8186acac..766b67831 100644 --- a/main/Util/BigInteger.cs +++ b/main/Util/BigInteger.cs @@ -1172,10 +1172,9 @@ public override bool Equals(object x) if (Object.ReferenceEquals(x, this)) return true; - if (!(x is BigInteger) || (null == x)) + if (x is not BigInteger xInt || (null == x)) return false; - BigInteger xInt = (BigInteger)x; if (xInt._signum != _signum) return false; diff --git a/main/Util/IOUtils.cs b/main/Util/IOUtils.cs index 30223c314..1320634e2 100644 --- a/main/Util/IOUtils.cs +++ b/main/Util/IOUtils.cs @@ -91,8 +91,8 @@ public static byte[] PeekFirstNBytes(Stream stream, int limit) long mark = stream.Position; ByteArrayOutputStream bos = new ByteArrayOutputStream(limit); - if(stream is ByteArrayInputStream) - Copy(new BoundedInputStream((ByteArrayInputStream) stream, limit), bos); + if(stream is ByteArrayInputStream inputStream) + Copy(new BoundedInputStream(inputStream, limit), bos); else { MemoryStream ms = new MemoryStream(); diff --git a/ooxml/POIFS/Crypt/Dsig/SignatureConfig.cs b/ooxml/POIFS/Crypt/Dsig/SignatureConfig.cs index 5c085f330..d4df58896 100644 --- a/ooxml/POIFS/Crypt/Dsig/SignatureConfig.cs +++ b/ooxml/POIFS/Crypt/Dsig/SignatureConfig.cs @@ -146,9 +146,9 @@ protected internal void Init(bool onlyValidation) { uriDereferencer = new OOXMLURIDereferencer(); } - if (uriDereferencer is ISignatureConfigurable) + if (uriDereferencer is ISignatureConfigurable configurable) { - ((ISignatureConfigurable)uriDereferencer).SetSignatureConfig(this); + configurable.SetSignatureConfig(this); } if (namespacePrefixes.Count == 0) { @@ -167,9 +167,9 @@ protected internal void Init(bool onlyValidation) signatureMarshalListener = new SignatureMarshalListener(); } - if (signatureMarshalListener is ISignatureConfigurable) + if (signatureMarshalListener is ISignatureConfigurable signatureConfigurable) { - ((ISignatureConfigurable)signatureMarshalListener).SetSignatureConfig(this); + signatureConfigurable.SetSignatureConfig(this); } if (tspService != null) diff --git a/ooxml/SS/Converter/ExcelToHtmlConverter.cs b/ooxml/SS/Converter/ExcelToHtmlConverter.cs index c3f8bc6c1..d71c0a42a 100644 --- a/ooxml/SS/Converter/ExcelToHtmlConverter.cs +++ b/ooxml/SS/Converter/ExcelToHtmlConverter.cs @@ -226,9 +226,9 @@ protected void ProcessSheetHeader(XmlElement htmlBody, ISheet sheet) protected void ProcessDocumentInformation(IWorkbook workbook) { - if (workbook is NPOI.HSSF.UserModel.HSSFWorkbook) + if (workbook is NPOI.HSSF.UserModel.HSSFWorkbook hssfWorkbook) { - SummaryInformation summaryInformation = ((HSSFWorkbook)workbook).SummaryInformation; + SummaryInformation summaryInformation = hssfWorkbook.SummaryInformation; if (summaryInformation != null) { if (!string.IsNullOrEmpty(summaryInformation.Title)) @@ -244,9 +244,9 @@ protected void ProcessDocumentInformation(IWorkbook workbook) htmlDocumentFacade.AddDescription(summaryInformation.Comments); } } - else if(workbook is NPOI.XSSF.UserModel.XSSFWorkbook) + else if(workbook is NPOI.XSSF.UserModel.XSSFWorkbook xssfWorkbook) { - POIXMLProperties props=((NPOI.XSSF.UserModel.XSSFWorkbook)workbook).GetProperties(); + POIXMLProperties props=xssfWorkbook.GetProperties(); if (!string.IsNullOrEmpty(props.CoreProperties.Title)) { htmlDocumentFacade.Title = props.CoreProperties.Title; @@ -645,9 +645,9 @@ protected String BuildStyle(IWorkbook workbook, ICellStyle cellStyle) { StringBuilder style = new StringBuilder(); - if (workbook is HSSFWorkbook) + if (workbook is HSSFWorkbook hssfWorkbook) { - HSSFPalette palette = ((HSSFWorkbook)workbook).GetCustomPalette(); + HSSFPalette palette = hssfWorkbook.GetCustomPalette(); style.Append("white-space: pre-wrap; "); ExcelToHtmlUtils.AppendAlign(style, cellStyle.Alignment); @@ -738,9 +738,9 @@ private void BuildStyle_Border(IWorkbook workbook, StringBuilder style, borderStyle.Append(' '); borderStyle.Append(ExcelToHtmlUtils.GetBorderStyle(xlsBorder)); - if (workbook is HSSFWorkbook) + if (workbook is HSSFWorkbook hssfWorkbook) { - var customPalette = ((HSSFWorkbook) workbook).GetCustomPalette(); + var customPalette = hssfWorkbook.GetCustomPalette(); HSSFColor color = null; if (customPalette != null) color = customPalette.GetColor(borderColor); @@ -792,9 +792,9 @@ void BuildStyle_Font(IWorkbook workbook, StringBuilder style, break; } - if (workbook is HSSFWorkbook) + if (workbook is HSSFWorkbook hssfWorkbook) { - var customPalette = ((HSSFWorkbook) workbook).GetCustomPalette(); + var customPalette = hssfWorkbook.GetCustomPalette(); HSSFColor fontColor=null; if(customPalette!=null) fontColor = customPalette.GetColor(font.Color); diff --git a/ooxml/XSSF/Extractor/XSSFExcelExtractor.cs b/ooxml/XSSF/Extractor/XSSFExcelExtractor.cs index 2f5bdd1df..6165579b5 100644 --- a/ooxml/XSSF/Extractor/XSSFExcelExtractor.cs +++ b/ooxml/XSSF/Extractor/XSSFExcelExtractor.cs @@ -286,9 +286,9 @@ public override string Text { foreach (XSSFShape shape in drawing.GetShapes()) { - if (shape is XSSFSimpleShape) + if (shape is XSSFSimpleShape simpleShape) { - String boxText = ((XSSFSimpleShape)shape).Text; + String boxText = simpleShape.Text; if (boxText.Length > 0) { text.Append(boxText); diff --git a/ooxml/XSSF/Extractor/XSSFExportToXml.cs b/ooxml/XSSF/Extractor/XSSFExportToXml.cs index 69385ebd0..2fd0a1e35 100644 --- a/ooxml/XSSF/Extractor/XSSFExportToXml.cs +++ b/ooxml/XSSF/Extractor/XSSFExportToXml.cs @@ -318,9 +318,8 @@ private void mapCellOnNode(XSSFCell cell, XmlNode node) default: break; } - if (node is XmlElement) + if (node is XmlElement currentElement) { - XmlElement currentElement = (XmlElement)node; currentElement.InnerText = value; } else diff --git a/ooxml/XSSF/Streaming/SXSSFCell.cs b/ooxml/XSSF/Streaming/SXSSFCell.cs index 7ad952a67..e0ccca74a 100644 --- a/ooxml/XSSF/Streaming/SXSSFCell.cs +++ b/ooxml/XSSF/Streaming/SXSSFCell.cs @@ -488,9 +488,9 @@ public ICell SetCellValue(string value) } if (_value.GetType() == CellType.Formula) - if (_value is NumericFormulaValue) + if (_value is NumericFormulaValue formulaValue) { - ((NumericFormulaValue)_value).PreEvaluatedValue = Double.Parse(value); + formulaValue.PreEvaluatedValue = Double.Parse(value); } else { @@ -820,9 +820,9 @@ private void SetFormulaType(CellType type) } // if we had a Formula before, we should copy over the _value of the formula - if (prevValue is FormulaValue) + if (prevValue is FormulaValue value) { - ((FormulaValue)_value).Value = ((FormulaValue)prevValue).Value; + ((FormulaValue)_value).Value = value.Value; } } private CellType ComputeTypeFromFormula(String formula) diff --git a/ooxml/XSSF/Streaming/SXSSFFormulaEvaluator.cs b/ooxml/XSSF/Streaming/SXSSFFormulaEvaluator.cs index 4bdff1766..9f1158275 100644 --- a/ooxml/XSSF/Streaming/SXSSFFormulaEvaluator.cs +++ b/ooxml/XSSF/Streaming/SXSSFFormulaEvaluator.cs @@ -52,13 +52,13 @@ public static SXSSFFormulaEvaluator Create(SXSSFWorkbook workbook, IStabilityCla protected override IEvaluationCell ToEvaluationCell(ICell cell) { - if (!(cell is SXSSFCell)) + if (cell is not SXSSFCell sxssfCell) { throw new ArgumentException("Unexpected type of cell: " + cell.GetType() + "." + " Only SXSSFCells can be evaluated."); } - return new SXSSFEvaluationCell((SXSSFCell)cell); + return new SXSSFEvaluationCell(sxssfCell); } public static void EvaluateAllFormulaCells(SXSSFWorkbook wb, bool skipOutOfWindow) diff --git a/ooxml/XSSF/Streaming/SXSSFPicture.cs b/ooxml/XSSF/Streaming/SXSSFPicture.cs index efa03e320..a27cb7461 100644 --- a/ooxml/XSSF/Streaming/SXSSFPicture.cs +++ b/ooxml/XSSF/Streaming/SXSSFPicture.cs @@ -284,7 +284,7 @@ public IClientAnchor ClientAnchor get { XSSFAnchor a = GetAnchor(); - return (a is XSSFClientAnchor) ? (XSSFClientAnchor)a : null; + return (a is XSSFClientAnchor anchor) ? anchor : null; } } diff --git a/ooxml/XSSF/Streaming/SXSSFRow.cs b/ooxml/XSSF/Streaming/SXSSFRow.cs index 311864d2f..3887ded14 100644 --- a/ooxml/XSSF/Streaming/SXSSFRow.cs +++ b/ooxml/XSSF/Streaming/SXSSFRow.cs @@ -200,11 +200,10 @@ public int CompareTo(SXSSFRow other) public override bool Equals(Object obj) { - if (!(obj is SXSSFRow)) + if (obj is not SXSSFRow other) { return false; } - SXSSFRow other = (SXSSFRow)obj; return (this.RowNum == other.RowNum) && (this.Sheet == other.Sheet); diff --git a/ooxml/XSSF/UserModel/BaseXSSFFormulaEvaluator.cs b/ooxml/XSSF/UserModel/BaseXSSFFormulaEvaluator.cs index 6106cda3a..37171bdaf 100644 --- a/ooxml/XSSF/UserModel/BaseXSSFFormulaEvaluator.cs +++ b/ooxml/XSSF/UserModel/BaseXSSFFormulaEvaluator.cs @@ -62,24 +62,21 @@ protected override CellValue EvaluateFormulaCellValue(ICell cell) { IEvaluationCell evalCell = ToEvaluationCell(cell); ValueEval eval = _bookEvaluator.Evaluate(evalCell); - if (eval is NumberEval) + if (eval is NumberEval numberEval) { - NumberEval ne = (NumberEval)eval; - return new CellValue(ne.NumberValue); + return new CellValue(numberEval.NumberValue); } - if (eval is BoolEval) + if (eval is BoolEval be) { - BoolEval be = (BoolEval)eval; return CellValue.ValueOf(be.BooleanValue); } - if (eval is StringEval) + if (eval is StringEval ne) { - StringEval ne = (StringEval)eval; return new CellValue(ne.StringValue); } - if (eval is ErrorEval) + if (eval is ErrorEval errorEval) { - return CellValue.GetError(((ErrorEval)eval).ErrorCode); + return CellValue.GetError(errorEval.ErrorCode); } throw new Exception("Unexpected eval class (" + eval.GetType().Name + ")"); } diff --git a/ooxml/XSSF/UserModel/Charts/XSSFAreaChartData.cs b/ooxml/XSSF/UserModel/Charts/XSSFAreaChartData.cs index a6843a418..060ca3855 100644 --- a/ooxml/XSSF/UserModel/Charts/XSSFAreaChartData.cs +++ b/ooxml/XSSF/UserModel/Charts/XSSFAreaChartData.cs @@ -123,12 +123,11 @@ public List> GetSeries() public void FillChart(SS.UserModel.IChart chart, params IChartAxis[] axis) { - if (!(chart is XSSFChart)) + if (chart is not XSSFChart xssfChart) { throw new ArgumentException("Chart must be instance of XSSFChart"); } - XSSFChart xssfChart = (XSSFChart)chart; CT_PlotArea plotArea = xssfChart.GetCTChart().plotArea; int allSeriesCount = plotArea.GetAllSeriesCount(); CT_AreaChart areaChart = plotArea.AddNewAreaChart(); diff --git a/ooxml/XSSF/UserModel/Charts/XSSFBarChartData.cs b/ooxml/XSSF/UserModel/Charts/XSSFBarChartData.cs index 3a23cbc1f..9fe6a9e33 100644 --- a/ooxml/XSSF/UserModel/Charts/XSSFBarChartData.cs +++ b/ooxml/XSSF/UserModel/Charts/XSSFBarChartData.cs @@ -124,12 +124,11 @@ public List> GetSeries() public void FillChart(SS.UserModel.IChart chart, params IChartAxis[] axis) { - if (!(chart is XSSFChart)) + if (chart is not XSSFChart xssfChart) { throw new ArgumentException("Chart must be instance of XSSFChart"); } - XSSFChart xssfChart = (XSSFChart)chart; CT_PlotArea plotArea = xssfChart.GetCTChart().plotArea; int allSeriesCount = plotArea.GetAllSeriesCount(); CT_BarChart barChart = plotArea.AddNewBarChart(); diff --git a/ooxml/XSSF/UserModel/Charts/XSSFColumnChartData.cs b/ooxml/XSSF/UserModel/Charts/XSSFColumnChartData.cs index 89ff84d05..9e72b086c 100644 --- a/ooxml/XSSF/UserModel/Charts/XSSFColumnChartData.cs +++ b/ooxml/XSSF/UserModel/Charts/XSSFColumnChartData.cs @@ -124,12 +124,11 @@ public List> GetSeries() public void FillChart(SS.UserModel.IChart chart, params IChartAxis[] axis) { - if (!(chart is XSSFChart)) + if (chart is not XSSFChart xssfChart) { throw new ArgumentException("Chart must be instance of XSSFChart"); } - XSSFChart xssfChart = (XSSFChart)chart; CT_PlotArea plotArea = xssfChart.GetCTChart().plotArea; int allSeriesCount = plotArea.GetAllSeriesCount(); CT_BarChart barChart = plotArea.AddNewBarChart(); diff --git a/ooxml/XSSF/UserModel/Charts/XSSFLineChartData.cs b/ooxml/XSSF/UserModel/Charts/XSSFLineChartData.cs index 947cd4ba7..18773759f 100644 --- a/ooxml/XSSF/UserModel/Charts/XSSFLineChartData.cs +++ b/ooxml/XSSF/UserModel/Charts/XSSFLineChartData.cs @@ -117,12 +117,11 @@ public List> GetSeries() public void FillChart(SS.UserModel.IChart chart, params IChartAxis[] axis) { - if (!(chart is XSSFChart)) + if (chart is not XSSFChart xssfChart) { throw new ArgumentException("Chart must be instance of XSSFChart"); } - XSSFChart xssfChart = (XSSFChart)chart; CT_PlotArea plotArea = xssfChart.GetCTChart().plotArea; int allSeriesCount = plotArea.GetAllSeriesCount(); CT_LineChart lineChart = plotArea.AddNewLineChart(); diff --git a/ooxml/XSSF/UserModel/Charts/XSSFPieChartData.cs b/ooxml/XSSF/UserModel/Charts/XSSFPieChartData.cs index 779562f33..b7cb77925 100644 --- a/ooxml/XSSF/UserModel/Charts/XSSFPieChartData.cs +++ b/ooxml/XSSF/UserModel/Charts/XSSFPieChartData.cs @@ -119,12 +119,11 @@ public List> GetSeries() public void FillChart(SS.UserModel.IChart chart, params IChartAxis[] axis) { - if (!(chart is XSSFChart)) + if (chart is not XSSFChart xssfChart) { throw new ArgumentException("Chart must be instance of XSSFChart"); } - XSSFChart xssfChart = (XSSFChart)chart; CT_PlotArea plotArea = xssfChart.GetCTChart().plotArea; int allSeriesCount = plotArea.GetAllSeriesCount(); diff --git a/ooxml/XSSF/UserModel/Charts/XSSFScatterChartData.cs b/ooxml/XSSF/UserModel/Charts/XSSFScatterChartData.cs index 239bffd6c..f17d30633 100644 --- a/ooxml/XSSF/UserModel/Charts/XSSFScatterChartData.cs +++ b/ooxml/XSSF/UserModel/Charts/XSSFScatterChartData.cs @@ -147,12 +147,11 @@ public IScatterChartSeries AddSeries(IChartDataSource values) public void FillChart(IChart chart, IChartAxis[] axis) { - if (!(chart is XSSFChart)) + if (chart is not XSSFChart xssfChart) { throw new ArgumentException("Chart must be instance of XSSFChart"); } - XSSFChart xssfChart = (XSSFChart)chart; CT_PlotArea plotArea = xssfChart.GetCTChart().plotArea; int allSeriesCount = plotArea.GetAllSeriesCount(); CT_ScatterChart scatterChart = plotArea.AddNewScatterChart(); diff --git a/ooxml/XSSF/UserModel/Extensions/XSSFCellBorder.cs b/ooxml/XSSF/UserModel/Extensions/XSSFCellBorder.cs index 2c534bc66..199fc9b95 100644 --- a/ooxml/XSSF/UserModel/Extensions/XSSFCellBorder.cs +++ b/ooxml/XSSF/UserModel/Extensions/XSSFCellBorder.cs @@ -201,10 +201,9 @@ public override int GetHashCode() public override bool Equals(Object o) { - if (!(o is XSSFCellBorder)) return false; + if (o is not XSSFCellBorder cf) return false; //TODO: change the compare logic - XSSFCellBorder cf = (XSSFCellBorder)o; return border.ToString().Equals(cf.GetCTBorder().ToString()); } } diff --git a/ooxml/XSSF/UserModel/Extensions/XSSFCellFill.cs b/ooxml/XSSF/UserModel/Extensions/XSSFCellFill.cs index 83f531773..36656731f 100644 --- a/ooxml/XSSF/UserModel/Extensions/XSSFCellFill.cs +++ b/ooxml/XSSF/UserModel/Extensions/XSSFCellFill.cs @@ -173,9 +173,8 @@ public override int GetHashCode() public override bool Equals(object o) { - if (!(o is XSSFCellFill)) return false; + if (o is not XSSFCellFill cf) return false; - XSSFCellFill cf = (XSSFCellFill)o; return _fill.ToString().Equals(cf.GetCTFill().ToString()); } } diff --git a/ooxml/XSSF/UserModel/Helpers/XSSFFormulaUtils.cs b/ooxml/XSSF/UserModel/Helpers/XSSFFormulaUtils.cs index 02d58caec..4c88facd1 100644 --- a/ooxml/XSSF/UserModel/Helpers/XSSFFormulaUtils.cs +++ b/ooxml/XSSF/UserModel/Helpers/XSSFFormulaUtils.cs @@ -180,9 +180,8 @@ private void UpdateName(IName name, String oldName, String newName) private void UpdatePtg(Ptg ptg, String oldName, String newName) { - if (ptg is Pxg) + if (ptg is Pxg pxg) { - Pxg pxg = (Pxg)ptg; if (pxg.ExternalWorkbookNumber < 1) { if (pxg.SheetName != null && @@ -190,11 +189,10 @@ private void UpdatePtg(Ptg ptg, String oldName, String newName) { pxg.SheetName = (newName); } - if (pxg is Pxg3D) + if (pxg is Pxg3D pxg3D) { - Pxg3D pxg3D = (Pxg3D)pxg; if (pxg3D.LastSheetName != null && - pxg3D.LastSheetName.Equals(oldName)) + pxg3D.LastSheetName.Equals(oldName)) { pxg3D.LastSheetName = (/*setter*/newName); } diff --git a/ooxml/XSSF/UserModel/XSSFCellStyle.cs b/ooxml/XSSF/UserModel/XSSFCellStyle.cs index 849bcf6fc..0d70f9a2c 100644 --- a/ooxml/XSSF/UserModel/XSSFCellStyle.cs +++ b/ooxml/XSSF/UserModel/XSSFCellStyle.cs @@ -122,10 +122,8 @@ public void VerifyBelongsToStylesSource(StylesTable src) */ public void CloneStyleFrom(ICellStyle source) { - if (source is XSSFCellStyle) + if (source is XSSFCellStyle src) { - XSSFCellStyle src = (XSSFCellStyle)source; - // Is it on our Workbook? if (src._stylesSource == _stylesSource) { @@ -1351,9 +1349,8 @@ public override int GetHashCode() */ public override bool Equals(Object o) { - if (o == null || !(o is XSSFCellStyle)) return false; + if (o == null || o is not XSSFCellStyle cf) return false; - XSSFCellStyle cf = (XSSFCellStyle)o; return _cellXf.ToString().Equals(cf.GetCoreXf().ToString()); } diff --git a/ooxml/XSSF/UserModel/XSSFClientAnchor.cs b/ooxml/XSSF/UserModel/XSSFClientAnchor.cs index c5a89aa39..d38816fed 100644 --- a/ooxml/XSSF/UserModel/XSSFClientAnchor.cs +++ b/ooxml/XSSF/UserModel/XSSFClientAnchor.cs @@ -230,17 +230,16 @@ internal XSSFClientAnchor(CT_Marker cell1, CT_Marker cell2, int left, int top, i public override bool Equals(Object o) { - if (o == null || !(o is XSSFClientAnchor)) return false; + if (o == null || o is not XSSFClientAnchor anchor) return false; - XSSFClientAnchor anchor = (XSSFClientAnchor)o; return Dx1 == anchor.Dx1 && - Dx2 == anchor.Dx2 && - Dy1 == anchor.Dy1 && - Dy2 == anchor.Dy2 && - Col1 == anchor.Col1 && - Col2 == anchor.Col2 && - Row1 == anchor.Row1 && - Row2 == anchor.Row2; + Dx2 == anchor.Dx2 && + Dy1 == anchor.Dy1 && + Dy2 == anchor.Dy2 && + Col1 == anchor.Col1 && + Col2 == anchor.Col2 && + Row1 == anchor.Row1 && + Row2 == anchor.Row2; } diff --git a/ooxml/XSSF/UserModel/XSSFColor.cs b/ooxml/XSSF/UserModel/XSSFColor.cs index fdee0c540..35346e7d8 100644 --- a/ooxml/XSSF/UserModel/XSSFColor.cs +++ b/ooxml/XSSF/UserModel/XSSFColor.cs @@ -385,7 +385,7 @@ public static XSSFColor ToXSSFColor(IColor color) // FIXME: this method would be more useful if it could convert any Color to an XSSFColor // Currently the only benefit of this method is to throw an IllegalArgumentException // instead of a ClassCastException. - if (color != null && !(color is XSSFColor)) { + if (color != null && color is not XSSFColor) { throw new ArgumentException("Only XSSFColor objects are supported"); } return (XSSFColor)color; @@ -450,11 +450,9 @@ public override int GetHashCode() public override bool Equals(Object o) { - if (o == null || !(o is XSSFColor)) + if (o == null || o is not XSSFColor other) return false; - XSSFColor other = (XSSFColor)o; - // Compare each field in ctColor. // Cannot compare ctColor's XML string representation because equivalent // colors may have different relation namespace URI's diff --git a/ooxml/XSSF/UserModel/XSSFComment.cs b/ooxml/XSSF/UserModel/XSSFComment.cs index eb4129c0e..a513e615e 100644 --- a/ooxml/XSSF/UserModel/XSSFComment.cs +++ b/ooxml/XSSF/UserModel/XSSFComment.cs @@ -209,11 +209,11 @@ public IRichTextString String } set { - if (!(value is XSSFRichTextString)) + if (value is not XSSFRichTextString textString) { throw new ArgumentException("Only XSSFRichTextString argument is supported"); } - _str = (XSSFRichTextString)value; + _str = textString; _comment.text = (_str.GetCTRst()); } } @@ -260,10 +260,10 @@ internal CT_Shape GetCTShape() public override bool Equals(Object obj) { - if (!(obj is XSSFComment)) { + if (obj is not XSSFComment other) { return false; } - XSSFComment other = (XSSFComment)obj; + return ((GetCTComment() == other.GetCTComment()) && (GetCTShape() == other.GetCTShape())); } diff --git a/ooxml/XSSF/UserModel/XSSFDrawing.cs b/ooxml/XSSF/UserModel/XSSFDrawing.cs index 178547222..a2f07c8f2 100644 --- a/ooxml/XSSF/UserModel/XSSFDrawing.cs +++ b/ooxml/XSSF/UserModel/XSSFDrawing.cs @@ -443,9 +443,9 @@ public List GetCharts() List charts = new List(); foreach (POIXMLDocumentPart part in GetRelations()) { - if (part is XSSFChart) + if (part is XSSFChart chart) { - charts.Add((XSSFChart)part); + charts.Add(chart); } } return charts; @@ -523,25 +523,25 @@ public List GetShapes() foreach(var s in lstCtShapes) { XSSFShape gShape = null; - if(s is CT_Connector) + if(s is CT_Connector connector) { - gShape = new XSSFConnector(this, (CT_Connector)s); + gShape = new XSSFConnector(this, connector); } - else if(s is CT_Picture) + else if(s is CT_Picture picture) { - gShape = new XSSFPicture(this, (CT_Picture)s); + gShape = new XSSFPicture(this, picture); } - else if(s is CT_Shape) + else if(s is CT_Shape ctShape) { - gShape = new XSSFSimpleShape(this, (CT_Shape)s); + gShape = new XSSFSimpleShape(this, ctShape); } - else if(s is CT_GroupShape) + else if(s is CT_GroupShape groupShape) { - gShape = new XSSFShapeGroup(this, (CT_GroupShape)s); + gShape = new XSSFShapeGroup(this, groupShape); } - else if(s is CT_GraphicalObjectFrame) + else if(s is CT_GraphicalObjectFrame frame) { - gShape = new XSSFGraphicFrame(this, (CT_GraphicalObjectFrame)s); + gShape = new XSSFGraphicFrame(this, frame); } if(gShape != null) { @@ -595,14 +595,14 @@ public List GetShapes() private XSSFAnchor GetAnchorFromIEGAnchor(IEG_Anchor ctAnchor) { CT_Marker ctFrom=null, ctTo=null; - if (ctAnchor is CT_TwoCellAnchor) + if (ctAnchor is CT_TwoCellAnchor cellAnchor) { - ctFrom = ((CT_TwoCellAnchor)ctAnchor).from; - ctTo = ((CT_TwoCellAnchor)ctAnchor).to; + ctFrom = cellAnchor.from; + ctTo = cellAnchor.to; } - else if (ctAnchor is CT_OneCellAnchor) + else if (ctAnchor is CT_OneCellAnchor oneCellAnchor) { - ctFrom = ((CT_OneCellAnchor)ctAnchor).from; + ctFrom = oneCellAnchor.from; } XSSFAnchor anchor = new XSSFClientAnchor(ctFrom, ctTo); return anchor; diff --git a/ooxml/XSSF/UserModel/XSSFEvaluationSheet.cs b/ooxml/XSSF/UserModel/XSSFEvaluationSheet.cs index 17a6cf937..4375d0a9d 100644 --- a/ooxml/XSSF/UserModel/XSSFEvaluationSheet.cs +++ b/ooxml/XSSF/UserModel/XSSFEvaluationSheet.cs @@ -125,11 +125,10 @@ public override int GetHashCode() public override bool Equals(Object obj) { - if (obj == null || !(obj is CellKey)) + if (obj == null || obj is not CellKey oKey) return false; // assumes other object is one of us, otherwise ClassCastException is thrown - CellKey oKey = (CellKey)obj; return _row == oKey._row && _col == oKey._col; } } diff --git a/ooxml/XSSF/UserModel/XSSFFont.cs b/ooxml/XSSF/UserModel/XSSFFont.cs index 5bfcc57b5..18cb3e531 100644 --- a/ooxml/XSSF/UserModel/XSSFFont.cs +++ b/ooxml/XSSF/UserModel/XSSFFont.cs @@ -654,9 +654,8 @@ public override int GetHashCode() public override bool Equals(Object o) { - if (!(o is XSSFFont)) return false; + if (o is not XSSFFont cf) return false; - XSSFFont cf = (XSSFFont)o; return _ctFont.ToString().Equals(cf.GetCTFont().ToString()); } diff --git a/ooxml/XSSF/UserModel/XSSFFormulaEvaluator.cs b/ooxml/XSSF/UserModel/XSSFFormulaEvaluator.cs index bd70fb5af..7fdaf4b4f 100644 --- a/ooxml/XSSF/UserModel/XSSFFormulaEvaluator.cs +++ b/ooxml/XSSF/UserModel/XSSFFormulaEvaluator.cs @@ -107,12 +107,12 @@ public override void EvaluateAll() */ protected override IEvaluationCell ToEvaluationCell(ICell cell) { - if (!(cell is XSSFCell)){ + if (cell is not XSSFCell xssfCell){ throw new ArgumentException("Unexpected type of cell: " + cell.GetType().Name + "." + " Only XSSFCells can be evaluated."); } - return new XSSFEvaluationCell((XSSFCell)cell); + return new XSSFEvaluationCell(xssfCell); } } } \ No newline at end of file diff --git a/ooxml/XSSF/UserModel/XSSFHyperlink.cs b/ooxml/XSSF/UserModel/XSSFHyperlink.cs index 95a7f914c..ff4773b10 100644 --- a/ooxml/XSSF/UserModel/XSSFHyperlink.cs +++ b/ooxml/XSSF/UserModel/XSSFHyperlink.cs @@ -116,9 +116,8 @@ public XSSFHyperlink(CT_Hyperlink ctHyperlink, PackageRelationship hyperlinkRel) //FIXME: change to protected if/when SXSSFHyperlink class is created public XSSFHyperlink(IHyperlink other) { - if (other is XSSFHyperlink) + if (other is XSSFHyperlink xlink) { - XSSFHyperlink xlink = (XSSFHyperlink)other; _type = xlink.Type; _location = xlink._location; _externalRel = xlink._externalRel; diff --git a/ooxml/XSSF/UserModel/XSSFMap.cs b/ooxml/XSSF/UserModel/XSSFMap.cs index 3bcee79af..a1659f06a 100644 --- a/ooxml/XSSF/UserModel/XSSFMap.cs +++ b/ooxml/XSSF/UserModel/XSSFMap.cs @@ -83,10 +83,9 @@ public List GetRelatedSingleXMLCell() XSSFSheet sheet = (XSSFSheet)mapInfo.Workbook.GetSheetAt(i); foreach (POIXMLDocumentPart p in sheet.GetRelations()) { - if (p is SingleXmlCells) + if (p is SingleXmlCells singleXmlCells) { - SingleXmlCells SingleXMLCells = (SingleXmlCells)p; - foreach (XSSFSingleXmlCell cell in SingleXMLCells.GetAllSimpleXmlCell()) + foreach (XSSFSingleXmlCell cell in singleXmlCells.GetAllSimpleXmlCell()) { if (cell.GetMapId() == ctMap.ID) { diff --git a/ooxml/XSSF/UserModel/XSSFName.cs b/ooxml/XSSF/UserModel/XSSFName.cs index 8f22d3094..6af4eb9a5 100644 --- a/ooxml/XSSF/UserModel/XSSFName.cs +++ b/ooxml/XSSF/UserModel/XSSFName.cs @@ -347,9 +347,8 @@ public override bool Equals(Object o) { if (o == this) return true; - if (!(o is XSSFName)) return false; + if (o is not XSSFName cf) return false; - XSSFName cf = (XSSFName)o; return _ctName.name == cf.GetCTName().name && _ctName.localSheetId == cf.GetCTName().localSheetId && _ctName.Value==cf.RefersToFormula ; } diff --git a/ooxml/XSSF/UserModel/XSSFPicture.cs b/ooxml/XSSF/UserModel/XSSFPicture.cs index ae6577c3b..1dd97119d 100644 --- a/ooxml/XSSF/UserModel/XSSFPicture.cs +++ b/ooxml/XSSF/UserModel/XSSFPicture.cs @@ -374,7 +374,7 @@ public IClientAnchor ClientAnchor get { XSSFAnchor a = GetAnchor() as XSSFAnchor; - return (a is XSSFClientAnchor) ? (XSSFClientAnchor)a : null; + return (a is XSSFClientAnchor clientAnchor) ? clientAnchor : null; } } diff --git a/ooxml/XSSF/UserModel/XSSFRow.cs b/ooxml/XSSF/UserModel/XSSFRow.cs index 239bec848..3c4410735 100644 --- a/ooxml/XSSF/UserModel/XSSFRow.cs +++ b/ooxml/XSSF/UserModel/XSSFRow.cs @@ -673,13 +673,11 @@ public int CompareTo(XSSFRow other) public override bool Equals(object obj) { - if (!(obj is XSSFRow)) + if (obj is not XSSFRow other) { return false; } - XSSFRow other = (XSSFRow)obj; - return (RowNum == other.RowNum) && (Sheet == other.Sheet); } diff --git a/ooxml/XSSF/UserModel/XSSFShapeGroup.cs b/ooxml/XSSF/UserModel/XSSFShapeGroup.cs index f818f3c0e..55a7df0d9 100644 --- a/ooxml/XSSF/UserModel/XSSFShapeGroup.cs +++ b/ooxml/XSSF/UserModel/XSSFShapeGroup.cs @@ -285,7 +285,7 @@ public void AutoFit(SS.UserModel.ISheet Sheet) { if(parent == null) { // top level group var ac = new XSSFClientAnchor(Sheet, (int)min.x, (int)min.y, (int)max.x, (int)max.y); - if(cellanchor is CT_TwoCellAnchor) { + if(cellanchor is CT_TwoCellAnchor cellAnchor) { ((CT_TwoCellAnchor) cellanchor).from = ac.From; ((CT_TwoCellAnchor) cellanchor).to= ac.To; } diff --git a/ooxml/XSSF/UserModel/XSSFSheet.cs b/ooxml/XSSF/UserModel/XSSFSheet.cs index d1b61c57a..7aeece652 100644 --- a/ooxml/XSSF/UserModel/XSSFSheet.cs +++ b/ooxml/XSSF/UserModel/XSSFSheet.cs @@ -4826,7 +4826,7 @@ private List GetRows(int startRowNum, int endRowNum, bool createRowIfMi { for(int i = startRowNum; i <= endRowNum; i++) { - if(!(GetRow(i) is XSSFRow row)) + if(GetRow(i) is not XSSFRow row) { row = CreateRow(i) as XSSFRow; } @@ -5751,7 +5751,7 @@ private static string GetReferenceBuiltInRecord( private CellRangeAddress GetRepeatingRowsOrColums(bool rows) { int sheetIndex = Workbook.GetSheetIndex(this); - if(!(Workbook is XSSFWorkbook xwb)) + if(Workbook is not XSSFWorkbook xwb) { throw new RuntimeException("Workbook should not be null"); } @@ -5833,7 +5833,7 @@ private void SetRepeatingRowsAndColumns( int sheetIndex = Workbook.GetSheetIndex(this); bool removeAll = rowDef == null && colDef == null; - if(!(Workbook is XSSFWorkbook xwb)) + if(Workbook is not XSSFWorkbook xwb) { throw new RuntimeException("Workbook should not be null"); } diff --git a/ooxml/XSSF/UserModel/XSSFTextParagraph.cs b/ooxml/XSSF/UserModel/XSSFTextParagraph.cs index 27f32bbbe..4f9679df7 100644 --- a/ooxml/XSSF/UserModel/XSSFTextParagraph.cs +++ b/ooxml/XSSF/UserModel/XSSFTextParagraph.cs @@ -42,25 +42,22 @@ public XSSFTextParagraph(CT_TextParagraph p, CT_Shape ctShape) _Runs = new List(); foreach (object ch in _p.r) { - if (ch is CT_RegularTextRun) + if (ch is CT_RegularTextRun run) { - CT_RegularTextRun r = (CT_RegularTextRun)ch; - _Runs.Add(new XSSFTextRun(r, this)); + _Runs.Add(new XSSFTextRun(run, this)); } - else if (ch is CT_TextLineBreak) + else if (ch is CT_TextLineBreak br) { - CT_TextLineBreak br = (CT_TextLineBreak)ch; CT_RegularTextRun r = new CT_RegularTextRun(); r.rPr = (br.rPr); r.t=("\n"); _Runs.Add(new XSSFTextRun(r, this)); } - else if (ch is CT_TextField) + else if (ch is CT_TextField field) { - CT_TextField f = (CT_TextField)ch; CT_RegularTextRun r = new CT_RegularTextRun(); - r.rPr = (f.rPr); - r.t = (f.t); + r.rPr = (field.rPr); + r.t = (field.t); _Runs.Add(new XSSFTextRun(r, this)); } } diff --git a/ooxml/XSSF/UserModel/XSSFVMLDrawing.cs b/ooxml/XSSF/UserModel/XSSFVMLDrawing.cs index 9ffb52844..c8714b68a 100644 --- a/ooxml/XSSF/UserModel/XSSFVMLDrawing.cs +++ b/ooxml/XSSF/UserModel/XSSFVMLDrawing.cs @@ -193,21 +193,21 @@ internal void Write(Stream out1) for (int i = 0; i < _items.Count; i++) { object xc = _items[i]; - if (xc is XmlNode) + if (xc is XmlNode node) { - sw.Write(((XmlNode)xc).OuterXml.Replace(" xmlns:v=\"urn:schemas-microsoft-com:vml\"", "").Replace(" xmlns:x=\"urn:schemas-microsoft-com:office:excel\"", "").Replace(" xmlns:o=\"urn:schemas-microsoft-com:office:office\"", "").Replace(" ", "")); + sw.Write(node.OuterXml.Replace(" xmlns:v=\"urn:schemas-microsoft-com:vml\"", "").Replace(" xmlns:x=\"urn:schemas-microsoft-com:office:excel\"", "").Replace(" xmlns:o=\"urn:schemas-microsoft-com:office:office\"", "").Replace(" ", "")); } - else if (xc is CT_Shapetype) + else if (xc is CT_Shapetype shapetype) { - ((CT_Shapetype)xc).Write(sw, "shapetype"); + shapetype.Write(sw, "shapetype"); } - else if (xc is CT_ShapeLayout) + else if (xc is CT_ShapeLayout layout) { - ((CT_ShapeLayout)xc).Write(sw, "shapelayout"); + layout.Write(sw, "shapelayout"); } - else if (xc is CT_Shape) + else if (xc is CT_Shape shape) { - ((CT_Shape)xc).Write(sw, "shape"); + shape.Write(sw, "shape"); } else { @@ -292,9 +292,8 @@ internal CT_Shape FindCommentShape(int row, int col) { foreach (object itm in _items) { - if (itm is CT_Shape) + if (itm is CT_Shape sh) { - CT_Shape sh = (CT_Shape)itm; if (sh.sizeOfClientDataArray() > 0) { CT_ClientData cldata = sh.GetClientDataArray(0); diff --git a/ooxml/XSSF/UserModel/XSSFWorkbook.cs b/ooxml/XSSF/UserModel/XSSFWorkbook.cs index 38a26c0d0..54a8104d1 100644 --- a/ooxml/XSSF/UserModel/XSSFWorkbook.cs +++ b/ooxml/XSSF/UserModel/XSSFWorkbook.cs @@ -335,18 +335,18 @@ internal override void OnDocumentRead() foreach (RelationPart rp in RelationParts) { POIXMLDocumentPart p = rp.DocumentPart; - if (p is SharedStringsTable) sharedStringSource = (SharedStringsTable)p; - else if (p is StylesTable) stylesSource = (StylesTable)p; - else if (p is ThemesTable) theme = (ThemesTable)p; - else if (p is CalculationChain) calcChain = (CalculationChain)p; - else if (p is MapInfo) mapInfo = (MapInfo)p; - else if (p is XSSFSheet) + if (p is SharedStringsTable table) sharedStringSource = table; + else if (p is StylesTable stylesTable) stylesSource = stylesTable; + else if (p is ThemesTable themesTable) theme = themesTable; + else if (p is CalculationChain chain) calcChain = chain; + else if (p is MapInfo info) mapInfo = info; + else if (p is XSSFSheet sheet) { - shIdMap[rp.Relationship.Id] = (XSSFSheet)p; + shIdMap[rp.Relationship.Id] = sheet; } - else if (p is ExternalLinksTable) + else if (p is ExternalLinksTable linksTable) { - elIdMap[rp.Relationship.Id] = (ExternalLinksTable)p; + elIdMap[rp.Relationship.Id] = linksTable; } } @@ -610,9 +610,9 @@ public ISheet CloneSheet(int sheetNum, String newName) { POIXMLDocumentPart r = rp.DocumentPart; // do not copy the drawing relationship, it will be re-created - if (r is XSSFDrawing) + if (r is XSSFDrawing drawing) { - dg = (XSSFDrawing)r; + dg = drawing; continue; } @@ -1826,7 +1826,7 @@ protected internal override void Commit() public void Write(Stream stream, bool leaveOpen = false) { bool? originalValue = null; - if (Package is ZipPackage) + if (Package is ZipPackage package) { //By default ZipPackage closes the stream if it wasn't constructed from a stream. originalValue = ((ZipPackage)Package).IsExternalStream; @@ -2273,9 +2273,8 @@ public void RemovePivotTables() foreach (var poixmlDocumentPart in GetRelations()) { - if (poixmlDocumentPart is XSSFPivotCacheDefinition) + if (poixmlDocumentPart is XSSFPivotCacheDefinition pivotCacheDefinition) { - var pivotCacheDefinition = (XSSFPivotCacheDefinition)poixmlDocumentPart; RemoveRelation(pivotCacheDefinition); } } diff --git a/ooxml/XWPF/Extractor/XWPFWordExtractor.cs b/ooxml/XWPF/Extractor/XWPFWordExtractor.cs index dc1c42f53..899b26f8d 100644 --- a/ooxml/XWPF/Extractor/XWPFWordExtractor.cs +++ b/ooxml/XWPF/Extractor/XWPFWordExtractor.cs @@ -89,17 +89,17 @@ public override String Text public void AppendBodyElementText(StringBuilder text, IBodyElement e) { - if (e is XWPFParagraph) + if (e is XWPFParagraph paragraph) { - AppendParagraphText(text, (XWPFParagraph)e); + AppendParagraphText(text, paragraph); } - else if (e is XWPFTable) + else if (e is XWPFTable table) { - AppendTableText(text, (XWPFTable)e); + AppendTableText(text, table); } - else if (e is XWPFSDT) + else if (e is XWPFSDT xwpfsdt) { - text.Append(((XWPFSDT)e).Content.Text); + text.Append(xwpfsdt.Content.Text); } } @@ -125,9 +125,9 @@ public void AppendParagraphText(StringBuilder text, XWPFParagraph paragraph) foreach (IRunElement run in paragraph.Runs) { text.Append(run.ToString()); - if (run is XWPFHyperlinkRun && fetchHyperlinks) + if (run is XWPFHyperlinkRun hyperlinkRun && fetchHyperlinks) { - XWPFHyperlink link = ((XWPFHyperlinkRun)run).GetHyperlink(document); + XWPFHyperlink link = hyperlinkRun.GetHyperlink(document); if (link != null) text.Append(" <" + link.URL + ">"); } @@ -173,13 +173,13 @@ private void AppendTableText(StringBuilder text, XWPFTable table) for (int i = 0; i < cells.Count; i++) { ICell cell = cells[(i)]; - if (cell is XWPFTableCell) + if (cell is XWPFTableCell tableCell) { - text.Append(((XWPFTableCell)cell).GetTextRecursively()); + text.Append(tableCell.GetTextRecursively()); } - else if (cell is XWPFSDTCell) + else if (cell is XWPFSDTCell xwpfsdtCell) { - text.Append(((XWPFSDTCell)cell).Content.Text); + text.Append(xwpfsdtCell.Content.Text); } if (i < cells.Count - 1) { diff --git a/ooxml/XWPF/Model/XWPFHeaderFooterPolicy.cs b/ooxml/XWPF/Model/XWPFHeaderFooterPolicy.cs index 86dfa3741..e61a2a7fc 100644 --- a/ooxml/XWPF/Model/XWPFHeaderFooterPolicy.cs +++ b/ooxml/XWPF/Model/XWPFHeaderFooterPolicy.cs @@ -86,9 +86,9 @@ public XWPFHeaderFooterPolicy(XWPFDocument doc, CT_SectPr sectPr) CT_HdrFtrRef ref1 = sectPr.GetHeaderReferenceArray(i); POIXMLDocumentPart relatedPart = doc.GetRelationById(ref1.id); XWPFHeader hdr = null; - if (relatedPart != null && relatedPart is XWPFHeader) + if (relatedPart != null && relatedPart is XWPFHeader part) { - hdr = (XWPFHeader)relatedPart; + hdr = part; } // Assign it ST_HdrFtr type = ref1.type; @@ -100,9 +100,9 @@ public XWPFHeaderFooterPolicy(XWPFDocument doc, CT_SectPr sectPr) CT_HdrFtrRef ref1 = sectPr.GetFooterReferenceArray(i); POIXMLDocumentPart relatedPart = doc.GetRelationById(ref1.id); XWPFFooter ftr = null; - if (relatedPart != null && relatedPart is XWPFFooter) + if (relatedPart != null && relatedPart is XWPFFooter part) { - ftr = (XWPFFooter)relatedPart; + ftr = part; } // Assign it ST_HdrFtr type = ref1.type; diff --git a/ooxml/XWPF/Usermodel/MathContainer.cs b/ooxml/XWPF/Usermodel/MathContainer.cs index 4e1666587..87a1d812e 100644 --- a/ooxml/XWPF/Usermodel/MathContainer.cs +++ b/ooxml/XWPF/Usermodel/MathContainer.cs @@ -55,33 +55,33 @@ private void BuildListsInOrderFromXml(ArrayList items) { foreach (object o in items) { - if (o is CT_R) + if (o is CT_R r) { - runs.Add(new XWPFSharedRun(o as CT_R, this)); + runs.Add(new XWPFSharedRun(r, this)); } - if (o is CT_Acc) + if (o is CT_Acc acc) { - accs.Add(new XWPFAcc(o as CT_Acc, this)); + accs.Add(new XWPFAcc(acc, this)); } - if (o is CT_Nary) + if (o is CT_Nary nary) { - naries.Add(new XWPFNary(o as CT_Nary, this)); + naries.Add(new XWPFNary(nary, this)); } - if (o is CT_SSub) + if (o is CT_SSub sub) { - sSubs.Add(new XWPFSSub(o as CT_SSub, this)); + sSubs.Add(new XWPFSSub(sub, this)); } - if (o is CT_F) + if (o is CT_F f) { - fs.Add(new XWPFF(o as CT_F, this)); + fs.Add(new XWPFF(f, this)); } - if (o is CT_Rad) + if (o is CT_Rad rad) { - rads.Add(new XWPFRad(o as CT_Rad, this)); + rads.Add(new XWPFRad(rad, this)); } } } diff --git a/ooxml/XWPF/Usermodel/XWPFComment.cs b/ooxml/XWPF/Usermodel/XWPFComment.cs index 953a28785..7a3edbc96 100644 --- a/ooxml/XWPF/Usermodel/XWPFComment.cs +++ b/ooxml/XWPF/Usermodel/XWPFComment.cs @@ -47,21 +47,21 @@ protected void Init() { foreach (var o in ctComment.Items) { - if (o is CT_P) + if (o is CT_P ctP) { - XWPFParagraph p = new XWPFParagraph((CT_P)o, this); + XWPFParagraph p = new XWPFParagraph(ctP, this); bodyElements.Add(p); paragraphs.Add(p); } - else if (o is CT_Tbl) + else if (o is CT_Tbl tbl) { - XWPFTable t = new XWPFTable((CT_Tbl)o, this); + XWPFTable t = new XWPFTable(tbl, this); bodyElements.Add(t); tables.Add(t); } - else if (o is CT_SdtBlock) + else if (o is CT_SdtBlock block) { - XWPFSDT c = new XWPFSDT((CT_SdtBlock)o, this); + XWPFSDT c = new XWPFSDT(block, this); bodyElements.Add(c); } } diff --git a/ooxml/XWPF/Usermodel/XWPFComments.cs b/ooxml/XWPF/Usermodel/XWPFComments.cs index 4095fe262..b2271f900 100644 --- a/ooxml/XWPF/Usermodel/XWPFComments.cs +++ b/ooxml/XWPF/Usermodel/XWPFComments.cs @@ -41,7 +41,7 @@ public class XWPFComments : POIXMLDocumentPart public XWPFComments(POIXMLDocumentPart parent, PackagePart part) : base(parent, part) { - if (!(GetParent() is XWPFDocument)) + if (GetParent() is not XWPFDocument) { throw new RuntimeException("Parent is not a XWPFDocuemnt: " + GetParent()); } @@ -86,9 +86,8 @@ internal override void OnDocumentRead() foreach (POIXMLDocumentPart poixmlDocumentPart in GetRelations()) { - if (poixmlDocumentPart is XWPFPictureData) + if (poixmlDocumentPart is XWPFPictureData xwpfPicData) { - XWPFPictureData xwpfPicData = (XWPFPictureData)poixmlDocumentPart; pictures.Add(xwpfPicData); document.RegisterPackagePictureData(xwpfPicData); } diff --git a/ooxml/XWPF/Usermodel/XWPFDocument.cs b/ooxml/XWPF/Usermodel/XWPFDocument.cs index 1f8ee942b..482ff67c9 100644 --- a/ooxml/XWPF/Usermodel/XWPFDocument.cs +++ b/ooxml/XWPF/Usermodel/XWPFDocument.cs @@ -107,21 +107,21 @@ internal override void OnDocumentRead() foreach (object o in ctDocument.body.Items) { - if (o is CT_P) + if (o is CT_P ctP) { - XWPFParagraph p = new XWPFParagraph((CT_P)o, this); + XWPFParagraph p = new XWPFParagraph(ctP, this); bodyElements.Add(p); paragraphs.Add(p); } - else if (o is CT_Tbl) + else if (o is CT_Tbl tbl) { - XWPFTable t = new XWPFTable((CT_Tbl)o, this); + XWPFTable t = new XWPFTable(tbl, this); bodyElements.Add(t); tables.Add(t); } - else if (o is CT_SdtBlock) + else if (o is CT_SdtBlock block) { - XWPFSDT c = new XWPFSDT((CT_SdtBlock)o, this); + XWPFSDT c = new XWPFSDT(block, this); bodyElements.Add(c); contentControls.Add(c); } @@ -1706,9 +1706,8 @@ public int GetNextPicNameNumber(int format) public XWPFPictureData GetPictureDataByID(String blipID) { POIXMLDocumentPart relatedPart = GetRelationById(blipID); - if (relatedPart is XWPFPictureData) + if (relatedPart is XWPFPictureData xwpfPicData) { - XWPFPictureData xwpfPicData = (XWPFPictureData)relatedPart; return xwpfPicData; } return null; @@ -1859,18 +1858,18 @@ public BodyType PartType */ public XWPFTableCell GetTableCell(CT_Tc cell) { - if (cell == null|| !(cell.Parent is CT_Row)) + if (cell == null|| cell.Parent is not CT_Row row) return null; - object parent2 = ((CT_Row)cell.Parent).Parent; - if ( parent2== null || !(parent2 is CT_Tbl)) + object parent2 = row.Parent; + if ( parent2== null || parent2 is not CT_Tbl tbl) return null; - XWPFTable table = GetTable((CT_Tbl)parent2); + XWPFTable table = GetTable(tbl); if (table == null) { return null; } - XWPFTableRow tableRow = table.GetRow((CT_Row)cell.Parent); + XWPFTableRow tableRow = table.GetRow(row); if (tableRow == null) { return null; diff --git a/ooxml/XWPF/Usermodel/XWPFFooter.cs b/ooxml/XWPF/Usermodel/XWPFFooter.cs index 934a1ab27..c5b077c5d 100644 --- a/ooxml/XWPF/Usermodel/XWPFFooter.cs +++ b/ooxml/XWPF/Usermodel/XWPFFooter.cs @@ -59,14 +59,14 @@ public XWPFFooter(XWPFDocument doc, CT_HdrFtr hdrFtr) cursor.Dispose();*/ foreach (object o in hdrFtr.Items) { - if (o is CT_P) + if (o is CT_P ctP) { - XWPFParagraph p = new XWPFParagraph((CT_P)o, this); + XWPFParagraph p = new XWPFParagraph(ctP, this); paragraphs.Add(p); } - if (o is CT_Tbl) + if (o is CT_Tbl tbl) { - XWPFTable t = new XWPFTable((CT_Tbl)o, this); + XWPFTable t = new XWPFTable(tbl, this); tables.Add(t); } } @@ -124,21 +124,21 @@ internal override void OnDocumentRead() // the XmlObject to its lists foreach (object o in headerFooter.Items) { - if (o is CT_P) + if (o is CT_P ctP) { - XWPFParagraph p = new XWPFParagraph((CT_P)o, this); + XWPFParagraph p = new XWPFParagraph(ctP, this); paragraphs.Add(p); bodyElements.Add(p); } - if (o is CT_Tbl) + if (o is CT_Tbl tbl) { - XWPFTable t = new XWPFTable((CT_Tbl)o, this); + XWPFTable t = new XWPFTable(tbl, this); tables.Add(t); bodyElements.Add(t); } - if (o is CT_SdtBlock) + if (o is CT_SdtBlock block) { - XWPFSDT c = new XWPFSDT((CT_SdtBlock)o, this); + XWPFSDT c = new XWPFSDT(block, this); bodyElements.Add(c); } } diff --git a/ooxml/XWPF/Usermodel/XWPFFootnote.cs b/ooxml/XWPF/Usermodel/XWPFFootnote.cs index 4ffa6e21e..061d4d429 100644 --- a/ooxml/XWPF/Usermodel/XWPFFootnote.cs +++ b/ooxml/XWPF/Usermodel/XWPFFootnote.cs @@ -53,21 +53,21 @@ private void Init() foreach (object o in ctFtnEdn.Items) { - if (o is CT_P) + if (o is CT_P ctP) { - XWPFParagraph p = new XWPFParagraph((CT_P)o, this); + XWPFParagraph p = new XWPFParagraph(ctP, this); bodyElements.Add(p); paragraphs.Add(p); } - else if (o is CT_Tbl) + else if (o is CT_Tbl tbl) { - XWPFTable t = new XWPFTable((CT_Tbl)o, this); + XWPFTable t = new XWPFTable(tbl, this); bodyElements.Add(t); tables.Add(t); } - else if (o is CT_SdtBlock) + else if (o is CT_SdtBlock block) { - XWPFSDT c = new XWPFSDT((CT_SdtBlock)o, this); + XWPFSDT c = new XWPFSDT(block, this); bodyElements.Add(c); } } @@ -207,14 +207,12 @@ public XWPFParagraph GetParagraphArray(int pos) public XWPFTableCell GetTableCell(CT_Tc cell) { object obj = cell.Parent; - if (!(obj is CT_Row)) + if (obj is not CT_Row row) return null; - CT_Row row = (CT_Row)obj; - if (!(row.Parent is CT_Tbl)) + if (row.Parent is not CT_Tbl tbl) return null; - CT_Tbl tbl = (CT_Tbl)row.Parent; XWPFTable table = GetTable(tbl); if(table == null){ return null; diff --git a/ooxml/XWPF/Usermodel/XWPFHeader.cs b/ooxml/XWPF/Usermodel/XWPFHeader.cs index 3bb3ae1a5..35295d5ef 100644 --- a/ooxml/XWPF/Usermodel/XWPFHeader.cs +++ b/ooxml/XWPF/Usermodel/XWPFHeader.cs @@ -69,14 +69,14 @@ public XWPFHeader(XWPFDocument doc, CT_HdrFtr hdrFtr) cursor.Dispose();*/ foreach (object o in hdrFtr.Items) { - if (o is CT_P) + if (o is CT_P ctP) { - XWPFParagraph p = new XWPFParagraph((CT_P)o, this); + XWPFParagraph p = new XWPFParagraph(ctP, this); paragraphs.Add(p); } - if (o is CT_Tbl) + if (o is CT_Tbl tbl) { - XWPFTable t = new XWPFTable((CT_Tbl)o, this); + XWPFTable t = new XWPFTable(tbl, this); tables.Add(t); } } @@ -125,21 +125,21 @@ internal override void OnDocumentRead() headerFooter = hdrDocument.Hdr; foreach (object o in headerFooter.Items) { - if (o is CT_P) + if (o is CT_P ctP) { - XWPFParagraph p = new XWPFParagraph((CT_P)o, this); + XWPFParagraph p = new XWPFParagraph(ctP, this); paragraphs.Add(p); bodyElements.Add(p); } - if (o is CT_Tbl) + if (o is CT_Tbl tbl) { - XWPFTable t = new XWPFTable((CT_Tbl)o, this); + XWPFTable t = new XWPFTable(tbl, this); tables.Add(t); bodyElements.Add(t); } - if (o is CT_SdtBlock) + if (o is CT_SdtBlock block) { - XWPFSDT c = new XWPFSDT((CT_SdtBlock)o, this); + XWPFSDT c = new XWPFSDT(block, this); bodyElements.Add(c); } } diff --git a/ooxml/XWPF/Usermodel/XWPFHeaderFooter.cs b/ooxml/XWPF/Usermodel/XWPFHeaderFooter.cs index ea48f5b67..aa2225c37 100644 --- a/ooxml/XWPF/Usermodel/XWPFHeaderFooter.cs +++ b/ooxml/XWPF/Usermodel/XWPFHeaderFooter.cs @@ -79,9 +79,8 @@ internal override void OnDocumentRead() { foreach (POIXMLDocumentPart poixmlDocumentPart in GetRelations()) { - if (poixmlDocumentPart is XWPFPictureData) + if (poixmlDocumentPart is XWPFPictureData xwpfPicData) { - XWPFPictureData xwpfPicData = (XWPFPictureData)poixmlDocumentPart; pictures.Add(xwpfPicData); document.RegisterPackagePictureData(xwpfPicData); } @@ -171,9 +170,9 @@ public String Text } foreach (IBodyElement bodyElement in BodyElements) { - if (bodyElement is XWPFSDT) + if (bodyElement is XWPFSDT xwpfsdt) { - t.Append(((XWPFSDT)bodyElement).Content.Text + '\n'); + t.Append(xwpfsdt.Content.Text + '\n'); } } return t.ToString(); @@ -360,9 +359,9 @@ public String AddPictureData(Stream is1, int format) public XWPFPictureData GetPictureDataByID(String blipID) { POIXMLDocumentPart relatedPart = GetRelationById(blipID); - if (relatedPart != null && relatedPart is XWPFPictureData) + if (relatedPart != null && relatedPart is XWPFPictureData data) { - return (XWPFPictureData)relatedPart; + return data; } return null; } @@ -605,15 +604,15 @@ public void ReadHdrFtr() // the XmlObject to its lists foreach (object o in headerFooter.Items) { - if (o is CT_P) + if (o is CT_P ctP) { - XWPFParagraph p = new XWPFParagraph((CT_P)o, this); + XWPFParagraph p = new XWPFParagraph(ctP, this); paragraphs.Add(p); bodyElements.Add(p); } - if (o is CT_Tbl) + if (o is CT_Tbl tbl) { - XWPFTable t = new XWPFTable((CT_Tbl)o, this); + XWPFTable t = new XWPFTable(tbl, this); tables.Add(t); bodyElements.Add(t); } @@ -699,7 +698,7 @@ public POIXMLDocumentPart Part } } - #region IBody ³ÉÔ± + #region IBody ��Ա public virtual BodyType PartType diff --git a/ooxml/XWPF/Usermodel/XWPFParagraph.cs b/ooxml/XWPF/Usermodel/XWPFParagraph.cs index a906d10b8..9eed69d77 100644 --- a/ooxml/XWPF/Usermodel/XWPFParagraph.cs +++ b/ooxml/XWPF/Usermodel/XWPFParagraph.cs @@ -73,9 +73,8 @@ public XWPFParagraph(CT_P prgrph, IBody part) for (int i = 0; i < r.Items.Count; i++) { object o = r.Items[i]; - if (o is CT_FtnEdnRef) + if (o is CT_FtnEdnRef ftn) { - CT_FtnEdnRef ftn = (CT_FtnEdnRef)o; footnoteText.Append("[").Append(ftn.id).Append(": "); XWPFFootnote footnote = null; @@ -122,15 +121,14 @@ private void BuildRunsInOrderFromXml(ArrayList items) { foreach (object o in items) { - if (o is CT_R) + if (o is CT_R ctR) { - XWPFRun r = new XWPFRun((CT_R)o, (IRunBody)this); + XWPFRun r = new XWPFRun(ctR, (IRunBody)this); runs.Add(r); iRuns.Add(r); } - if (o is CT_Hyperlink1) + if (o is CT_Hyperlink1 link) { - CT_Hyperlink1 link = (CT_Hyperlink1)o; foreach (CT_R r in link.GetRList()) { //runs.Add(new XWPFHyperlinkRun(link, r, this)); @@ -140,8 +138,7 @@ private void BuildRunsInOrderFromXml(ArrayList items) } } - if (o is CT_SimpleField) { - CT_SimpleField field = (CT_SimpleField)o; + if (o is CT_SimpleField field) { foreach (CT_R r in field.GetRList()) { XWPFFieldRun fr = new XWPFFieldRun(field, r, this); @@ -149,34 +146,34 @@ private void BuildRunsInOrderFromXml(ArrayList items) iRuns.Add(fr); } } - if (o is CT_SdtBlock) + if (o is CT_SdtBlock block) { - XWPFSDT cc = new XWPFSDT((CT_SdtBlock)o, part); + XWPFSDT cc = new XWPFSDT(block, part); iRuns.Add(cc); } - if (o is CT_SdtRun) + if (o is CT_SdtRun run) { - XWPFSDT cc = new XWPFSDT((CT_SdtRun)o, part); + XWPFSDT cc = new XWPFSDT(run, part); iRuns.Add(cc); } - if (o is CT_RunTrackChange) + if (o is CT_RunTrackChange change) { - foreach (CT_R r in ((CT_RunTrackChange)o).GetRList()) + foreach (CT_R r in change.GetRList()) { XWPFRun cr = new XWPFRun(r, (IRunBody)this); runs.Add(cr); iRuns.Add(cr); } } - if (o is CT_SmartTagRun) + if (o is CT_SmartTagRun tagRun) { // Smart Tags can be nested many times. // This implementation does not preserve the tagging information - BuildRunsInOrderFromXml((o as CT_SmartTagRun).Items); + BuildRunsInOrderFromXml(tagRun.Items); } - if (o is CT_RunTrackChange) { + if (o is CT_RunTrackChange trackChange) { // add all the insertions as text - foreach (CT_RunTrackChange ins in ((CT_RunTrackChange)o).GetInsList()) + foreach (CT_RunTrackChange ins in trackChange.GetInsList()) { foreach (CT_R r in ins.GetRList()) { @@ -193,9 +190,9 @@ private void BuildOMathsInOrderFromXml(ArrayList items) { foreach (object o in items) { - if(o is S.CT_OMath) + if(o is S.CT_OMath math) { - oMaths.Add(new XWPFOMath(o as S.CT_OMath, this)); + oMaths.Add(new XWPFOMath(math, this)); } } } @@ -264,18 +261,17 @@ public String Text StringBuilder out1 = new StringBuilder(); foreach (IRunElement run in iRuns) { - if (run is XWPFRun) + if (run is XWPFRun xRun) { - XWPFRun xRun = (XWPFRun)run; // don't include the text if reviewing is enabled and this is a deleted run if (xRun.GetCTR().GetDelTextList().Count==0) { out1.Append(xRun.ToString()); } } - else if (run is XWPFSDT) + else if (run is XWPFSDT xwpfsdt) { - out1.Append(((XWPFSDT)run).Content.Text); + out1.Append(xwpfsdt.Content.Text); } else { @@ -1400,11 +1396,11 @@ public TextSegment SearchText(String searched, PositionInParagraph startPos) CT_R ctRun = paragraph.GetRList()[runPos]; foreach (object o in ctRun.Items) { - if (o is CT_Text) + if (o is CT_Text text) { if (textPos >= startText) { - String candidate = ((CT_Text)o).Value; + String candidate = text.Value; if (runPos == startRun) charPos = startChar; else diff --git a/ooxml/XWPF/Usermodel/XWPFPicture.cs b/ooxml/XWPF/Usermodel/XWPFPicture.cs index a6775c4fb..761297071 100644 --- a/ooxml/XWPF/Usermodel/XWPFPicture.cs +++ b/ooxml/XWPF/Usermodel/XWPFPicture.cs @@ -81,9 +81,9 @@ public XWPFPictureData GetPictureData() if (part != null) { POIXMLDocumentPart relatedPart = part.GetRelationById(blipId); - if (relatedPart is XWPFPictureData) + if (relatedPart is XWPFPictureData data) { - return (XWPFPictureData)relatedPart; + return data; } } return null; diff --git a/ooxml/XWPF/Usermodel/XWPFPictureData.cs b/ooxml/XWPF/Usermodel/XWPFPictureData.cs index 792e33c5d..e98f78309 100644 --- a/ooxml/XWPF/Usermodel/XWPFPictureData.cs +++ b/ooxml/XWPF/Usermodel/XWPFPictureData.cs @@ -225,12 +225,11 @@ public override bool Equals(Object obj) return false; } - if (!(obj is XWPFPictureData)) + if (obj is not XWPFPictureData picData) { return false; } - XWPFPictureData picData = (XWPFPictureData)obj; PackagePart foreignPackagePart = picData.GetPackagePart(); PackagePart ownPackagePart = this.GetPackagePart(); diff --git a/ooxml/XWPF/Usermodel/XWPFRun.cs b/ooxml/XWPF/Usermodel/XWPFRun.cs index 57c8c8a46..d6d6320f7 100644 --- a/ooxml/XWPF/Usermodel/XWPFRun.cs +++ b/ooxml/XWPF/Usermodel/XWPFRun.cs @@ -155,9 +155,8 @@ public XWPFRun(CT_R r, XWPFParagraph p) // pictures.Add((NPOI.OpenXmlFormats.Dml.CT_Picture)pict); //} //} - if (o is CT_Drawing) + if (o is CT_Drawing drawing) { - CT_Drawing drawing = o as CT_Drawing; if (drawing.inline != null) { foreach (CT_Inline inline in drawing.inline) @@ -166,9 +165,9 @@ public XWPFRun(CT_R r, XWPFParagraph p) } } } - else if (o is CT_GraphicalObjectData) + else if (o is CT_GraphicalObjectData data) { - GetPictures(o as CT_GraphicalObjectData, pictures); + GetPictures(data, pictures); } return pictures; } @@ -217,8 +216,8 @@ public XWPFParagraph Paragraph { get { - if (parent is XWPFParagraph) - return (XWPFParagraph)parent; + if (parent is XWPFParagraph paragraph) + return paragraph; return null; } } @@ -475,17 +474,16 @@ public string Text for (int i = 0; i < run.Items.Count; i++) { object o = run.Items[i]; - if (o is CT_Text) + if (o is CT_Text ctText) { if (!(run.ItemsElementName[i] == RunItemsChoiceType.instrText)) { - text.Append(((CT_Text)o).Value); + text.Append(ctText.Value); } } // Complex type evaluation (currently only for extraction of check boxes) - if (o is CT_FldChar) + if (o is CT_FldChar ctfldChar) { - CT_FldChar ctfldChar = ((CT_FldChar)o); if (ctfldChar.fldCharType == ST_FldCharType.begin) { if (ctfldChar.ffData != null) @@ -533,9 +531,8 @@ public string Text } } - if (o is CT_FtnEdnRef) + if (o is CT_FtnEdnRef ftn) { - CT_FtnEdnRef ftn = (CT_FtnEdnRef)o; String footnoteRef = ftn.DomNode.LocalName.Equals("footnoteReference") ? "[footnoteRef:" + ftn.id + "]" : "[endnoteRef:" + ftn.id + "]"; text.Append(footnoteRef); @@ -1072,15 +1069,13 @@ XWPFPicture AddPicture(Stream pictureData, int pictureType, String filename, int // Work out what to add the picture to, then add both the // picture and the relationship for it // TODO Should we have an interface for this sort of thing? - if (parent.Part is XWPFHeaderFooter) + if (parent.Part is XWPFHeaderFooter headerFooter) { - XWPFHeaderFooter headerFooter = (XWPFHeaderFooter)parent.Part; relationId = headerFooter.AddPictureData(pictureData, pictureType); picData = (XWPFPictureData)headerFooter.GetRelationById(relationId); } - else if (parent.Part is XWPFComments) + else if (parent.Part is XWPFComments comments) { - XWPFComments comments = (XWPFComments)parent.Part; relationId = comments.AddPictureData(pictureData, pictureType); picData = (XWPFPictureData)comments.GetRelationById(relationId); } diff --git a/ooxml/XWPF/Usermodel/XWPFSDTContent.cs b/ooxml/XWPF/Usermodel/XWPFSDTContent.cs index 29bcbae08..2867c3063 100644 --- a/ooxml/XWPF/Usermodel/XWPFSDTContent.cs +++ b/ooxml/XWPF/Usermodel/XWPFSDTContent.cs @@ -54,27 +54,27 @@ public XWPFSDTContent(CT_SdtContentBlock block, IBody part, IRunBody parent) foreach (object o in block.Items) { - if (o is CT_P) + if (o is CT_P ctP) { - XWPFParagraph p = new XWPFParagraph((CT_P)o, part); + XWPFParagraph p = new XWPFParagraph(ctP, part); bodyElements.Add(p); paragraphs.Add(p); } - else if (o is CT_Tbl) + else if (o is CT_Tbl tbl) { - XWPFTable t = new XWPFTable((CT_Tbl)o, part); + XWPFTable t = new XWPFTable(tbl, part); bodyElements.Add(t); tables.Add(t); } - else if (o is CT_SdtBlock) + else if (o is CT_SdtBlock sdtBlock) { - XWPFSDT c = new XWPFSDT(((CT_SdtBlock)o), part); + XWPFSDT c = new XWPFSDT(sdtBlock, part); bodyElements.Add(c); contentControls.Add(c); } - else if (o is CT_R) + else if (o is CT_R r) { - XWPFRun run = new XWPFRun((CT_R)o, parent); + XWPFRun run = new XWPFRun(r, parent); runs.Add(run); bodyElements.Add(run); } @@ -90,24 +90,24 @@ public String Text for (int i = 0; i < bodyElements.Count; i++) { Object o = bodyElements[i]; - if (o is XWPFParagraph) + if (o is XWPFParagraph paragraph) { - AppendParagraph((XWPFParagraph)o, text); + AppendParagraph(paragraph, text); addNewLine = true; } - else if (o is XWPFTable) + else if (o is XWPFTable table) { - AppendTable((XWPFTable)o, text); + AppendTable(table, text); addNewLine = true; } - else if (o is XWPFSDT) + else if (o is XWPFSDT xwpfsdt) { - text.Append(((XWPFSDT)o).Content.Text); + text.Append(xwpfsdt.Content.Text); addNewLine = true; } - else if (o is XWPFRun) + else if (o is XWPFRun run) { - text.Append(((XWPFRun)o).ToString()); + text.Append(run.ToString()); addNewLine = false; } if (addNewLine && i < bodyElements.Count-1) @@ -128,13 +128,13 @@ private void AppendTable(XWPFTable table, StringBuilder text) for (int i = 0; i < cells.Count; i++) { ICell cell = cells[i]; - if (cell is XWPFTableCell) + if (cell is XWPFTableCell tableCell) { - text.Append(((XWPFTableCell)cell).GetTextRecursively()); + text.Append(tableCell.GetTextRecursively()); } - else if (cell is XWPFSDTCell) + else if (cell is XWPFSDTCell xwpfsdtCell) { - text.Append(((XWPFSDTCell)cell).Content.Text); + text.Append(xwpfsdtCell.Content.Text); } if (i < cells.Count - 1) { diff --git a/ooxml/XWPF/Usermodel/XWPFSharedRun.cs b/ooxml/XWPF/Usermodel/XWPFSharedRun.cs index a63a8a08a..4373034a4 100644 --- a/ooxml/XWPF/Usermodel/XWPFSharedRun.cs +++ b/ooxml/XWPF/Usermodel/XWPFSharedRun.cs @@ -180,9 +180,9 @@ public string Text for (int i = 0; i < run.Items.Count; i++) { object o = run.Items[i]; - if (o is CT_Text1) + if (o is CT_Text1 text1) { - text.Append(((CT_Text1)o).Value); + text.Append(text1.Value); } } diff --git a/ooxml/XWPF/Usermodel/XWPFTableCell.cs b/ooxml/XWPF/Usermodel/XWPFTableCell.cs index dae8917e0..30e9a4121 100644 --- a/ooxml/XWPF/Usermodel/XWPFTableCell.cs +++ b/ooxml/XWPF/Usermodel/XWPFTableCell.cs @@ -73,26 +73,26 @@ public XWPFTableCell(CT_Tc cell, XWPFTableRow tableRow, IBody part) tables = new List(); foreach (object o in ctTc.Items) { - if (o is CT_P) + if (o is CT_P ctP) { - XWPFParagraph p = new XWPFParagraph((CT_P)o, this); + XWPFParagraph p = new XWPFParagraph(ctP, this); paragraphs.Add(p); bodyElements.Add(p); } - if (o is CT_Tbl) + if (o is CT_Tbl tbl) { - XWPFTable t = new XWPFTable((CT_Tbl)o, this); + XWPFTable t = new XWPFTable(tbl, this); tables.Add(t); bodyElements.Add(t); } - if (o is CT_SdtBlock) + if (o is CT_SdtBlock block) { - XWPFSDT c = new XWPFSDT((CT_SdtBlock)o, this); + XWPFSDT c = new XWPFSDT(block, this); bodyElements.Add(c); } - if (o is CT_SdtRun) + if (o is CT_SdtRun run) { - XWPFSDT c = new XWPFSDT((CT_SdtRun)o, this); + XWPFSDT c = new XWPFSDT(run, this); bodyElements.Add(c); } } @@ -548,17 +548,16 @@ public String GetTextRecursively() private void AppendBodyElementText(StringBuilder text, IBodyElement e, bool isLast) { - if (e is XWPFParagraph) + if (e is XWPFParagraph paragraph) { - text.Append(((XWPFParagraph)e).Text); + text.Append(paragraph.Text); if (isLast == false) { text.Append('\t'); } } - else if (e is XWPFTable) + else if (e is XWPFTable eTable) { - XWPFTable eTable = (XWPFTable)e; foreach (XWPFTableRow row in eTable.Rows) { foreach (XWPFTableCell cell in row.GetTableCells()) @@ -577,9 +576,9 @@ private void AppendBodyElementText(StringBuilder text, IBodyElement e, bool isLa text.Append('\n'); } } - else if (e is XWPFSDT) + else if (e is XWPFSDT xwpfsdt) { - text.Append(((XWPFSDT)e).Content.Text); + text.Append(xwpfsdt.Content.Text); if (isLast == false) { text.Append('\t'); @@ -591,15 +590,14 @@ private void AppendBodyElementText(StringBuilder text, IBodyElement e, bool isLa */ public XWPFTableCell GetTableCell(CT_Tc cell) { - if (!(cell.Parent is CT_Row)) + if (cell.Parent is not CT_Row row) return null; - CT_Row row = (CT_Row)cell.Parent; - if (!(row.Parent is CT_Tbl)) + if (row.Parent is not CT_Tbl tbl) { return null; } - CT_Tbl tbl = (CT_Tbl)row.Parent; + XWPFTable table = GetTable(tbl); if (table == null) { diff --git a/ooxml/XWPF/Usermodel/XWPFTableRow.cs b/ooxml/XWPF/Usermodel/XWPFTableRow.cs index c19b6d6e5..c71644272 100644 --- a/ooxml/XWPF/Usermodel/XWPFTableRow.cs +++ b/ooxml/XWPF/Usermodel/XWPFTableRow.cs @@ -175,13 +175,13 @@ public List GetTableICells() foreach(object o in ctRow.Items) { - if (o is CT_Tc) + if (o is CT_Tc tc) { - cells.Add(new XWPFTableCell((CT_Tc)o, this, table.Body)); + cells.Add(new XWPFTableCell(tc, this, table.Body)); } - else if (o is CT_SdtCell) + else if (o is CT_SdtCell cell) { - cells.Add(new XWPFSDTCell((CT_SdtCell)o, this, table.Body)); + cells.Add(new XWPFSDTCell(cell, this, table.Body)); } } return cells; diff --git a/openxml4Net/OPC/Internal/ContentType.cs b/openxml4Net/OPC/Internal/ContentType.cs index 17beb64c9..db4fd9e2e 100644 --- a/openxml4Net/OPC/Internal/ContentType.cs +++ b/openxml4Net/OPC/Internal/ContentType.cs @@ -203,7 +203,7 @@ public String ToStringWithParameters() public override bool Equals(Object obj) { - return (!(obj is ContentType)) + return (obj is not ContentType) || (this.ToString().Equals(obj.ToString(), StringComparison.InvariantCultureIgnoreCase)); } diff --git a/openxml4Net/OPC/Internal/Marshallers/PackagePropertiesMarshaller.cs b/openxml4Net/OPC/Internal/Marshallers/PackagePropertiesMarshaller.cs index 62369a74a..987762443 100644 --- a/openxml4Net/OPC/Internal/Marshallers/PackagePropertiesMarshaller.cs +++ b/openxml4Net/OPC/Internal/Marshallers/PackagePropertiesMarshaller.cs @@ -65,10 +65,10 @@ public class PackagePropertiesMarshaller : PartMarshaller */ public virtual bool Marshall(PackagePart part, Stream out1) { - if (!(part is PackagePropertiesPart)) + if (part is not PackagePropertiesPart propertiesPart) throw new ArgumentException( "'part' must be a PackagePropertiesPart instance."); - propsPart = (PackagePropertiesPart)part; + propsPart = propertiesPart; // Configure the document xmlDoc = new XmlDocument(); diff --git a/openxml4Net/OPC/Internal/Marshallers/ZipPackagePropertiesMarshaller.cs b/openxml4Net/OPC/Internal/Marshallers/ZipPackagePropertiesMarshaller.cs index 548fa9a33..391c0042e 100644 --- a/openxml4Net/OPC/Internal/Marshallers/ZipPackagePropertiesMarshaller.cs +++ b/openxml4Net/OPC/Internal/Marshallers/ZipPackagePropertiesMarshaller.cs @@ -15,12 +15,11 @@ public class ZipPackagePropertiesMarshaller:PackagePropertiesMarshaller { public override bool Marshall(PackagePart part, Stream out1) { - if (!(out1 is ZipOutputStream)) { + if (out1 is not ZipOutputStream zos) { throw new ArgumentException("ZipOutputStream expected!"); } - ZipOutputStream zos = (ZipOutputStream) out1; - // Saving the part in the zip file + // Saving the part in the zip file string name = ZipHelper .GetZipItemNameFromOPCName(part.PartName.URI.ToString()); ZipEntry ctEntry = new ZipEntry(name); @@ -30,9 +29,9 @@ public override bool Marshall(PackagePart part, Stream out1) // Save in ZIP zos.PutNextEntry(ctEntry); // Add entry in ZIP - base.Marshall(part, out1); // Marshall the properties inside a XML + base.Marshall(part, zos); // Marshall the properties inside a XML // Document - StreamHelper.SaveXmlInStream(xmlDoc, out1); + StreamHelper.SaveXmlInStream(xmlDoc, zos); zos.CloseEntry(); } diff --git a/openxml4Net/OPC/Internal/Marshallers/ZipPartMarshaller.cs b/openxml4Net/OPC/Internal/Marshallers/ZipPartMarshaller.cs index f1f76151b..dc2cd43a6 100644 --- a/openxml4Net/OPC/Internal/Marshallers/ZipPartMarshaller.cs +++ b/openxml4Net/OPC/Internal/Marshallers/ZipPartMarshaller.cs @@ -26,7 +26,7 @@ public class ZipPartMarshaller : PartMarshaller */ public bool Marshall(PackagePart part, Stream os) { - if (!(os is ZipOutputStream)) + if (os is not ZipOutputStream zos) { logger.Log(POILogger.ERROR,"Unexpected class " + os.GetType().Name); throw new OpenXml4NetException("ZipOutputStream expected !"); @@ -41,7 +41,6 @@ public bool Marshall(PackagePart part, Stream os) return true; } - ZipOutputStream zos = (ZipOutputStream)os; string name = ZipHelper .GetZipItemNameFromOPCName(part.PartName.URI .OriginalString); diff --git a/openxml4Net/OPC/Internal/Unmarshallers/PackagePropertiesUnmarshaller.cs b/openxml4Net/OPC/Internal/Unmarshallers/PackagePropertiesUnmarshaller.cs index 52bc507e2..9d24d2f22 100644 --- a/openxml4Net/OPC/Internal/Unmarshallers/PackagePropertiesUnmarshaller.cs +++ b/openxml4Net/OPC/Internal/Unmarshallers/PackagePropertiesUnmarshaller.cs @@ -432,8 +432,8 @@ public void CheckElementForOPCCompliance(XmlElement el) IEnumerator itChildren = el.GetEnumerator(); while (itChildren.MoveNext()) { - if (itChildren.Current is XmlElement) - CheckElementForOPCCompliance((XmlElement)itChildren.Current); + if (itChildren.Current is XmlElement element) + CheckElementForOPCCompliance(element); } } } diff --git a/openxml4Net/OPC/Internal/ZipContentTypeManager.cs b/openxml4Net/OPC/Internal/ZipContentTypeManager.cs index a13889bec..ad0d45b42 100644 --- a/openxml4Net/OPC/Internal/ZipContentTypeManager.cs +++ b/openxml4Net/OPC/Internal/ZipContentTypeManager.cs @@ -34,8 +34,8 @@ public ZipContentTypeManager(Stream in1, OPCPackage pkg):base(in1, pkg) public override bool SaveImpl(XmlDocument content, Stream out1) { ZipOutputStream zos = null; - if (out1 is ZipOutputStream) - zos = (ZipOutputStream) out1; + if (out1 is ZipOutputStream stream) + zos = stream; else zos = new ZipOutputStream(out1); diff --git a/openxml4Net/OPC/Internal/ZipHelper.cs b/openxml4Net/OPC/Internal/ZipHelper.cs index d18a083b4..c687a4245 100644 --- a/openxml4Net/OPC/Internal/ZipHelper.cs +++ b/openxml4Net/OPC/Internal/ZipHelper.cs @@ -175,9 +175,9 @@ public static void VerifyZipHeader(InputStream stream) // start before beginning processing. // Put things back - if (stream is PushbackInputStream) + if (stream is PushbackInputStream inputStream) { - ((PushbackInputStream)stream).Unread(data); + inputStream.Unread(data); } else if (stream.MarkSupported()) { diff --git a/openxml4Net/OPC/OPCPackage.cs b/openxml4Net/OPC/OPCPackage.cs index b03e56c11..f02834b86 100644 --- a/openxml4Net/OPC/OPCPackage.cs +++ b/openxml4Net/OPC/OPCPackage.cs @@ -847,11 +847,11 @@ public List GetParts() // Core properties case-- use first CoreProperties part we come across // and ignore any subsequent ones - if (unmarshallPart is PackagePropertiesPart && + if (unmarshallPart is PackagePropertiesPart propertiesPart && hasCorePropertiesPart && needCorePropertiesPart) { - this.packageProperties = (PackagePropertiesPart)unmarshallPart; + this.packageProperties = propertiesPart; needCorePropertiesPart = false; } } diff --git a/openxml4Net/OPC/PackagePartName.cs b/openxml4Net/OPC/PackagePartName.cs index d3de6eb10..c4d532953 100644 --- a/openxml4Net/OPC/PackagePartName.cs +++ b/openxml4Net/OPC/PackagePartName.cs @@ -505,12 +505,12 @@ public String Name public override bool Equals(Object other) { - if (other is PackagePartName) + if (other is PackagePartName name) { // String.equals() is compatible with our compareTo(), but cheaper return this.partNameURI.OriginalString.ToLower().Equals ( - ((PackagePartName)other).partNameURI.OriginalString.ToLower() + name.partNameURI.OriginalString.ToLower() ); } else diff --git a/openxml4Net/OPC/PackageRelationship.cs b/openxml4Net/OPC/PackageRelationship.cs index 29f47b6fb..e1fcb98ff 100644 --- a/openxml4Net/OPC/PackageRelationship.cs +++ b/openxml4Net/OPC/PackageRelationship.cs @@ -95,16 +95,16 @@ public PackageRelationship(OPCPackage pkg, PackagePart sourcePart, public override bool Equals(Object obj) { - if (!(obj is PackageRelationship)) + if (obj is not PackageRelationship rel) { return false; } - PackageRelationship rel = (PackageRelationship)obj; + return (this.id == rel.id && this.relationshipType == rel.relationshipType && (rel.source != null ? rel.source.Equals(this.source) : true) && this.targetMode == rel.targetMode && this.targetUri - .Equals(rel.targetUri)); + .Equals(rel.targetUri)); } diff --git a/openxml4Net/OPC/ZipPackage.cs b/openxml4Net/OPC/ZipPackage.cs index abd1c89e7..535999b2b 100644 --- a/openxml4Net/OPC/ZipPackage.cs +++ b/openxml4Net/OPC/ZipPackage.cs @@ -528,10 +528,10 @@ protected override void SaveImpl(Stream outputStream) try { - if (!(outputStream is ZipOutputStream)) + if (outputStream is not ZipOutputStream stream) zos = new ZipOutputStream(outputStream); else - zos = (ZipOutputStream)outputStream; + zos = stream; zos.UseZip64 = UseZip64.Off; // If the core properties part does not exist in the part list, diff --git a/openxml4Net/Util/ZipSecureFile.cs b/openxml4Net/Util/ZipSecureFile.cs index 53edb5915..20ccec3a7 100644 --- a/openxml4Net/Util/ZipSecureFile.cs +++ b/openxml4Net/Util/ZipSecureFile.cs @@ -207,42 +207,42 @@ public void Advance(int advance) public ZipEntry GetNextEntry() { - if (!(input is ZipInputStream)) { + if (input is not ZipInputStream stream) { throw new NotSupportedException("underlying stream is not a ZipInputStream"); } counter = 0; - return ((ZipInputStream)input).GetNextEntry(); + return stream.GetNextEntry(); } public void CloseEntry() { - if (!(input is ZipInputStream)) { + if (input is not ZipInputStream stream) { throw new NotSupportedException("underlying stream is not a ZipInputStream"); } counter = 0; - ((ZipInputStream)input).CloseEntry(); + stream.CloseEntry(); } public void Unread(int b) { - if (!(input is PushbackInputStream)) { + if (input is not PushbackInputStream stream) { throw new NotSupportedException("underlying stream is not a PushbackInputStream"); } if (--counter < 0) counter = 0; - ((PushbackInputStream)input).Unread(b); + stream.Unread(b); } public void Unread(byte[] b, int off, int len) { - if (!(input is PushbackInputStream)) { + if (input is not PushbackInputStream stream) { throw new NotSupportedException("underlying stream is not a PushbackInputStream"); } counter -= len; if (--counter < 0) counter = 0; - ((PushbackInputStream)input).Unread(b, off, len); + stream.Unread(b, off, len); } public int Available()