Advertisement
Guest User

Untitled

a guest
Sep 24th, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.80 KB | None | 0 0
  1. public void GetTraitForObject(int index, string traitClassName)
  2. {
  3.     var instance = this.stack[index];
  4.     var objectType = instance.GetType();
  5.     var methodInfo = objectType.GetMethods().FirstOrDefault(m => m.Name == "Trait");
  6.  
  7.     if (methodInfo != null)
  8.     {
  9.         var assemblies = AppDomain.CurrentDomain.GetAssemblies();
  10.         var traitType = assemblies.FirstOrDefault(
  11.             a => a.GetType("OpenRA.Traits." + traitClassName) != null);
  12.    
  13.         if (traitType != null)
  14.         {
  15.             var genericMethodInfo = methodInfo.MakeGenericMethod(traitType);
  16.  
  17.             if (genericMethodInfo.ReturnType != typeof(void))
  18.             {
  19.                 object result = genericMethodInfo.Invoke(instance, null);
  20.                 this.stack.Push(result);
  21.             }
  22.         }
  23.     }
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement