An open API service indexing awesome lists of open source software.

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

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

benchmark