@@ -17,12 +17,12 @@ public static void ConvertToWord(MarkdownSpec spec, string templateFile, string
17
17
resultDoc . AddPart ( part . OpenXmlPart , part . RelationshipId ) ;
18
18
}
19
19
20
- var body = resultDoc . MainDocumentPart . Document . Body ;
20
+ var body = resultDoc . MainDocumentPart ! . Document . Body ! ;
21
21
22
22
ReplaceTableOfContents ( spec , body ) ;
23
23
24
24
var context = new ConversionContext ( ) ;
25
- context . MaxBookmarkId . Value = 1 + body . Descendants < BookmarkStart > ( ) . Max ( bookmark => int . Parse ( bookmark . Id ) ) ;
25
+ context . MaxBookmarkId . Value = 1 + body . Descendants < BookmarkStart > ( ) . Max ( bookmark => int . Parse ( bookmark . Id ! ) ) ;
26
26
27
27
foreach ( var src in spec . Sources )
28
28
{
@@ -72,9 +72,12 @@ private static void ReplaceTableOfContents(MarkdownSpec spec, Body body)
72
72
}
73
73
}
74
74
75
- private static bool FindToc ( Body body , out int ifirst , out int iLast , out string instr , out Paragraph secBreak )
75
+ private static bool FindToc ( Body body , out int ifirst , out int iLast , out string ? instr , out Paragraph ? secBreak )
76
76
{
77
- ifirst = - 1 ; iLast = - 1 ; instr = null ; secBreak = null ;
77
+ ifirst = - 1 ;
78
+ iLast = - 1 ;
79
+ instr = null ;
80
+ secBreak = null ;
78
81
79
82
for ( int i = 0 ; i < body . ChildElements . Count ; i ++ )
80
83
{
@@ -86,23 +89,25 @@ private static bool FindToc(Body body, out int ifirst, out int iLast, out string
86
89
87
90
// The TOC might be a simple field
88
91
var sf = p . OfType < SimpleField > ( ) . FirstOrDefault ( ) ;
89
- if ( sf != null && sf . Instruction . Value . Contains ( "TOC" ) )
92
+ if ( sf ? . Instruction ? . Value ? . Contains ( "TOC" ) == true )
90
93
{
91
94
if ( ifirst != - 1 )
92
95
{
93
96
throw new Exception ( "Found start of TOC and then another simple TOC" ) ;
94
97
}
95
98
96
- ifirst = i ; iLast = i ; instr = sf . Instruction . Value ;
99
+ ifirst = i ;
100
+ iLast = i ;
101
+ instr = sf . Instruction . Value ;
97
102
break ;
98
103
}
99
104
100
105
// or it might be a complex field
101
106
var runElements = ( from r in p . OfType < Run > ( ) from e in r select e ) . ToList ( ) ;
102
- var f1 = runElements . FindIndex ( f => f is FieldChar && ( f as FieldChar ) . FieldCharType . Value == FieldCharValues . Begin ) ;
103
- var f2 = runElements . FindIndex ( f => f is FieldCode && ( f as FieldCode ) . Text . Contains ( "TOC" ) ) ;
104
- var f3 = runElements . FindIndex ( f => f is FieldChar && ( f as FieldChar ) . FieldCharType . Value == FieldCharValues . Separate ) ;
105
- var f4 = runElements . FindIndex ( f => f is FieldChar && ( f as FieldChar ) . FieldCharType . Value == FieldCharValues . End ) ;
107
+ var f1 = runElements . FindIndex ( f => f is FieldChar fc && fc . FieldCharType ? . Value == FieldCharValues . Begin ) ;
108
+ var f2 = runElements . FindIndex ( f => f is FieldCode fc && fc . Text . Contains ( "TOC" ) ) ;
109
+ var f3 = runElements . FindIndex ( f => f is FieldChar fc && fc . FieldCharType ? . Value == FieldCharValues . Separate ) ;
110
+ var f4 = runElements . FindIndex ( f => f is FieldChar fc && fc . FieldCharType ? . Value == FieldCharValues . End ) ;
106
111
107
112
if ( f1 != - 1 && f2 != - 1 && f3 != - 1 && f2 > f1 && f3 > f2 )
108
113
{
@@ -111,7 +116,8 @@ private static bool FindToc(Body body, out int ifirst, out int iLast, out string
111
116
throw new Exception ( "Found start of TOC and then another start of TOC" ) ;
112
117
}
113
118
114
- ifirst = i ; instr = ( runElements [ f2 ] as FieldCode ) . Text ;
119
+ ifirst = i ;
120
+ instr = ( ( FieldCode ) runElements [ f2 ] ) . Text ;
115
121
}
116
122
if ( f4 != - 1 && f4 > f1 && f4 > f2 && f4 > f3 )
117
123
{
@@ -141,7 +147,7 @@ private static bool FindToc(Body body, out int ifirst, out int iLast, out string
141
147
continue ;
142
148
}
143
149
144
- var sp = p . ParagraphProperties . OfType < SectionProperties > ( ) . FirstOrDefault ( ) ;
150
+ var sp = p . ParagraphProperties ? . OfType < SectionProperties > ( ) . FirstOrDefault ( ) ;
145
151
if ( sp == null )
146
152
{
147
153
continue ;
0 commit comments