public ConsoleColor B = ConsoleColor.Green;
public string C = "TESTTEST";
public MyClass(int a, ConsoleColor b, string c = "I am optional parameter value")
public static class MyFactory
public static T MyCreateInstance<T>()
return (T) MyCreateInstance(typeof (T));
public static object MyCreateInstance(Type type)
.FirstOrDefault(c => c.GetParameters().Length > 0);
return Activator.CreateInstance(type);
p.HasDefaultValue? p.DefaultValue :
p.ParameterType.IsValueType && Nullable.GetUnderlyingType(p.ParameterType) == null
? Activator.CreateInstance(p.ParameterType)
public static void Main(string[] args)
Assembly.GetExecutingAssembly()
var instance = MyFactory.MyCreateInstance(someType);
var values = someType.GetFields().Select(f => f.GetValue(instance)).ToArray();
foreach (var value in values)
Console.WriteLine(value);