HexagonSoftware.ExpressionTransforms
2021.6.9.7
See the version list below for details.
dotnet add package HexagonSoftware.ExpressionTransforms --version 2021.6.9.7
NuGet\Install-Package HexagonSoftware.ExpressionTransforms -Version 2021.6.9.7
<PackageReference Include="HexagonSoftware.ExpressionTransforms" Version="2021.6.9.7" />
paket add HexagonSoftware.ExpressionTransforms --version 2021.6.9.7
#r "nuget: HexagonSoftware.ExpressionTransforms, 2021.6.9.7"
// Install HexagonSoftware.ExpressionTransforms as a Cake Addin #addin nuget:?package=HexagonSoftware.ExpressionTransforms&version=2021.6.9.7 // Install HexagonSoftware.ExpressionTransforms as a Cake Tool #tool nuget:?package=HexagonSoftware.ExpressionTransforms&version=2021.6.9.7
Expression Transformations is a utility library that relies of manipulation of System.Linq.Expressions.Expression
instances to simplify
basic tasks.
Examples
Following are examples of how and why you might want to use this library.
Converting Read Expressions to Setters
Sometimes, you want clients to be able to tell an API how to store a datum. Often, developers using such an API want to copy a value into a field or property of an object.
The norm in such cases, is to allow developers to pass an Action<T>
into an API. The API will then call that action with appropriate values at the appropriate time.
However, it often feels kludgy to a developer. They have to write expressions that capture values and do the assignment, themselves. For example.
var API = new MyCoolApi();
API.OnVersionNumberChanged += NewVersionNumber => this.VersionNumber = NewVersionNumber;
While it's a small nuisance, it is emblematic of the fact that client-developers are required to tell an API how to store a value, when what they really want to say is where the data should go.
Sometimes that's fine but sometimes it is not.
In the cases where you really want to allow for property mappings, you can define them using the ToSetter
extension method in this library.
class MyCoolApi
{
...
public void MapVersionNumberTo(Expression<Func<int>> Selector)
{
OnVersionNumberChanged += Selector.ToSetter().Compile();
}
...
}
This allows for a more semantically-meaningful call from the client's perspective.
var API = new MyCoolApi();
API.MapVersionNumberTo(() => this.VersionNumber);
Binding Targets for IObservable
s
Another example of the kind of problem you might want to solve with this is binding outgoing values from observables to the setters of properties as in the following code snippet.
var Observable = new Observable();
var Target = new Target();
Observable.BindTo(() => Target.Value);
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 is compatible. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
-
net5.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
2021.6.15.3 | 410 | 6/15/2021 |
2021.6.15.2 | 352 | 6/15/2021 |
2021.6.15.1 | 328 | 6/15/2021 |
2021.6.9.7 | 293 | 6/9/2021 |
2021.6.9.6 | 319 | 6/9/2021 |
2021.6.9.5 | 353 | 6/9/2021 |
2021.6.9.4 | 344 | 6/9/2021 |
2021.6.9.3 | 348 | 6/9/2021 |
2021.6.9.2 | 322 | 6/9/2021 |
2021.6.9.1 | 349 | 6/9/2021 |
2021.6.8.1 | 360 | 6/9/2021 |