var props = t.GetProperties().Where(
prop => Attribute.IsDefined(prop, typeof(MyAttribute)));
This avoids having to materialize any attribute instances (i.e. it is cheaper than GetCustomAttribute[s]()
.
More Related Contents:
- How do I use reflection to call a generic method?
- How costly is .NET reflection?
- Getting all types in a namespace via reflection
- Testing if object is of generic type in C#
- Read the value of an attribute of a method
- How does WCF deserialization instantiate objects without calling a constructor?
- GetMethod for generic method [duplicate]
- Convert.ChangeType() fails on Nullable Types
- How to call generic method with a given Type object? [duplicate]
- What is the “cost” of .NET reflection? [duplicate]
- AddEventHandler using reflection
- How can you get the names of method parameters?
- Getting a System.Type from type’s partial name
- Using PropertyInfo to find out the property type
- Invoking methods with optional parameters through reflection
- Is there a way to get a type’s alias through reflection?
- How to hide public methods from IntelliSense
- Why GetType returns System.Int32 instead of Nullable? [duplicate]
- Finding out if a type implements a generic interface
- How to find out if a property is an auto-implemented property with reflection?
- How to get MethodInfo of interface method, having implementing MethodInfo of class method?
- C#: how to get an object by the name stored in String?
- Why do some C# lambda expressions compile to static methods?
- Create object instance of a class from its name in string variable
- Dynamically creating a proxy class
- Finding all classes with a particular attribute
- How do I check if a type provides a parameterless constructor?
- Using Reflection to create a DataTable from a Class?
- Get private Properties/Method of base-class with reflection
- Why is the use of reflection in .NET recommended?