Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ionite34/compiledexpressions
Create Compiled Delegates from Expressions with nested member support and binding accessibility checking. AOT compatible with no run-time reflection.
https://github.com/ionite34/compiledexpressions
Last synced: 17 days ago
JSON representation
Create Compiled Delegates from Expressions with nested member support and binding accessibility checking. AOT compatible with no run-time reflection.
- Host: GitHub
- URL: https://github.com/ionite34/compiledexpressions
- Owner: ionite34
- License: mit
- Created: 2024-07-29T00:57:50.000Z (5 months ago)
- Default Branch: main
- Last Pushed: 2024-08-03T20:26:24.000Z (5 months ago)
- Last Synced: 2024-12-06T12:14:34.761Z (about 1 month ago)
- Language: C#
- Homepage:
- Size: 46.9 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# CompiledExpressions
[![NuGet Version](https://img.shields.io/nuget/v/CompiledExpressions)](https://www.nuget.org/packages/CompiledExpressions)
[![Build](https://github.com/ionite34/CompiledExpressions/actions/workflows/build.yml/badge.svg)](https://github.com/ionite34/CompiledExpressions/actions/workflows/build.yml)
[![codecov](https://codecov.io/gh/ionite34/CompiledExpressions/branch/main/graph/badge.svg?token=Uyd765s2KE)](https://codecov.io/gh/ionite34/CompiledExpressions)
![GitHub License](https://img.shields.io/github/license/ionite34/CompiledExpressions)Create Compiled Delegates like Setters from Getter expressions
- Any level of nesting member support (i.e. `x => x.Prop1.Prop2.Prop3`)
- Bind time error and accessibility checking. (i.e. Getters without a Setter or with a private Setter)
- NativeAOT compatible with no run-time reflection.## Usage
> Full Sample Project: [CompiledExpressions.Sample](./CompiledExpressions.Sample)
1. For a library method, call `CompiledExpression.CreateAccessor` with a property/field access expression. This returns a [`CompiledAccessor`](CompiledExpressions/ComponentModel/CompiledAccessor.cs) struct with `Get(T instance)` and `Set(T instance, TValue value)` methods. The `MemberNames` property contains an array of the member names in the original expression.
```csharp
using System;
using System.Linq.Expressions;
using CompiledExpressions;public static class Example
{
public static void Bind(
T target,
Expression> targetMember
)
{
var accessor = CompiledExpression.CreateAccessor(targetMember);
// Get the existing value
var value = accessor.Get(target);
// Set a new value
accessor.Set(target, value);
// Get the member names
var memberNames = accessor.MemberNames; // ["Prop1", "Prop2", "Prop3"]
var memberPath = accessor.FullName; // "Prop1.Prop2.Prop3"
}
}
```## License
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.