consider the following code snippet. It works well in an asp.net mvc program
public IList<ActionAndControllerName> AreaAndActionAndControllerNamesList()
{
Assembly asm = Assembly.GetExecutingAssembly();
var contradistinction = asm.GetTypes()
.Where(type => typeof(Controller).IsAssignableFrom(type))
.SelectMany(type =>
type.GetMethods(BindingFlags.Instance | BindingFlags.DeclaredOnly | BindingFlags.Public))
.Select(x => new
{
Controller = x.DeclaringType?.Name,
Action = x.Name,
Area = x.DeclaringType?.CustomAttributes.Where(c => c.AttributeType == typeof(AreaAttribute))
});
var list = new List<ActionAndControllerName>();
foreach (var item in contradistinction)
{
if (item.Area.Any())
{
list.Add(new ActionAndControllerName()
{
ControllerName = item.Controller,
ActionName = item.Action,
AreaName = item.Area.Select(v => v.ConstructorArguments[0].Value.ToString()).FirstOrDefault()
});
}
}
return list.Distinct().ToList();
}
}
But returns a null when used in a web api. What needs to change?