Advertisement
Guest User

Enumerate funcs

a guest
Nov 11th, 2017
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.81 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3.  
  4. namespace 2ch
  5. {
  6.     public class Shiet
  7.     {
  8.         public string[] PrintAllT();
  9.         public T Get<T>();
  10.     }
  11.  
  12.     public class ShietService
  13.     {
  14.         public static Dictionary<Type, Func<object>> DoShit(Shiet shiet)
  15.         {
  16.             var dict = new Dictionary<Type, Func<object>>();
  17.             var method = typeof(Shiet).GetMethod("Get");
  18.             foreach (var t in shiet.PrintAllT())
  19.             {
  20.                 //not 'int' or 'Int32', but 'System.Int32, mscorlib'
  21.                 var type = Type.GetType(t);
  22.                 var generic = method.MakeGenericMethod(type);
  23.                 Func<object> func = () => generic.Invoke(shiet, null);
  24.                 dict.Add(type, func);
  25.             }
  26.             return dict;
  27.         }
  28.     }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement