fork download
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. //public interface IThing {}
  6. public class MachineClass /* : IThing */ { }
  7. public class AnimalClass /* : IThing */ { }
  8. public class Plane /* : IThing */ { }
  9.  
  10. public class Program
  11. {
  12. public enum Things
  13. {
  14. Car,
  15. Animal,
  16. Plane
  17. }
  18.  
  19. private static readonly IDictionary<Things, string> _classNameMap =
  20. new Dictionary<Things, string> {
  21. { Things.Car, "MachineClass" },
  22. { Things.Animal, "AnimalClass" },
  23. { Things.Plane, "FlyClass" } };
  24.  
  25. public static void Main(string[] args)
  26. {
  27. var realtypes = _classNameMap.ToDictionary(
  28. kvp => kvp.Key,
  29. kvp => System.Type.GetType(/*"Namespace." +*/ kvp.Value));
  30.  
  31. Type dynamicType = realtypes[Things.Plane]; // typeof(Namespace.FlyClass)
  32.  
  33. foreach (var realtype in realtypes)
  34. Console.WriteLine("{0}, class {1}",
  35. realtype.Key, realtype.Value);
  36. }
  37.  
  38. }
  39.  
stdin
Standard input is empty
compilation info
prog.cs(31,15): warning CS0219: The variable `dynamicType' is assigned but its value is never used
Compilation succeeded - 1 warning(s)
stdout
Car, class MachineClass
Animal, class AnimalClass
Plane, class