@@ -1743,15 +1743,14 @@ private void OpenRegex()
17431743 . Replace ( "#CSharpTextSource\r \n " , string . Empty ) ?? string . Empty ;
17441744 if ( Enum . TryParse ( root . SelectNodes ( "//comment()" )
17451745 . Cast < XmlComment > ( )
1746- . FirstOrDefault ( c => c . Value . StartsWith ( "#TextSource" ) )
1746+ . FirstOrDefault ( c => c . Value . StartsWith ( "#TextSource" ) ) ?
17471747 . Value
17481748 . Replace ( "#TextSource " , string . Empty )
17491749 , out RegexTextSource regexTextSource ) )
17501750 {
17511751 Config . Instance . TextSourceOn = regexTextSource ;
17521752 }
17531753
1754-
17551754 string [ ] xOptions = root . SelectSingleNode ( "//Options" ) . InnerText . Split ( ' ' ) ;
17561755
17571756 regExOptionViewModelsList . ForEach ( ( RegExOptionViewModel optionModel ) => optionModel . Selected = xOptions . Contains ( optionModel . Name ) ) ;
@@ -2133,24 +2132,36 @@ private void ExportToVisualStudio_Click(object sender, RoutedEventArgs e)
21332132 string textSourceFile = Path . Combine ( projectDirectory , "TextSource.txt" ) ;
21342133 string projectGuid = Guid . NewGuid ( ) . ToString ( ) ;
21352134 string resourcesForCsProj = string . Empty ;
2135+
21362136 string options = regExOptionViewModelsList . Count ( option => option . Selected ) == 0
21372137 ? "RegexOptions.None"
21382138 : string . Join ( " | " ,
21392139 regExOptionViewModelsList
21402140 . FindAll ( option => option . Selected )
21412141 . Select ( option => "RegexOptions." + option . RegexOptions . ToString ( ) ) ) ;
21422142
2143+ // The base stuff for the entry code
21432144 string programCode = Res . VSProgram
2144- . Replace ( "projectname " , projectName )
2145+ . Replace ( "_projectname_ " , projectName )
21452146 . Replace ( "$pattern$" , Config . Instance . RegexEditorText . ToLiteral ( ) )
2146- . Replace ( "$replacement$" , Config . Instance . ReplaceEditorText . ToLiteral ( ) )
21472147 . Replace ( "_options_" , options ) ;
21482148
21492149 Directory . CreateDirectory ( projectDirectory ) ;
21502150
2151+ // Modify entry code for CSharp replace (with a lambda of type Func<Match, string>)
21512152 if ( Config . Instance . CSharpReplaceMode )
21522153 {
21532154 File . WriteAllText ( replaceFile , ReplaceScriptForMatch ) ;
2155+ programCode = programCode
2156+ . Replace ( "\r \n private readonly static string replacement = \" $replacement$\" ;" , string . Empty )
2157+ . Replace ( "//code" , string . Empty ) ;
2158+ }
2159+ // Modify entry code for standard replacement.
2160+ else
2161+ {
2162+ programCode = programCode
2163+ . Replace ( "$replacement$" , Config . Instance . ReplaceEditorText . ToLiteral ( ) )
2164+ . Replace ( "//code" , Res . StandardReplaceCode ) ;
21542165 }
21552166
21562167 // Write text source as specific cs file if in CSharpScript
0 commit comments