Adhesive 2.0.1-alpha

This is a prerelease version of Adhesive.
dotnet add package Adhesive --version 2.0.1-alpha
NuGet\Install-Package Adhesive -Version 2.0.1-alpha
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="Adhesive" Version="2.0.1-alpha" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Adhesive --version 2.0.1-alpha
#r "nuget: Adhesive, 2.0.1-alpha"
#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 Adhesive as a Cake Addin
#addin nuget:?package=Adhesive&version=2.0.1-alpha&prerelease

// Install Adhesive as a Cake Tool
#tool nuget:?package=Adhesive&version=2.0.1-alpha&prerelease

Adhesive

Adhesive gives you a multi-direction data binding for properties of objects that stick together. Adhesive is not intended to be used only for UI elements and can be used as method of connecting dissimilar APIs, etc.

Requirements

  • Any class who's member is used as the source for a binding, must implement INotifyPropertyChanged.
  • Properties should call OnPropertyChanged() when their value has been updated.
  • Properties must not call OnPropertyChanged() if they are set to the same value they already are (unless you don't intend on using TwoWayBindings).

Usage

All bindings, in one way or another, are some combination of a OneWayBinding internally.

Using the example classes:

public class Employee : INotifyPropertyChanged {

        private string _firstName;
        private string _lastName;

        public string FirstName {
            get => _firstName;
            set {
                if (_firstName == value) return;

                _firstName = value;
                OnPropertyChanged();
            }
        }

        public string LastName {
            get => _lastName;
            set {
                if (_lastName == value) return;

                _lastName = value;
                OnPropertyChanged();
            }
        }

        public Employee(string firstName, string lastName) {
            this.FirstName = firstName;
            this.LastName = lastName;
        }
        
        #region INotifyPropertyChanged

        public event PropertyChangedEventHandler PropertyChanged;

        private void OnPropertyChanged([CallerMemberName] string propertyName = null) {
            this.PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
        }

        #endregion

    }

    public class Nameplate {

        private string _inscribedName;

        public string InscribedName {
            get => _inscribedName;
            set {
                if (_inscribedName == value) return;

                _inscribedName = value;
                OnPropertyChanged();
            }
        }

        #region INotifyPropertyChanged

        public event PropertyChangedEventHandler PropertyChanged;

        private void OnPropertyChanged([CallerMemberName] string propertyName = null) {
            this.PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
        }

        #endregion

    }
OneWayBinding
var nameplateBinding = new Adhesive.OneWayBinding<string, string>(() => henrysNameplate.InscribedName, () => henry.FirstName);

Now, if henry.FirstName is set to any other value, henrysNameplate.InscribedName will immediately update to match it.

TwoWayBinding
var nameplateBinding = new Adhesive.TwoWayBinding<string, string>(
	() => henry.FirstName, 
	() => henrysNameplate.InscribedName, 
	 o => o.ToUpper(), 
	 o => o.ToLower(), 
	InitialBindingProcedure.ApplyRight
);

This will sync the values between henry.FirstName and henrysNameplate.InscribedName, but the value converters will ensure that henry.FirstName is always uppercase and henryNameplate.InscribedName is always lowercase.

ManyToOneBinding
var nameplateBinding = new Adhesive.ManyToOneBinding<string, string>(
	() => henrysNameplate.InscribedName,
	new List<Expression<Func<string>>>() {
		() => henry.FirstName,
		() => henry.LastName
	},
	 o => $"{henry.LastName}, {henry.FirstName}"
);

Updates to either henry.FirstName or henry.LastName will update henrysNameplate.InscribedName in the format "Lastname, Firstname."

OneToManyBinding

Sample Coming Soon

Allows for many properties to be updated when a single property is changed.

SyncBinding

Sample Coming Soon

All members are both source and target properties. A change to any property in the binding will be applied to all other members of the binding.

License

MIT

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.
  • .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
2.0.1-alpha 3,570 3/26/2019
1.0.2-alpha 400 3/19/2019
1.0.0-alpha 383 3/19/2019