https://github.com/usercode/fastpropertyaccessor
Fast C# property accessor without using reflection
https://github.com/usercode/fastpropertyaccessor
csharp dotnet
Last synced: 3 months ago
JSON representation
Fast C# property accessor without using reflection
- Host: GitHub
- URL: https://github.com/usercode/fastpropertyaccessor
- Owner: usercode
- License: mit
- Created: 2022-07-20T21:22:25.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2022-12-29T20:31:31.000Z (over 2 years ago)
- Last Synced: 2025-01-30T04:25:54.584Z (5 months ago)
- Topics: csharp, dotnet
- Language: C#
- Homepage:
- Size: 29.3 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# FastPropertyAccessor
Fast property accessor without using reflection## Sample
```csharp
Model model = new Model();
model.Amount = 100;//name property info
PropertyInfo pi = model.GetType().GetProperty(nameof(Model.Amount));//name property accessor
PropertyAccessor accessor = PropertyAccessor.Get(pi);//get value
int amount = (int)accessor.GetValue(model);//set value
accessor.SetValue(model, 200);//prevent boxing/unboxing for primitive types
int amount2 = accessor.GetInt32Value(model);accessor.SetInt32Value(model, 200);
//use TypeAccessor
TypeAccessor typeAccessor = TypeAccessor.Get(model.GetType());typeAccessor[model, "Amount"] = 100;
//enumerate properties
foreach(PropertyAccessor property in typeAccessor)
{
//access to property
}
```## Benchmark