BarkingMouseStudio / haste

Open-source implementation of the original quick search for Unity 3D.
MIT License
14 stars 2 forks source link

reflectiontypeloadexception in HestleReflection on recompile #5

Open friuns2 opened 5 years ago

friuns2 commented 5 years ago

reflectiontypeloadexception in HestleReflection on recompile

based on this, i modified HestleReflection.cs

https://stackoverflow.com/questions/7889228/how-to-prevent-reflectiontypeloadexception-when-calling-assembly-gettypes


public static IEnumerable<HasteTuple<T, MethodInfo>> GetAttributesInAssembly<T>(Assembly assembly) {
      var flags = BindingFlags.Public|BindingFlags.NonPublic|BindingFlags.Static|BindingFlags.DeclaredOnly;
      Type[] enumerable=null;
      try
      {
        enumerable = assembly.GetTypes();
      }
      catch (ReflectionTypeLoadException e)
      {
        yield break;        
      }
      foreach (var type in enumerable) {
        foreach (var methodInfo in type.GetMethods(flags)) {
          foreach (var attribute in methodInfo.GetCustomAttributes(typeof(T), true)) {
            yield return HasteTuple.Create((T)attribute, methodInfo);
          }
        }
      }
    }