Example #1
0
        /// <summary>
        /// Initializes the MIB type. This will remove all levels of
        /// indirection present, such as references to types or values. No
        /// information is lost by this operation. This method may modify
        /// this object as a side-effect, and will return the basic
        /// type.
        /// NOTE: This is an internal method that should
        /// only be called by the MIB loader.
        /// </summary>
        /// <param name="symbol">The MIB symbol containing this type</param>
        /// <param name="log">The MIB loader log</param>
        /// <returns>The basic MIB type</returns>
        public override MibType Initialize(MibSymbol symbol, MibLoaderLog log)
        {
            if (!(symbol is MibValueSymbol))
            {
                throw new MibException(
                          symbol.Location,
                          "only values can have the " + Name + " type");
            }

            this.syntax = this.syntax.Initialize(symbol, log);

            SnmpObjectType.CheckType((MibValueSymbol)symbol, log, this.syntax);

            foreach (SnmpIndex si in this.index)
            {
                si.Initialize(symbol, log);
            }

            if (this.augments != null)
            {
                this.augments = this.augments.Initialize(log, this.syntax);
            }

            if (this.defaultValue != null)
            {
                this.defaultValue = this.defaultValue.Initialize(log, this.syntax);
            }

            return(this);
        }
 /// <summary>
 /// Validates a MIB type. This will check any sequences and make
 /// sure their elements are present in the MIB file. If they are
 /// not, new symbols will be added to the MIB.
 /// </summary>
 /// <param name="symbol">The MIB symbol containing this type</param>
 /// <param name="log">The MIB loader log</param>
 /// <param name="type">The MIB type to check</param>
 /// <exception cref="MibException">
 /// If an error was encountered during the validation
 /// </exception>
 private static void CheckType(
     MibValueSymbol symbol,
     MibLoaderLog log,
     MibType type)
 {
     if (type is SequenceOfType sequence)
     {
         SnmpObjectType.CheckType(symbol, log, sequence.ElementType);
     }
     else if (type is SequenceType tp)
     {
         IList <ElementType> elems = tp.AllElements.ToList();
         for (int i = 0; i < elems.Count(); i++)
         {
             SnmpObjectType.CheckElement(symbol, log, elems[i], i + 1);
         }
     }
 }