Переглянути джерело

Not generating AddRawSettings call in VB.NET code within Using statement to simplify generation code

(and it would not be possible with object initializer anyway)

Source commit: 7486a8be76fde2f3397898f71cde119153c0e4e9
Martin Prikryl 7 роки тому
батько
коміт
8467f81c31
2 змінених файлів з 5 додано та 30 видалено
  1. 1 0
      source/core/Common.cpp
  2. 4 30
      source/core/SessionData.cpp

+ 1 - 0
source/core/Common.cpp

@@ -3792,6 +3792,7 @@ UnicodeString __fastcall AssemblyNewClassInstanceStart(
       // Historically we use Dim .. With instead of object initilizer.
       // But for inline use, we have to use object initialize.
       // We should consistently always use object initilizers.
+      // Unfortunatelly VB.NET object initializer (contrary to C#) does not allow trailing comma.
       if (!Inline)
       {
         Result += RtfKeyword(L"Dim") + RtfText(L" ");

+ 4 - 30
source/core/SessionData.cpp

@@ -3394,18 +3394,7 @@ void __fastcall TSessionData::GenerateAssemblyCode(
     SessionData->Timeout = FactoryDefaults->Timeout;
   }
 
-  switch (Language)
-  {
-    case alCSharp:
-    case alPowerShell:
-      Head += AssemblyNewClassInstanceEnd(Language, false);
-      break;
-
-    case alVBNET:
-      // noop
-      // Ending With only after AddRawSettings
-      break;
-  }
+  Head += AssemblyNewClassInstanceEnd(Language, false);
 
   std::unique_ptr<TStrings> RawSettings(SessionData->SaveToOptions(FactoryDefaults.get()));
 
@@ -3422,23 +3411,12 @@ void __fastcall TSessionData::GenerateAssemblyCode(
       UnicodeString AddRawSettingsMethod =
         RtfLibraryMethod(SessionOptionsClassName, L"AddRawSettings", false) +
         FORMAT(L"(%s, %s)", (AssemblyString(Language, Name), AssemblyString(Language, Value)));
-      switch (Language)
-      {
-        case alCSharp:
-          Head += RtfText(SessionOptionsVariableName + L".") + AddRawSettingsMethod + RtfText(L";") + RtfPara;
-          break;
-
-        case alVBNET:
-          Head += RtfText(L"    .") + AddRawSettingsMethod + RtfPara;
-          break;
-
-        case alPowerShell:
-          Head += RtfText(SessionOptionsVariableName + L".") + AddRawSettingsMethod + RtfPara;
-          break;
-      }
+      Head += RtfText(SessionOptionsVariableName + L".") + AddRawSettingsMethod + AssemblyStatementSeparator(Language) + RtfPara;
     }
   }
 
+  Head += RtfPara;
+
   UnicodeString Indentation = L"    ";
   UnicodeString SessionVariableName = AssemblyVariableName(Language, SessionClassName);
   UnicodeString RtfSessionClass = RtfLibraryClass(SessionClassName);
@@ -3454,7 +3432,6 @@ void __fastcall TSessionData::GenerateAssemblyCode(
   {
     case alCSharp:
       Head +=
-        RtfPara +
         RtfKeyword(L"using") + RtfText(" (") + NewSessionInstance + RtfText(L"())") + RtfPara +
         RtfText(L"{") + RtfPara +
         OpenCall;
@@ -3465,8 +3442,6 @@ void __fastcall TSessionData::GenerateAssemblyCode(
 
     case alVBNET:
       Head +=
-        AssemblyNewClassInstanceEnd(Language, false) +
-        RtfPara +
         RtfKeyword(L"Using") + RtfText(L" ") + NewSessionInstance + RtfPara +
         OpenCall;
 
@@ -3476,7 +3451,6 @@ void __fastcall TSessionData::GenerateAssemblyCode(
 
     case alPowerShell:
       Head +=
-        RtfPara +
         NewSessionInstance + RtfPara +
         RtfPara +
         RtfKeyword(L"try") + RtfPara +