Cogs.ActiveExpressions
1.15.0
See the version list below for details.
dotnet add package Cogs.ActiveExpressions --version 1.15.0
NuGet\Install-Package Cogs.ActiveExpressions -Version 1.15.0
<PackageReference Include="Cogs.ActiveExpressions" Version="1.15.0" />
paket add Cogs.ActiveExpressions --version 1.15.0
#r "nuget: Cogs.ActiveExpressions, 1.15.0"
// Install Cogs.ActiveExpressions as a Cake Addin #addin nuget:?package=Cogs.ActiveExpressions&version=1.15.0 // Install Cogs.ActiveExpressions as a Cake Tool #tool nuget:?package=Cogs.ActiveExpressions&version=1.15.0
This library accepts a LambdaExpression
and arguments to pass to it, dissects the LambdaExpression
's body, and hooks into change notification events for properties (INotifyPropertyChanged
), collections (INotifyCollectionChanged
), and dictionaries (Cogs.Collections.INotifyDictionaryChanged
).
// Employee implements INotifyPropertyChanged
var elizabeth = Employee.GetByName("Elizabeth");
var expr = ActiveExpression.Create(e => e.Name.Length, elizabeth);
// expr subscribed to elizabeth's PropertyChanged
Then, as changes involving any elements of the expression occur, a chain of automatic re-evaluation will get kicked off, possibly causing the active expression's Value
property to change.
var elizabeth = Employee.GetByName("Elizabeth");
var expr = ActiveExpression.Create(e => e.Name.Length, elizabeth);
// expr.Value == 9
elizabeth.Name = "Lizzy";
// expr.Value == 5
Also, since exceptions may be encountered after an active expression was created due to subsequent element changes, active expressions also have a Fault
property, which will be set to the exception that was encountered during evaluation.
var elizabeth = Employee.GetByName("Elizabeth");
var expr = ActiveExpression.Create(e => e.Name.Length, elizabeth);
// expr.Fault is null
elizabeth.Name = null;
// expr.Fault is NullReferenceException
Active expressions raise property change events of their own, so listen for those (kinda the whole point)!
var elizabeth = Employee.GetByName("Elizabeth");
var expr = ActiveExpression.Create(e => e.Name.Length, elizabeth);
expr.PropertyChanged += (sender, e) =>
{
if (e.PropertyName == "Fault")
{
// Whoops
}
else if (e.PropertyName == "Value")
{
// Do something
}
};
When you dispose of your active expression, it will disconnect from all the events.
var elizabeth = Employee.GetByName("Elizabeth");
using (var expr = ActiveExpression.Create(e => e.Name.Length, elizabeth))
{
// expr subscribed to elizabeth's PropertyChanged
}
// expr unsubcribed from elizabeth's PropertyChanged
Active expressions will also try to automatically dispose of disposable objects they create in the course of their evaluation when and where it makes sense. Use the ActiveExpressionOptions
class for more direct control over this behavior.
You can use the static property Optimizer
to specify an optimization method to invoke automatically during the active expression creation process. We recommend Tuomas Hietanen's Linq.Expression.Optimizer, the utilization of which would like like so:
ActiveExpression.Optimizer = ExpressionOptimizer.tryVisit;
var a = Expression.Parameter(typeof(bool));
var b = Expression.Parameter(typeof(bool));
var lambda = Expression.Lambda<Func<bool, bool, bool>>
(
Expression.AndAlso
(
Expression.Not(a),
Expression.Not(b)
),
a,
b
); // lambda explicitly defined as (a, b) => !a && !b
var expr = ActiveExpression.Create<bool>(lambda, false, false);
// optimizer has intervened and defined expr as (a, b) => !(a || b)
// (because Augustus De Morgan said they're essentially the same thing, but this involves less steps)
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 | netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.1 is compatible. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | 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.1
- Cogs.Collections (>= 1.9.3)
- Cogs.Components (>= 1.1.0)
- Cogs.Disposal (>= 1.3.2)
- Cogs.Reflection (>= 1.4.4)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on Cogs.ActiveExpressions:
Package | Downloads |
---|---|
Cogs.ActiveQuery
Cogs for active queries. |
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
1.17.2 | 468 | 2/10/2023 |
1.17.1 | 489 | 1/26/2023 |
1.17.0 | 268 | 1/26/2023 |
1.16.1 | 472 | 1/21/2023 |
1.16.0 | 462 | 5/17/2022 |
1.15.2 | 3,056 | 4/12/2022 |
1.15.1 | 456 | 4/12/2022 |
1.15.0 | 466 | 4/12/2022 |
1.14.4 | 671 | 4/11/2022 |
1.14.3 | 2,159 | 12/21/2021 |
1.14.2 | 911 | 12/16/2021 |
1.14.1 | 304 | 12/7/2021 |
1.14.0 | 809 | 11/3/2021 |
1.12.0 | 1,495 | 2/20/2021 |
1.11.0 | 657 | 2/8/2021 |
1.10.6 | 515 | 2/1/2021 |
1.10.5 | 532 | 1/30/2021 |
1.10.4 | 374 | 1/30/2021 |
1.10.3 | 620 | 11/23/2020 |
1.10.2 | 543 | 11/22/2020 |
1.10.1 | 1,612 | 10/19/2020 |
1.10.0 | 835 | 9/28/2020 |
1.9.2 | 784 | 9/27/2020 |
1.9.1 | 745 | 9/27/2020 |
1.9.0 | 759 | 9/27/2020 |
1.8.2 | 513 | 6/2/2020 |
1.8.1 | 655 | 6/2/2020 |
1.8.0 | 520 | 6/2/2020 |
1.7.2 | 871 | 5/26/2020 |
1.7.1 | 652 | 5/26/2020 |
1.7.0 | 494 | 5/26/2020 |
1.6.2 | 497 | 5/26/2020 |
1.6.1 | 750 | 5/17/2020 |
1.6.0 | 695 | 5/15/2020 |
1.5.3 | 449 | 5/13/2020 |
1.5.2 | 840 | 5/13/2020 |
1.5.1 | 715 | 5/13/2020 |
1.5.0 | 674 | 5/12/2020 |
1.4.0 | 678 | 5/9/2020 |
1.3.0 | 664 | 5/9/2020 |
1.2.0 | 1,085 | 4/29/2020 |
1.1.1 | 684 | 4/17/2020 |
1.1.0 | 860 | 4/11/2020 |
1.0.2 | 887 | 3/4/2020 |
1.0.1 | 495 | 3/3/2020 |
1.0.0 | 493 | 3/3/2020 |
We added IObservableActiveExpression and IObserveActiveExpressions to implement an observer pattern to internally replace the property change pattern from the BCL's component model. This eliminates the need to allocate property change handler delegates on the heap and can have a dramatic impact on performance and memory usage. Also, the public ActiveExpression classes are now sealed (breaking if you derived from them).