ByChance.Core.Context.AlignTo C# (CSharp) Method

AlignTo() public method

Aligns this context to other, making Target of both contexts point to each other.
is null. This context or is already aligned to another context. has a different type than this context.
public AlignTo ( Context other ) : void
other Context Context to align this one to.
return void
        public void AlignTo(Context other)
        {
            if (other == null)
            {
                throw new ArgumentNullException("other");
            }

            if (this.Target != null)
            {
                throw new InvalidOperationException(
                    "The source context is already aligned to another context. "
                    + "Make sure to clear the target of the source context before aligning it to another one.");
            }

            if (other.Target != null)
            {
                throw new InvalidOperationException(
                    "The target context is already aligned to another context. "
                    + "Make sure to clear the target of the target context before aligning it to another one.");
            }

            if (this.GetType() != other.GetType())
            {
                throw new ArgumentException(
                    "The target context has a different type than the source context. "
                    + "Aligned contexts have to be of the same type.",
                    "other");
            }

            this.Target = other;
            other.Target = this;
        }