TypedColumnBasedataTypeBindValue(FuncdataType) Method

Binds the value of this column to the specified expression

Definition

Namespace: Firefly.Box.Data.Advanced
Assembly: Firefly.Box (in Firefly.Box.dll) Version: debug-master-v:33791
C#
public TypedColumnBase<dataType> BindValue(
	Func<dataType> expression
)

Parameters

expression  FuncdataType

Return Value

TypedColumnBasedataType

Remarks

The expression specified will determine the column's value in one of the following scenarios:
  • The column is bound to an entity, and a new row is created
  • The column is NOT bound to an entity, and a row is entered
  • One of the expression's elements change, acording to the reevaluation engine. For more information see Columns

Example

This example demonstrates the usage of ColumnsCollection
This example is in the form of Unit Tests. It references the NUnit framework. This framework can be downloaded from www.NUnit.org. For more information about unit testing visit: www.NUnit.org.
C#
using System;
using System.Collections.Generic;
using System.Text;
using Firefly.Box.Data;
using NUnit.Framework;
using Firefly.Box;
using Firefly.Box.Testing;

namespace TestFirefly.Box.Documentation
{
    [TestFixture]
    public class ColumnsCollection
    {
        [Test]
        public void BasicReevaluation()
        {
            var bp = new BusinessProcess();
            NumberColumn a = new NumberColumn(),
                         b = new NumberColumn();
            bp.Columns.Add(a, b);
            b.BindValue(() => a + 5);

            bp.ForFirstRow(() =>
            {
                a.ShouldBe(0);
                b.ShouldBe(5);
                a.Value = 6;
                a.ShouldBe(6);
                b.ShouldBe(11);
            });
        }
        [Test]
        public void ReevaluationIsNotDoneBeforeAnyRowWasEntered()
        {
            var bp = new BusinessProcess();
            NumberColumn a = new NumberColumn(),
                         b = new NumberColumn();
            bp.Columns.Add(a, b);
            b.BindValue(() => a + 5);
            bp.Start += () =>
            {
                a.ShouldBe(0);
                b.ShouldBe(0); //Because a row was not entered, and no value was set,
                //the reevaluation of b was not performed
            };
            bp.ForFirstRow(() =>
            {
                a.ShouldBe(0);
                b.ShouldBe(5);
                a.Value = 6;
                a.ShouldBe(6);
                b.ShouldBe(11);
            });
        }

    }
}

See Also