Advertisement
Guest User

Untitled

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