@@ -31,6 +31,7 @@ export class CSharpLanguageGenerator implements LanguageGenerator {
3131 name : string ;
3232 highlighter = 'csharp' as Language ;
3333 _mode : CSharpLanguageMode ;
34+ private _pageAliases = new Map < string , string > ( ) ;
3435
3536 constructor ( mode : CSharpLanguageMode ) {
3637 if ( mode === 'library' ) {
@@ -51,6 +52,22 @@ export class CSharpLanguageGenerator implements LanguageGenerator {
5152 this . _mode = mode ;
5253 }
5354
55+ reset ( ) {
56+ this . _pageAliases . clear ( ) ;
57+ }
58+
59+ private _pageAlias ( pageGuid : string ) : string {
60+ let alias = this . _pageAliases . get ( pageGuid ) ;
61+ if ( ! alias ) {
62+ alias = 'page' + ( this . _pageAliases . size || '' ) ;
63+ // Outside of the library mode, the first page is a class member, the rest are local variables.
64+ if ( this . _mode !== 'library' && alias === 'page' )
65+ alias = 'Page' ;
66+ this . _pageAliases . set ( pageGuid , alias ) ;
67+ }
68+ return alias ;
69+ }
70+
5471 generateAction ( actionInContext : actions . ActionInContext , options : LanguageGeneratorOptions ) : string {
5572 const action = this . _generateActionInner ( actionInContext , options ) ;
5673 if ( action )
@@ -60,9 +77,10 @@ export class CSharpLanguageGenerator implements LanguageGenerator {
6077
6178 _generateActionInner ( actionInContext : actions . ActionInContext , options : LanguageGeneratorOptions ) : string {
6279 const action = actionInContext . action ;
80+ // Resolve before the early return, so that pages are named in the order they are opened.
81+ const pageAlias = this . _pageAlias ( actionInContext . pageGuid ) ;
6382 if ( this . _mode !== 'library' && ( action . name === 'openPage' || action . name === 'closePage' ) )
6483 return '' ;
65- const pageAlias = this . _formatPageAlias ( actionInContext . frame . pageAlias ) ;
6684 const formatter = new CSharpFormatter ( this . _mode === 'library' ? 0 : 8 ) ;
6785
6886 if ( action . name === 'openPage' ) {
@@ -94,7 +112,8 @@ export class CSharpLanguageGenerator implements LanguageGenerator {
94112 }
95113
96114 if ( signals . popup ) {
97- lines . unshift ( `var ${ this . _formatPageAlias ( signals . popup . popupAlias ) } = await ${ pageAlias } .RunAndWaitForPopupAsync(async () =>\n{` ) ;
115+ const popupAlias = this . _pageAlias ( signals . popup . popupPageGuid ) ;
116+ lines . unshift ( `var ${ popupAlias } = await ${ pageAlias } .RunAndWaitForPopupAsync(async () =>\n{` ) ;
98117 lines . push ( `});` ) ;
99118 }
100119
@@ -107,17 +126,6 @@ export class CSharpLanguageGenerator implements LanguageGenerator {
107126 return formatter . format ( ) ;
108127 }
109128
110- private _formatPageAlias ( pageAlias : string ) : string {
111- if ( this . _mode === 'library' )
112- return pageAlias ;
113-
114- if ( pageAlias === 'page' )
115- return 'Page' ; // first page is class member
116-
117- // other pages are local variables
118- return pageAlias ;
119- }
120-
121129 private _generateActionCall ( subject : string , actionInContext : actions . ActionInContext ) : string {
122130 const action = actionInContext . action ;
123131 switch ( action . name ) {
0 commit comments