ExpressWalker.Core 2.1.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package ExpressWalker.Core --version 2.1.0                
NuGet\Install-Package ExpressWalker.Core -Version 2.1.0                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="ExpressWalker.Core" Version="2.1.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add ExpressWalker.Core --version 2.1.0                
#r "nuget: ExpressWalker.Core, 2.1.0"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install ExpressWalker.Core as a Cake Addin
#addin nuget:?package=ExpressWalker.Core&version=2.1.0

// Install ExpressWalker.Core as a Cake Tool
#tool nuget:?package=ExpressWalker.Core&version=2.1.0                

ExpressWalker provides a generic way to examine and change any object graph in fashion similar to "Visitor Pattern". You can build generic hierarchy composition (visitor) that can visit and change any object's property, basing on configuration. Relies on expression trees while visiting objects (uses reflection only once while building a visitor). That's why IT IS WAY FASTER than custom solutions built with reflection.
It is protected from circular references so you can avoid exceptions. Provides fluent API which increases code readability in terms of guessing the hierarchy being built from the code. Some of functionalities: visiting properties by matching owner type, property name and type (or only property type), visiting collecitons and dictionary items, specifying depth, custom expression for changing property value, cloning etc.

//example 1 - IVisitor that visits properties by ownner type and property names and/or types (start from TypeWalker class):

 var typeVisitor = TypeWalker<Parent>.Create()
                 .ForProperty<Parent, string>(p => p.TestString1, (old, met) => old + met)
                 .ForProperty<Child, DateTime>(p => p.TestDate1, (old, met) => old.AddYears(10))
                 .ForProperty<CommonType>((old, met) => new CommonType { CommonString = "..." })
                 .Build(depth:10, guard:new PropertyGuard(), supportsCloning: true);
 
//guard is protection against type-wise circular references. supportsCloning = false improves build time.
 
 var parentClone = new Parent();
 var propertyValues = new HashSet<PropertyValue>()
 typeVisitor.Visit(parentObject, parentClone, depth:10, guard:new InstanceGuard(), values:propertyValues);

//guard is protection against instance-wise circular references. values will hold flat list of new/old values.
 
//example 2 - IVisitor that visits properties by explicit configuration (start from ManualWalker class):

 var manualVisitor = ManualWalker.Create<A1>()
                                   .Property<A1, DateTime>(a1 => a1.A1Date, (va1, met) => va1.AddYears(10))
                                   .Element<A1, B1>(a1 => a1.B1, b1 =>
                                           b1.Property<B1, string>(x => x.B1Name, (vb1, met) => vb1 + "Test2"))
                                   .Collection<A1, B2>(a1 => a1.B2List, b2 => b2
                                           .Property<B2, DateTime>(x => x.B2Date, (vb2, met) => vb2.AddYears(10)))
                               .Build();

 manualVisitor.Visit(parentObject, blueprint:null, depth:10, guard:new InstanceGuard(), values:null);

//Paremeter 'met' in expressions above is optional metadata object set in design-time.
//It can be set by [VisitorMetadata] property attribute in visited class.
//e.g. in example above, there is [VisitorMetadata("AnyString")] on property Parent.TestString1.

//example 3 - IVisitor built and cached using the IVisitorsFactory:
//scenario for visitors of same settings built for different types:
 
 var factory = new VisitorsFactory().WithSettings("name1", depth:5, usePropertyGuard:false, supportsCloning:false)
                                      .ForProperty<int>((val, met) => 2)
                                    .WithSettings("name6")
                                      .ForProperty<Parent, string>( x => x.Name, (val, met) => "t");

 var visitor1 = factory.GetVisitor("name1", typeof(Class1));
 var visitor1a = factory.GetVisitor("name1", typeof(Class1));
 var visitor2 = factory.GetVisitor("name1", typeof(Class2));
 var visitor6 = factory.GetVisitor("name6", typeof(Class6));
 
//visitor1 == visitor1a --true
//visitor1 == visitor2 --false

Many thanks to Francisco José Rey Gozalo for contributing with ideas and solutions.
Read more on https://github.com/kopalite/ExpressWalker

Product 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

This package has 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
5.0.0.1 814 1/29/2021
2.1.0.1 708 4/23/2019
2.1.0 653 4/23/2019

Visiting dictionary values is now supported. IVisitorsFactory can be used for building visitors for many types basing on the same settings. It caches visitors instances and use them as singletons - this will minimize boilerplate code you need to write. [VisitorHierarchy] attribute can be used to mark structures that are build as compositions (hierarchies) - that helps improving visitors build time.