0

In my MVC 3 project I have method, that scans folder bin at dll and some loads. Then I filtered and get list Controller class. Then I filtered and try get list the methods who return ActionResult. But I get duplication methods. I try filtered an by Attribute. But nothing not obtained

private void GetControllers()
{
        IEnumerable<FileInfo> files = this.GetFileList();

        foreach (var fileInfo in files)
        {
            if (fileInfo.Name != "SGN.Framework.dll" && fileInfo.Name != "SGN.Controls.dll")
            {
                Assembly assembly = Assembly.LoadFile(fileInfo.FullName);
                AssemblyName asamName = assembly.GetName();
                IList<Type> myType =
                    assembly.GetTypes().Where(item => item.Name.Contains("Controller")).Where(
                        item => item.Name != "AdminsController" && item.Name != "ModuleController").ToList();

                foreach (var type in myType)
                {
                    var m =
                        type.GetMethods().Where(
                            item =>
                            item.ReturnType == typeof(ActionResult)).Except(type.GetCustomAttributes(true).Where(i => i != typeof(ActionInfoAttribute)));
                }
            }
        }
}
1
  • Before write here, I try all used variations what I know. But not found answer Commented Apr 14, 2012 at 18:24

1 Answer 1

1

I know that the question is old. But maybe my answer will help someone. For this case the following code will work:

type.GetMethods().Where(
    item =>
    item.ReturnType == typeof(ActionResult) && item.IsDefined(typeof(ActionInfoAttribute), false));
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.