Ejemplo n.º 1
0
 private static void RedirectMethods(
     System.Type type,
     System.Type targetType,
     Dictionary <MethodInfo, Redirector> redirects,
     bool onCreated)
 {
     foreach (MethodInfo method in ((IEnumerable <MethodInfo>)type.GetMethods(BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic)).Where <MethodInfo>((Func <MethodInfo, bool>)(method =>
     {
         object[] customAttributes = method.GetCustomAttributes(typeof(RedirectMethodAttribute), false);
         if (customAttributes.Length != 1)
         {
             return(false);
         }
         return(((RedirectMethodAttribute)customAttributes[0]).OnCreated == onCreated);
     })))
     {
         Debug.Log((object)("Redirecting " + targetType.Name + "#" + method.Name + "..."));
         Redirector redirector = RedirectionUtil.RedirectMethod(targetType, method, redirects, false);
         FieldInfo  field      = type.GetField(method.Name + "Redirector", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
         if (field != null && field.FieldType == typeof(Redirector))
         {
             Debug.Log((object)"Redirector field found!");
             field.SetValue((object)null, (object)redirector);
         }
     }
 }
Ejemplo n.º 2
0
        private static Redirector RedirectMethod(
            System.Type targetType,
            MethodInfo method,
            Dictionary <MethodInfo, Redirector> redirects,
            bool reverse = false)
        {
            Tuple <MethodInfo, Redirector> tuple = RedirectionUtil.RedirectMethod(targetType, method, reverse);

            redirects.Add(tuple.First, tuple.Second);
            return(tuple.Second);
        }
Ejemplo n.º 3
0
        public static Dictionary <MethodInfo, Redirector> RedirectType(
            System.Type type,
            bool onCreated = false)
        {
            Dictionary <MethodInfo, Redirector> redirects = new Dictionary <MethodInfo, Redirector>();

            object[] customAttributes = type.GetCustomAttributes(typeof(TargetTypeAttribute), false);
            if (customAttributes.Length != 1)
            {
                return((Dictionary <MethodInfo, Redirector>)null);
            }
            System.Type type1 = ((TargetTypeAttribute)customAttributes[0]).Type;
            RedirectionUtil.RedirectMethods(type, type1, redirects, onCreated);
            RedirectionUtil.RedirectReverse(type, type1, redirects, onCreated);
            return(redirects);
        }
Ejemplo n.º 4
0
 private static void RedirectReverse(
     System.Type type,
     System.Type targetType,
     Dictionary <MethodInfo, Redirector> redirects,
     bool onCreated)
 {
     foreach (MethodInfo method in ((IEnumerable <MethodInfo>)type.GetMethods(BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic)).Where <MethodInfo>((Func <MethodInfo, bool>)(method =>
     {
         object[] customAttributes = method.GetCustomAttributes(typeof(RedirectReverseAttribute), false);
         if (customAttributes.Length == 1)
         {
             return(((RedirectReverseAttribute)customAttributes[0]).OnCreated == onCreated);
         }
         return(false);
     })))
     {
         Debug.Log((object)("Redirecting reverse " + targetType.Name + "#" + method.Name + "..."));
         RedirectionUtil.RedirectMethod(targetType, method, redirects, true);
     }
 }