Advertisement
Guest User

Untitled

a guest
Sep 24th, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.79 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(a => a.GetType("OpenRA.Traits." + traitClassName) != null);
  11.    
  12.         if (traitType != null)
  13.         {
  14.             var genericMethodInfo = methodInfo.MakeGenericMethod(traitType);
  15.  
  16.             if (genericMethodInfo.ReturnType != typeof(void))
  17.             {
  18.                 object result = genericMethodInfo.Invoke(instance, null);
  19.                 this.stack.Push(result);
  20.             }
  21.         }
  22.     }
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement