コード例 #1
0
        /// <summary>
        /// Gets the index of the corresponding PacketDefinition, if cached.
        /// Otherwise, returns -1.
        /// </summary>
        /// <param name="packet">IPacket object for which a PacketDefinition may be cached</param>
        public int IndexOf(IPacket packet)
        {
            // Most packets have a static field structure.  But some packets, such as EventMetrics, have a
            // dynamic set of fields determined at run-time.  In this case, we want to cache a distinct
            // PacketDefinition for each set of field definitions associated with the type.
            // Classes that require this dynamic type capability should implement IDynamicPacket which
            // will define a DynamicTypeName field on the packet.  This field will be automatically
            // serialized in the PacketDefinition and the DynamictTypeName is apppeded to the static
            // type name for purposes of indexing in this collection.
            string         typeName = packet.GetType().Name;
            IDynamicPacket dynamicPacket;

            if (packet is GenericPacket)
            {
                typeName = packet.GetPacketDefinition().QualifiedTypeName;
            }
            else if ((dynamicPacket = packet as IDynamicPacket) != null)
            {
                typeName += "+" + dynamicPacket.DynamicTypeName;
            }

            return(IndexOf(typeName));
        }