@@ -90,21 +90,13 @@ protected static bool ConvertJTokenToBool(string token, IGeneratedSymbolConfig c
9090 try
9191 {
9292 var jToken = JToken . Parse ( token ) ;
93- if ( jToken . Type is not JTokenType . Boolean and not JTokenType . String )
94- {
95- throw new TemplateAuthoringException ( string . Format ( LocalizableStrings . MacroConfig_Exception_ValueShouldBeBoolean , config . VariableName , parameterName ) , config . VariableName ) ;
96- }
97- if ( bool . TryParse ( jToken . ToString ( ) , out bool result ) )
93+ if ( jToken . TryParseBool ( out bool result ) )
9894 {
9995 return result ;
10096 }
10197 throw new TemplateAuthoringException ( string . Format ( LocalizableStrings . MacroConfig_Exception_ValueShouldBeBoolean , config . VariableName , parameterName ) , config . VariableName ) ;
10298 }
103- catch ( TemplateAuthoringException )
104- {
105- throw ;
106- }
107- catch ( Exception ex )
99+ catch ( Exception ex ) when ( ex is not TemplateAuthoringException )
108100 {
109101 throw new TemplateAuthoringException ( string . Format ( LocalizableStrings . MacroConfig_Exception_InvalidJSON , config . VariableName , parameterName ) , config . VariableName , ex ) ;
110102 }
@@ -115,21 +107,13 @@ protected static int ConvertJTokenToInt(string token, IGeneratedSymbolConfig con
115107 try
116108 {
117109 var jToken = JToken . Parse ( token ) ;
118- if ( jToken . Type is not JTokenType . Integer and not JTokenType . String )
119- {
120- throw new TemplateAuthoringException ( string . Format ( LocalizableStrings . MacroConfig_Exception_ValueShouldBeInteger , config . VariableName , parameterName ) , config . VariableName ) ;
121- }
122- if ( int . TryParse ( jToken . ToString ( ) , out int result ) )
110+ if ( jToken . TryParseInt ( out int result ) )
123111 {
124112 return result ;
125113 }
126114 throw new TemplateAuthoringException ( string . Format ( LocalizableStrings . MacroConfig_Exception_ValueShouldBeInteger , config . VariableName , parameterName ) , config . VariableName ) ;
127115 }
128- catch ( TemplateAuthoringException )
129- {
130- throw ;
131- }
132- catch ( Exception ex )
116+ catch ( Exception ex ) when ( ex is not TemplateAuthoringException )
133117 {
134118 throw new TemplateAuthoringException ( string . Format ( LocalizableStrings . MacroConfig_Exception_InvalidJSON , config . VariableName , parameterName ) , config . VariableName , ex ) ;
135119 }
@@ -146,11 +130,7 @@ protected static string ConvertJTokenToString(string token, IGeneratedSymbolConf
146130 }
147131 return jToken . ToString ( ) ;
148132 }
149- catch ( TemplateAuthoringException )
150- {
151- throw ;
152- }
153- catch ( Exception ex )
133+ catch ( Exception ex ) when ( ex is not TemplateAuthoringException )
154134 {
155135 throw new TemplateAuthoringException ( string . Format ( LocalizableStrings . MacroConfig_Exception_InvalidJSON , config . VariableName , parameterName ) , config . VariableName , ex ) ;
156136 }
@@ -167,11 +147,7 @@ protected static JArray ConvertJTokenToJArray(string token, IGeneratedSymbolConf
167147 }
168148 return ( JArray ) jToken ;
169149 }
170- catch ( TemplateAuthoringException )
171- {
172- throw ;
173- }
174- catch ( Exception ex )
150+ catch ( Exception ex ) when ( ex is not TemplateAuthoringException )
175151 {
176152 throw new TemplateAuthoringException ( string . Format ( LocalizableStrings . MacroConfig_Exception_InvalidJSON , config . VariableName , parameterName ) , config . VariableName , ex ) ;
177153 }
0 commit comments