Reflection in C# is very expensive operation especially when you use it often enough (For example creating your own ORM or pluginable system)
This small library help you to boost project speed using reflection cache. In this case system will use reflection only once, and then it will take data from memory.
Just add this sources to your solution (or include compiled dll)
To get list of special attributes you need to follow these semple steps:
// 1. Get reflection class from cache (or if it is not in cache - reflect it and add to cache)
var reflection = ReflectionCache.GetReflection(typeof(ExampleObject));
// 2. Get list of attributes from cache
var attributes = reflection.Attributes;
// 3. Get attibutes by type
var attributesByType = attributes[typeof(SomeType)];
Other available functions:
Cache:
- static ReflectionClass GetReflection(Type t)
Class:
- ReflectionAttributeList Attributes
- Type BaseType
- string FullName
- ReflectionMethodList Methods
- string Name
- ReflectionPropertyList Properties
- bool IsAssignableFrom(Type type)
Method:
- string FullName
- string Name
- string WithClassName
- ParameterInfo[] Parameters
- ReflectionAttributeList Attributes
- Type ReturnType
- object Invoke(object obj, params object[] param)
Property:
- ReflectionAttributeList Attributes
- string FullName
- string Name
- Type PropertyType
- string WithClassName
- object GetValue(object from)
- void SetValue(object to, object what)
Created by Artem Votincev (apmem.org)
Distributed under MIT license