Switch
Switch - Reference Guide Documentation

The Switch framework is...

For more information see Switch page or Documentations.md file.

Examples

The classic first application 'Hello World'.

Console

HelloWorld.cpp:

#include <Switch/Switch>
using namespace System;
namespace HelloWorld {
class Program {
public:
static void Main() {
Console::WriteLine("Hello, World!");
}
};
}

CMakeLists.txt:

cmake_minimum_required(VERSION 3.2)
Project(HelloWorld)
find_package(Switch REQUIRED)
add_executable(HelloWorld HelloWorld.cpp)
target_link_libraries(HelloWorld Switch.Core)

Forms

HelloWorldForm.cpp:

#include <Switch/Switch>
using namespace System;
using namespace System::Drawing;
using namespace System::Windows::Forms;
namespace HelloWorld {
class Program {
public:
static void Main() {
Application::EnableVisualStyles();
Button button;
button.Text = "Click me";
button.Location = Point(10, 10);
button.Click += delegate_(const object& sender, const EventArgs& e) {
MessageBox::Show("Hello, World!");
};
Form form;
form.Text = "Hello World Form";
form.Controls().Add(button);
Application::Run(form);
}
};
}

CMakeLists.txt:

cmake_minimum_required(VERSION 3.2)
Project(HelloWorldForm)
find_package(Switch REQUIRED)
add_executable(HelloWorldForm ${SWITCH_GUI} HelloWorldForm.cpp)
target_link_libraries(HelloWorldForm Switch.Forms)

TUnit

HelloWorldTest.cpp:

#include <Switch/Switch>
using namespace TUnit::Framework;
using namespace System;
namespace UnitTests {
class TestFixture_(HelloWorldTest) {
void Test_(CreateStringFromLiteral) {
string s = "Hello, World!";
Assert::AreEqual("Hello, World!", s);
}
void Test_(CreateStringFromChars) {
string s = {'H', 'e', 'l', 'l', 'o', ',', ' ', 'W', 'o', 'r', 'l', 'd', '!'};
Assert::AreEqual("Hello, World!", s);
}
};
AddTestFixture_(HelloWorldTest);
}

CMakeLists.txt:

cmake_minimum_required(VERSION 3.2)
Project(HelloWorldTest)
find_package(Switch REQUIRED)
add_executable(HelloWorldTest HelloWorldTest.cpp)
target_link_libraries(HelloWorldTest Switch.TUnit.Main)

For more examples see Examples.

Download Switch

Before running examples you must download and install Switch. To download and install it read Downloads page or Downloads.md file.