Exemplo n.º 1
0
        /// <summary>
        /// Resolves changes in assignment methods.
        /// </summary>
        /// <param name="old">The current assignment method.</param>
        /// <param name="newA">The assignment method that may be used in the future.</param>
        protected void HandleAssignmentChange(IAssignment old, IAssignment newA)
        {
            // Don't do anything when the assignments are equal.
            var areEqual = old.GetType().Equals(newA.GetType());

            if (areEqual)
            {
                return;
            }

            // Assign the new assignment method.
            Assignment = newA;

            // If the new assignment is a name assignment, a new name object should be assigned.
            if (newA is NameAssignment)
            {
                Object = new NameObject();
                return;
            }

            // If the assignment method switches from the name object, there should be a new object to write to.
            if (old is NameAssignment && !(newA is NameAssignment))
            {
                var nameObject = Object as NameObject;
                var name       = nameObject?.Name?.Trim() ?? "";
                if (name.Length > 0)
                {
                    CreateObject(name);
                }
            }
        }