public static void Main() { Address sourceAddr = new Address(); sourceAddr.City = "Miami"; sourceAddr.Street = "Sterling Rd"; MapBindingTreeNodeContainer addressNodeContainer = new MapBindingTreeNodeContainer(); addressNodeContainer.TheObj = sourceAddr; addressNodeContainer .AddNewMapChild ( new PlainPropBindingPathLink<object>(nameof(Address.City)) ); addressNodeContainer .AddNewMapChild ( new PlainPropBindingPathLink<object>(nameof(Address.Street)) ); Contact sourceContact = new Contact() { FirstName = "Nick", HomeAddress = sourceAddr }; MapBindingTreeNodeContainer contactNodeContainer = new MapBindingTreeNodeContainer(); contactNodeContainer.AddChild ( new PlainPropBindingPathLink<object>(nameof(Contact.HomeAddress)), addressNodeContainer ); contactNodeContainer.AddNewMapChild ( new PlainPropBindingPathLink<object>(nameof(Contact.FirstName)) ); contactNodeContainer.TheObj = sourceContact; // change home address sourceAddr = new Address(); sourceAddr.City = "Boston"; sourceAddr.Street = "Blenford Rd"; sourceContact.HomeAddress = sourceAddr; }
public static void Main() { Address address = new Address { City = "Boston" }; Contact aContact = new Contact { HomeAddress = address }; PrintModel printModel = new PrintModel { HomeCityPrintObj = new PrintProp("Home City") }; OneWayPropertyBinding homeCityBinding = new OneWayPropertyBinding { SourcePropertyGetter = new CompositePathGetter<object> ( new List<BindingPathLink<object>> { new BindingPathLink<object>("HomeAddress"), new BindingPathLink<object>("City") }, null ) { TheObj = aContact } , TargetPropertySetter = new CompositePathSetter<object> ( new List<BindingPathLink<object>> { new BindingPathLink<object>("HomeCityPrintObj"), new BindingPathLink<object>("PropValueToPrint") } ) { TheObj = printModel } }; homeCityBinding.Bind(); printModel.Print(); address.City = "Miami"; printModel.Print(); }
public static void Main() { // we want to bind City property on the // source object's HomeAddress to City property on the // target object Contact sourceObj = new Contact(); Address sourceAddr = new Address(); sourceAddr.City = "Miami"; sourceObj.HomeAddress = sourceAddr; Address targetAddr = new Address(); StatelessBinding<Address> binding = new StatelessBinding<Address> ( (addr) => addr.City, (addr, cityObj) => addr.City = cityObj as string ); // this should bind them so, that // 1. they are sync'ed at the binding time // 2. the target is updated every time the source // is updated (since the source is notifiable) binding.AddObjsToBinding(sourceAddr, targetAddr); Console.WriteLine($"The Target City is '{targetAddr.City}'"); sourceAddr.City = "Holywood"; Console.WriteLine("\nAfter the change:"); Console.WriteLine($"The Target City is '{targetAddr.City}'"); // now change the whole HomeAddress object sourceObj.HomeAddress = new Address { City = "Ft. Lauderdale" }; Console.WriteLine("\nAfter the HomeAddress obj change:"); Console.WriteLine($"The Target City is '{targetAddr.City}'"); }