Home > DeveloperSection > Forums > ASP.NET MVC Find class by class attribute value using Reflection
Mark Devid
Mark Devid

Total Post:101

Posted on    August-14-2014 5:17 AM

 C# C# 

 1 Reply(s)
 752  View(s)
Rate this:

I have a class with a custom attribute that has a string parameter.


public class ClassB : ClassA



I have different action names defined for different classes.

What I want is to obtain the namespace of ClassB or obtain the type of ClassB by searching the entire application after Ampe21.

How can I do that?

Pravesh Singh

Total Post:411

Posted on    August-14-2014 6:57 AM

Hi Mark, 
Try this:

var types = AppDomain.CurrentDomain.GetAssemblies()


    (x => x.GetTypes()

        .Where(t => t.GetCustomAttribute<ANAttribute>() != null &&

                    t.GetCustomAttribute<ANAttribute>().YourProperty == "Ampe21")


foreach (var type in types)




Don't want to miss updates? Please click the below button!

Follow MindStick