https://github.com/apmem/reflectionutilities
Increse speed of your project by cache reflection operations (which is originally slow)
https://github.com/apmem/reflectionutilities
Last synced: about 1 year ago
JSON representation
Increse speed of your project by cache reflection operations (which is originally slow)
- Host: GitHub
- URL: https://github.com/apmem/reflectionutilities
- Owner: ApmeM
- License: mit
- Created: 2011-12-08T18:34:07.000Z (over 14 years ago)
- Default Branch: master
- Last Pushed: 2024-11-02T08:01:50.000Z (over 1 year ago)
- Last Synced: 2025-03-27T07:35:49.778Z (about 1 year ago)
- Language: C#
- Homepage:
- Size: 53.7 KB
- Stars: 13
- Watchers: 3
- Forks: 4
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Reflection Cache
## Introduction
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.
Performance test result :
| Method | Mean | Error | StdDev | Gen 0 | Allocated |
|------------------- |-----------:|--------:|--------:|-------:|----------:|
| UseReflectionCache | 395.5 ns | 3.47 ns | 3.07 ns | 0.0572 | 240 B |
| RegularReflection | 2,353.9 ns | 7.69 ns | 7.19 ns | 0.1068 | 456 B |
## Installation and usage
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:
1. static ReflectionClass GetReflection(Type t)
Class:
1. ReflectionAttributeList Attributes
2. Type BaseType
3. string FullName
4. ReflectionMethodList Methods
5. string Name
6. ReflectionPropertyList Properties
7. bool IsAssignableFrom(Type type)
Method:
1. string FullName
2. string Name
3. string WithClassName
4. ParameterInfo[] Parameters
5. ReflectionAttributeList Attributes
6. Type ReturnType
7. object Invoke(object obj, params object[] param)
Property:
1. ReflectionAttributeList Attributes
2. string FullName
3. string Name
4. Type PropertyType
5. string WithClassName
6. object GetValue(object from)
7. void SetValue(object to, object what)