Here is the source code for the method:
static class IListExtension
{
public static void AddNotExist<T>(this IList<T> list, T type)
{
if (!list.Contains(type))
{
list.Add(type);
}
}
}
static class TypeExtensions
{
public static IEnumerable<MethodDefinition> GetMethods(this
TypeDefinition type)
{
foreach (MethodDefinition method in type.Methods)
{
yield return method;
}
foreach (MethodDefinition method in type.Constructors)
{
yield return method;
}
}
}
class Dependencies
{
public static IList<TypeReference> GetDependencies
(TypeDefinition type)
{
var dep = new List<TypeReference>();
dep.AddNotExist(type.BaseType);
foreach (CustomAttribute attr in type.CustomAttributes)
{
TypeReference tref = attr.Constructor.DeclaringType;
dep.AddNotExist(tref);
}
foreach (FieldDefinition field in type.Fields)
{
dep.AddNotExist(field.FieldType);
}
foreach (MethodDefinition method in type.GetMethods())
{
if (!method.HasBody) continue;
foreach (Instruction instruction in
method.Body.Instructions)
{
var methodOp = instruction.Operand as
MemberReference;
if (methodOp != null)
dep.AddNotExist(methodOp.DeclaringType);
}
dep.AddNotExist(method.ReturnType.ReturnType);
foreach (ParameterDefinition parameter in
method.Parameters)
{
dep.AddNotExist(parameter.ParameterType);
}
}
return dep;
}
}
--~--~---------~--~----~------------~-------~--~----~
--
mono-cecil
-~----------~----~----~----~------~----~------~--~---