MethodInfo List : MethodInfo « Reflection « C# / C Sharp






MethodInfo List

      
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;

namespace RNR.Dynamics
{
    class TransobjectUtils
    {

        public static List<MethodInfo> BuildFull(object obj)
        {
            var result = new List<MethodInfo>();

            #region Listar Interfaces
            List<Type> interfaceList = new List<Type>();

            Type baseType = obj.GetType();
            Type parentType = baseType;
            if (baseType == null || baseType.IsInterface)
            {
                parentType = typeof(object);
                if (baseType != null) interfaceList.Add(baseType);
            }

            // Agregamos las interfaces hereditarias recursivamente.
            Type[] interfaces = interfaceList.ToArray();
            foreach (Type interfaceType in interfaces)
            {
                BuildInterfaceList(interfaceType, interfaceList);
            }
            #endregion

            MethodInfo[] methods = baseType.GetMethods(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static);
            BuildMethodList(interfaceList, methods, result);
       
            return result;
        }
        public static void BuildInterfaceList(Type currentType, List<Type> interfaceList)
        {
            Type[] interfaces = currentType.GetInterfaces();
            if (interfaces == null || interfaces.Length == 0)
                return;

            foreach (Type current in interfaces)
            {
                if (interfaceList.Contains(current))
                    continue;

                interfaceList.Add(current);
                BuildInterfaceList(current, interfaceList);
            }
        }

        public static void BuildMethodList(IEnumerable<Type> interfaceList, IEnumerable<MethodInfo> methods,
                                            List<MethodInfo> proxyList)
        {
            foreach (MethodInfo method in methods)
                proxyList.Add(method);

            foreach (Type interfaceType in interfaceList)
            {
                MethodInfo[] interfaceMethods = interfaceType.GetMethods();
                foreach (MethodInfo interfaceMethod in interfaceMethods)
                {
                    if (proxyList.Contains(interfaceMethod))
                        continue;

                    proxyList.Add(interfaceMethod);
                }
            }
        }

    }
}

   
    
    
    
    
    
  








Related examples in the same category

1.MethodInfo: Name
2.Type.GetMethods
3.List Assembly Info
4.dump the public methods of a class
5.Finding the class that contains a method in an assembly.
6.Invoke methods using reflectionInvoke methods using reflection
7.Analyze methods using reflectionAnalyze methods using reflection
8.dynamic invocation is demonstrated with MethodInfo.Invoke and Type.InvokeMember
9.Invokes the method.
10.Call a static method in a nested namespace.
11.Gets a MethodBody that provides access to the MSIL stream, local variables, and exceptions for the current method.
12.Gets the parameters of the specified method or constructor.
13.Invokes the method or constructor represented by the current instance, using the specified parameters.
14.Gets a value indicating whether the method is abstract.
15.Indicating whether the potential visibility of this method or constructor is described by MethodAttributes.Assembly
16.Gets a value indicating whether this method is final.
17.Is it a public method.