---
title: "ASP.NET MVC Find class by class attribute value using Reflection"  
description: "ASP.NET MVC Find class by class attribute value using Reflection"  
author: "Mark Devid"  
published: 2014-08-14  
updated: 2014-08-14  
canonical: https://www.mindstick.com/forum/2043/asp-dot-net-mvc-find-class-by-class-attribute-value-using-reflection  
category: "c#"  
tags: ["c#"]  
reading_time: 1 minute  

---

# ASP.NET MVC Find class by class attribute value using Reflection

I have a [class](https://www.mindstick.com/blog/165/generic-class-in-c-sharp) with a [custom attribute](https://www.mindstick.com/forum/161975/how-to-create-a-custom-attribute-in-c-sharp) that has a [string](https://www.mindstick.com/articles/1527/string-split-in-c-sharp) parameter.

```
[ANAttribute("Ampe21")]public class ClassB : ClassA{}
```

I have different [action](https://www.mindstick.com/forum/155752/what-is-action-result-with-its-types) names defined for different classes.

What I want is to obtain the [namespace](https://www.mindstick.com/articles/12552/namespace) of ClassB or obtain the type of ClassB by searching the entire [application](https://www.mindstick.com/articles/12824/calculator-application-in-android) after Ampe21.

How can I do that?

## Replies

### Reply by Pravesh Singh

Hi Mark, Try this:

```
var types = AppDomain.CurrentDomain.GetAssemblies()    .SelectMany(x =>x.GetTypes()        .Where(t =>t.GetCustomAttribute<ANAttribute>() != null &&                   
t.GetCustomAttribute<ANAttribute>().YourProperty =="Ampe21")    );foreach (var type in types){   
Console.WriteLine(type.Namespace);}
```


---

Original Source: https://www.mindstick.com/forum/2043/asp-dot-net-mvc-find-class-by-class-attribute-value-using-reflection

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
