fork(1) download
  1. using System;
  2. using System.Collections.Generic;
  3.  
  4. class Foo {
  5. public int Bar { get; set; }
  6. public Foo(Dictionary<string, object> values) {
  7. var propertyInfo = this.GetType().GetProperties();
  8. foreach(var property in propertyInfo) {
  9. if(values.ContainsKey(property.Name)) {
  10. property.SetValue(this, values[property.Name], null);
  11. }
  12. }
  13. }
  14. }
  15.  
  16. class Program {
  17. public static void Main(String[] args) {
  18. Dictionary<string, object> values = new Dictionary<string, object>();
  19. values.Add("Bar", 42);
  20. Foo foo = new Foo(values);
  21. Console.WriteLine(foo.Bar);
  22. }
  23. }
Success #stdin #stdout 0.04s 34872KB
stdin
Standard input is empty
stdout
42