Created
February 14, 2021 12:35
-
-
Save mitsakosgr/68b54f1203d3dae4da22b641d80955fa to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Globalization; | |
using System.Reflection; | |
namespace TestActivator | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
Activator.CreateInstance( | |
Type.GetType("TestActivator.Test1", true), | |
BindingFlags.CreateInstance | BindingFlags.Public | BindingFlags.Instance | BindingFlags.OptionalParamBinding, | |
null, | |
new object[] { }, | |
CultureInfo.CurrentCulture); | |
Activator.CreateInstance( | |
Type.GetType("TestActivator.Test2", true), | |
BindingFlags.CreateInstance | BindingFlags.Public | BindingFlags.Instance | BindingFlags.OptionalParamBinding, | |
null, | |
new object[] { }, | |
CultureInfo.CurrentCulture); | |
Activator.CreateInstance( | |
Type.GetType("TestActivator.Test2", true), | |
BindingFlags.CreateInstance | BindingFlags.Public | BindingFlags.Instance | BindingFlags.OptionalParamBinding, | |
null, | |
new object[] { "Dimitris" }, | |
CultureInfo.CurrentCulture); | |
} | |
} | |
public class Test1 | |
{ | |
public Test1() | |
{ | |
Console.WriteLine("Hello World!!!"); | |
} | |
} | |
public class Test2 | |
{ | |
public Test2(string name = null) | |
{ | |
Console.WriteLine($"Hello {name ?? "NoName"}!!!"); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment