Exemple #1
0
        /// <summary>
        /// Checks if this object equals another object.
        /// </summary>
        /// <param name="obj">The object to compare to</param>
        /// <returns>True if the objects are equal, false if not</returns>
        public override bool Equals(object obj)
        {
            NumberValue nv = obj as NumberValue;

            if (nv == null)
            {
                return(false);
            }

            return(this.CompareTo(nv) == 0);
        }
Exemple #2
0
        /// <summary>
        /// Compare this value to another MIB Value
        /// </summary>
        /// <param name="other">The MIB Value to compare against</param>
        /// <returns>
        /// Zero (0) if the objects are equal, an non-zero integer value if not
        /// </returns>
        public override int CompareTo(MibValue other)
        {
            NumberValue nv = other as NumberValue;

            if (nv != null)
            {
                return(this.CompareToNumber((double)nv.Value));
            }

            return(this.ToString().CompareTo(other));
        }
Exemple #3
0
        /// <summary>
        /// Initializes the MIB value. This will remove all levels of
        /// indirection present, such as references to other values. No
        /// value information is lost by this operation. This method may
        /// modify this object as a side-effect, and will return the basic
        /// value.
        /// </summary>
        /// <remarks>
        /// This is an internal method that should only be called by
        /// the MIB loader.
        /// </remarks>
        /// <param name="log">The MIB loader log</param>
        /// <param name="type">The value type</param>
        /// <returns>The basic MIB value</returns>
        public override MibValue Initialize(MibLoaderLog log, MibType type)
        {
            int bytes  = (this.minLength / 2) + ((this.minLength % 2 > 0) ? 1 : 0);
            int length = NumberValue.GetByteSize(type, bytes) * 2;

            if (length > this.minLength)
            {
                this.minLength = length;
            }

            return(this);
        }
        /// <summary>
        /// Initializes a the MIB value from a value reference. This will
        /// resolve the reference, and set the bit corresponding to the
        /// value.
        /// </summary>
        /// <param name="log">The MIB loader log</param>
        /// <param name="type">The value type</param>
        /// <param name="vref">The value reference to resolve</param>
        /// <exception cref="MibException">
        /// If an error occurred during initialization
        /// </exception>
        private void Initialize(MibLoaderLog log, MibType type, ValueReference vref)
        {
            MibValue val = vref.Initialize(log, type);

            NumberValue nv = val as NumberValue;

            if (nv != null)
            {
                this.value.Set((int)nv.Value, true);
            }
            else
            {
                throw new MibException(
                          vref.Location,
                          "referenced value is not a number");
            }
        }