Beispiel #1
0
        // adds a enumeration (keyword, opcode, task or channel) represented by 'staticField'
        // to the manifest.  
        private static void AddProviderEnumKind(ManifestBuilder manifest, FieldInfo staticField, string providerEnumKind)
        {
            Type staticFieldType = staticField.FieldType;
            if (staticFieldType == typeof(EventOpcode))
            {
                if (providerEnumKind != "Opcodes") goto Error;
                int value = (int)staticField.GetRawConstantValue();
                if (value <= 10)
                    throw new ArgumentException(Environment.GetResourceString("EventSource_ReservedOpcode"));
                manifest.AddOpcode(staticField.Name, value);
            }
            else if (staticFieldType == typeof(EventTask))
            {
                if (providerEnumKind != "Tasks") goto Error;
                manifest.AddTask(staticField.Name, (int)staticField.GetRawConstantValue());
            }
            else if (staticFieldType == typeof(EventKeywords))
            {
                if (providerEnumKind != "Keywords") goto Error;
                manifest.AddKeyword(staticField.Name, (ulong)(long)staticField.GetRawConstantValue());
            }
#if FEATURE_MANAGED_ETW_CHANNELS
            else if (staticFieldType == typeof(EventChannel))
            {
                if (providerEnumKind != "Channels") goto Error;
                var channelAttribute = (ChannelAttribute)GetCustomAttributeHelper(staticField, typeof(ChannelAttribute));
                manifest.AddChannel(staticField.Name, (byte)staticField.GetRawConstantValue(), channelAttribute);
            }
#endif
            return;
        Error:
            throw new ArgumentException(Environment.GetResourceString("EventSource_EnumKindMismatch",  staticField.FieldType.Name, providerEnumKind));
        }