HexagonSoftware.ExpressionTransforms
2021.6.15.3
dotnet add package HexagonSoftware.ExpressionTransforms --version 2021.6.15.3
NuGet\Install-Package HexagonSoftware.ExpressionTransforms -Version 2021.6.15.3
<PackageReference Include="HexagonSoftware.ExpressionTransforms" Version="2021.6.15.3" />
paket add HexagonSoftware.ExpressionTransforms --version 2021.6.15.3
#r "nuget: HexagonSoftware.ExpressionTransforms, 2021.6.15.3"
// Install HexagonSoftware.ExpressionTransforms as a Cake Addin #addin nuget:?package=HexagonSoftware.ExpressionTransforms&version=2021.6.15.3 // Install HexagonSoftware.ExpressionTransforms as a Cake Tool #tool nuget:?package=HexagonSoftware.ExpressionTransforms&version=2021.6.15.3
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 += SetterFactory.Parameterless.ToSetter(Selector);
}
...
}
This allows for a more semantically-meaningful call from the client's perspective.
var API = new MyCoolApi();
API.MapVersionNumberTo(() => this.VersionNumber);
Converting Abstract Read Expressions to Abstract Setters
You can also create a setter expression from a getter expression without knowing the object to be read/written in advance.
For instance, SetterFactory.ForParameter<MyObject>().ToSetter(O => O.Value)
will produce a setter Action
that accepts both an instance of MyObject
and a paramter suitable to be assigned to Value
.
Whenver invoked, that action will assign the Value
property on the object passed in as the first parameter.
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 was computed. 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. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.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 |