Пример #1
0
        /// <summary>
        /// Replace fields from another item
        /// </summary>
        /// <param name="item">DatItem to pull new information from</param>
        /// <param name="fields">List of Fields representing what should be updated</param>
        public override void ReplaceFields(DatItem item, List <Field> fields)
        {
            // Replace common fields first
            base.ReplaceFields(item, fields);

            // If we don't have a DipSwitch to replace from, ignore specific fields
            if (item.ItemType != ItemType.DipSwitch)
            {
                return;
            }

            // Cast for easier access
            DipSwitch newItem = item as DipSwitch;

            // Replace the fields

            #region Common

            if (fields.Contains(Field.DatItem_Name))
            {
                Name = newItem.Name;
            }

            if (fields.Contains(Field.DatItem_Tag))
            {
                Tag = newItem.Tag;
            }

            if (fields.Contains(Field.DatItem_Mask))
            {
                Mask = newItem.Mask;
            }

            // DatItem_Condition_* doesn't make sense here
            // since not every condition under the other item
            // can replace every condition under this item

            // DatItem_Location_* doesn't make sense here
            // since not every location under the other item
            // can replace every location under this item

            // DatItem_Setting_* doesn't make sense here
            // since not every value under the other item
            // can replace every value under this item

            #endregion

            #region SoftwareList

            if (PartSpecified && newItem.PartSpecified)
            {
                Part.ReplaceFields(newItem.Part, fields);
            }

            #endregion
        }
Пример #2
0
        public override bool Equals(DatItem other)
        {
            // If we don't have a DipSwitch, return false
            if (ItemType != other.ItemType)
            {
                return(false);
            }

            // Otherwise, treat it as a DipSwitch
            DipSwitch newOther = other as DipSwitch;

            // If the DipSwitch information matches
            bool match = (Name == newOther.Name &&
                          Tag == newOther.Tag &&
                          Mask == newOther.Mask);

            if (!match)
            {
                return(match);
            }

            // If the part matches
            if (PartSpecified)
            {
                match &= (Part == newOther.Part);
            }

            // If the conditions match
            if (ConditionsSpecified)
            {
                foreach (Condition condition in Conditions)
                {
                    match &= newOther.Conditions.Contains(condition);
                }
            }

            // If the locations match
            if (LocationsSpecified)
            {
                foreach (Location location in Locations)
                {
                    match &= newOther.Locations.Contains(location);
                }
            }

            // If the values match
            if (ValuesSpecified)
            {
                foreach (Setting value in Values)
                {
                    match &= newOther.Values.Contains(value);
                }
            }

            return(match);
        }