Example #1
0
        public PopulatedOrganizationWithDepartment()
        {
            WonkaFactory = new PopulatedOrganization();
            WonkaFactory.TheMostImportantDepartment = new Organization();

            _departmentNameBinding = new OneWayPropertyBindingWithPath();

            _departmentNameBinding.SourceObj = this;
            _departmentNameBinding.SourcePathLinks = StringCodePathResolver.ResolveStringPath("WonkaFactory.TheMostImportantDepartment.OrgName").ToList();

            _departmentNameBinding.TargetObj = this;
            _departmentNameBinding.TargetPathLinks = StringCodePathResolver.ResolveStringPath("DepartmentName").ToList();

            _departmentNameBinding.Bind();

            _departmentNameBinding.OnTargetSetEvent += _departmentNameBinding_OnTargetSetEvent;

            WonkaFactory.TheMostImportantDepartment.OrgName = "Chocolate Department";

            _departmentEventBinding = new OneWayPropertyBindingWithPath();
        }
Example #2
0
        void AddFieldBinding(TextFieldPresenter fieldPresenter, string propName)
        {
            OneWayPropertyBindingWithPath fieldBinding = new OneWayPropertyBindingWithPath();

            fieldBinding.SourceObj = TheClass;
            fieldBinding.SourcePathLinks = new List<BindingPathLink<object>>
            {
                new BindingPathLink<object>(propName)
            };
            fieldBinding.TargetObj = fieldPresenter;
            fieldBinding.TargetPathLinks = new List<BindingPathLink<object>> { new BindingPathLink<object>("TheValue") };

            fieldBinding.Bind();

            TheBindingsAProp.SetProperty(fieldPresenter, fieldBinding);
        }
Example #3
0
        static void Main(string[] args)
        {
            #region Plain C# to Plain C# property binding
            Console.WriteLine("\n\nTesting binding from plain property to another plain property\n");

            // initialize test objects
            MyTestDataClass sourceObj = new MyTestDataClass
            {
                MyStringProp = "Hello World"
            };

            MyTestDataClass targetObj = new MyTestDataClass();

            OneWayPropertyBindingWithPath<string, string> plainToPlainPropBinding =
                new OneWayPropertyBindingWithPath<string, string>();

            plainToPlainPropBinding.SourceObj = sourceObj;
            plainToPlainPropBinding.SourcePPath = new BindingPathLink<string>("MyStringProp");
            plainToPlainPropBinding.TargetObj = targetObj;
            plainToPlainPropBinding.TargetPPath = new BindingPathLink<string>("MyStringProp");

            // bind the two properties.
            plainToPlainPropBinding.Bind();

            // verify that the binding changed the target property
            // to be the same as the source property
            Console.Write("Testing target property change after binding operation: ");
            Console.WriteLine(targetObj.MyStringProp); // should print Hello World;

            // let us change the source property and verify that target property also changes
            sourceObj.MyStringProp = "Hi World";
            Console.Write("Testing target property change after the source property change: ");
            Console.WriteLine(targetObj.MyStringProp); // should print Hi World;

            #endregion Plain C# to Plain C# property binding

            #region AProperty to AProperty binding
            Console.WriteLine("\n\nTesting binding from plain property to another plain property\n");

            AProperty<object, string> myAProperty = new AProperty<object, string>();

            // reinitialize test objects
            sourceObj = new MyTestDataClass();
            targetObj = new MyTestDataClass();

            // set AProperty on the source object before the binding
            myAProperty.SetProperty(sourceObj, "Hello World");

            OneWayPropertyBinding<string, string> aPropToAPropBinding = new OneWayPropertyBinding<string, string>();

            aPropToAPropBinding.SourceObj = sourceObj;
            aPropToAPropBinding.SourcePPath = new BindingPathLink<string>(myAProperty);
            aPropToAPropBinding.TargetObj = targetObj;
            aPropToAPropBinding.TargetPPath = new BindingPathLink<string>(myAProperty);

            aPropToAPropBinding.Bind();

            Console.Write("Testing target property change after binding operation: ");
            Console.WriteLine(myAProperty.GetProperty(targetObj));

            // change the source property
            myAProperty.SetProperty(sourceObj, "Hi World");

            Console.Write("Testing target property change after the source property change: ");
            Console.WriteLine(myAProperty.GetProperty(targetObj));

            #endregion AProperty to AProperty binding

            #region plain property to AProperty binding

            Console.WriteLine("\n\nTesting binding from plain property to AProp\n");

            // reinitialize test objects
            sourceObj = new MyTestDataClass
            {
                MyStringProp = "Hello World"
            };

            targetObj = new MyTestDataClass();

            OneWayPropertyBinding<string, string> plainToAPropBinding = new OneWayPropertyBinding<string, string>();
            plainToAPropBinding.SourcePPath = new BindingPathLink<string>("MyStringProp") { DefaultValue = "blablabla" };
            plainToAPropBinding.TargetObj = targetObj;
            plainToAPropBinding.TargetPPath = new BindingPathLink<string>(myAProperty);

            plainToAPropBinding.Bind();

            Console.Write("Testing target property change after binding operation without source object (default value will be used): ");
            Console.WriteLine(myAProperty.GetProperty(targetObj));

            plainToAPropBinding.SourceObj = sourceObj;

            Console.Write("Testing target property change after binding operation with source object: ");
            Console.WriteLine(myAProperty.GetProperty(targetObj));

            sourceObj.MyStringProp = "Hi World";
            Console.Write("Testing target property change after the source property change: ");
            Console.WriteLine(myAProperty.GetProperty(targetObj));

            #endregion plain property to AProperty binding

            #region AProperty to plain property binding

            Console.WriteLine("\n\nTesting binding from AProp to plain property\n");

            // reinitialize test objects
            sourceObj = new MyTestDataClass();
            targetObj = new MyTestDataClass();

            myAProperty.SetProperty(sourceObj, "Hello World");

            OneWayPropertyBinding<string, string> aPropToPlainBinding = new OneWayPropertyBinding<string, string>();
            aPropToPlainBinding.SourceObj = sourceObj;
            aPropToPlainBinding.SourcePPath = new BindingPathLink<string>(myAProperty);
            aPropToPlainBinding.TargetObj = targetObj;
            aPropToPlainBinding.TargetPPath = new BindingPathLink<string>("MyStringProp");

            aPropToPlainBinding.Bind();

            Console.Write("Testing target property change after binding operation: ");
            Console.WriteLine(targetObj.MyStringProp);

            myAProperty.SetProperty(sourceObj, "Hi World");

            Console.Write("Testing target property change after the source property change: ");
            Console.WriteLine(targetObj.MyStringProp);

            #endregion AProperty to plain property binding
        }