Beispiel #1
0
        /// <summary>
        /// Inserts TaxObject newMember at index in the array. Throws and exception if TaxObject is null or index is out of range.
        /// </summary>
        /// <param name="newMember"></param>
        /// <param name="index"></param>
        /// <returns></returns>
        public virtual bool InsertArrayMember(TaxObject newMember, int index = -1)
        {
            if (index >= mArrayMembers.Count)
            {
                throw new Exception("Tried to insert an array member at an out-of-range index.");
            }

            if (newMember == null)
            {
                throw new Exception("Tried to insert a null TaxObject into an array.");
            }

            if (!mArrayMembers.Contains(newMember))
            {
                if (index < 0)
                {
                    mArrayMembers.Add(newMember);
                }
                else
                {
                    mArrayMembers.Insert(index, newMember);
                }

                newMember.AddBaseTypeReference(this);
                return(true);
            }

            return(false);
        }
Beispiel #2
0
        /// <summary>
        /// Attempts to set the value of the DataType to the data Object.
        /// </summary>
        /// <param name="data"> Represents the new value for the DataType. </param>
        /// <returns> True if the data is successfully set. </returns>
        public override bool SetData(object data)
        {
            if (data == null)
            {
                if (TaxObject != null)
                {
                    TaxObject.RemoveBaseTypeReference(this);
                }

                TaxObject = null;
                return(true);
            }
            else if (data is TaxObject)
            {
                TaxObject newObject = (TaxObject)data;
                if (newObject != TaxObject)
                {
                    if (TaxObject != null)
                    {
                        TaxObject.RemoveBaseTypeReference(this);
                    }

                    TaxObject = newObject;

                    if (TaxObject != null)
                    {
                        TaxObject.AddBaseTypeReference(this);
                    }


                    return(true);
                }

                return(false);
            }

            throw new Exception("Tried to set PointerType with bad data.");
        }