Пример #1
0
        public static OpcodeDescriptorAttribute GetDescriptor(this InstructionOpcode opcode)
        {
            // Check our cache for our descriptor.
            if (_cachedDescriptors.TryGetValue(opcode, out var val))
            {
                return(val);
            }

            // Cache miss, obtain our enum option's field info
            FieldInfo fi = opcode.GetType().GetField(opcode.ToString());

            if (fi == null)
            {
                return(null);
            }

            // Obtain all attributes of type we are interested in.
            var attributes = fi.GetCustomAttributes <OpcodeDescriptorAttribute>(false).ToArray();

            // If one exists, cache it and return it.
            if (attributes != null && attributes.Length > 0)
            {
                _cachedDescriptors[opcode] = attributes[0];
                return(attributes[0]);
            }

            return(null);
        }
Пример #2
0
        public static OpcodeBaseGasCostAttribute[] GetBaseGasCosts(this InstructionOpcode opcode)
        {
            // Cache miss, obtain our enum option's field info
            FieldInfo fi = opcode.GetType().GetField(opcode.ToString());

            if (fi == null)
            {
                return(null);
            }

            // Obtain all attributes of type we are interested in.
            var attributes = fi.GetCustomAttributes <OpcodeBaseGasCostAttribute>(false).ToArray();

            return(attributes);
        }