using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;
namespace RNR.Dynamics
{
class TransobjectUtils
{
public static List BuildFull(object obj)
{
var result = new List();
#region Listar Interfaces
List interfaceList = new List();
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 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 interfaceList, IEnumerable methods,
List 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);
}
}
}
}
}