コード例 #1
0
        private byte[] CreateManifestAndDescriptors(string providerDllName)
        { 
            Type providerType = this.GetType();
            MethodInfo[] methods = providerType.GetMethods(BindingFlags.DeclaredOnly | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance);
            EventAttribute defaultEventAttribute = new EventAttribute(0);
            int eventId = 1;        // The number given to an event that does not have a explicitly given ID. 
            m_eventData = new EventData[methods.Length];
            ManifestBuilder manifest = new ManifestBuilder(Name, Guid, providerDllName); 
 
            // Collect task, opcode, keyword and channel information
            FieldInfo[] staticFields = providerType.GetFields(BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static); 
            if (staticFields.Length > 0)
            {
                foreach (FieldInfo staticField in staticFields)
                { 
                    Type staticFieldType = staticField.FieldType;
                    if (staticFieldType == typeof(EventOpcode)) 
                        manifest.AddOpcode(staticField.Name, (int)staticField.GetRawConstantValue()); 
                    else if (staticFieldType == typeof(EventTask))
                        manifest.AddTask(staticField.Name, (int)staticField.GetRawConstantValue()); 
                    else if (staticFieldType == typeof(EventKeywords))
                        manifest.AddKeyword(staticField.Name, (ulong)(long)staticField.GetRawConstantValue());
                    else if (staticFieldType == typeof(EventChannel))
                        manifest.AddChannel(staticField.Name, (int)staticField.GetRawConstantValue()); 
                }
            } 
 
            for (int i = 0; i < methods.Length; i++)
            { 
                MethodInfo method = methods[i];
                ParameterInfo[] args = method.GetParameters();

                // Get the EventDescriptorInternal (from the Custom attributes) 
                EventAttribute eventAttribute = (EventAttribute)Attribute.GetCustomAttribute(method, typeof(EventAttribute), false);
 
                // Methods that don't return void can't be events. 
                if (method.ReturnType != typeof(void))
                { 
                    if (eventAttribute != null && DoDebugChecks())
                        throw new ArgumentException("Event attribute placed on method " + method.Name + " which does not return 'void'");
                    continue;
                } 
                if (method.IsVirtual || method.IsStatic)
                { 
                    continue; 
                }
 
                if (eventAttribute == null)
                {
                    // If we explictly mark the method as not being an event, then honor that.
                    if (Attribute.GetCustomAttribute(method, typeof(NonEventAttribute), false) != null) 
                        continue;
 
                    defaultEventAttribute.EventId = eventId; 
                    defaultEventAttribute.Opcode = EventOpcode.Info;
                    defaultEventAttribute.Task = EventTask.None; 
                    eventAttribute = defaultEventAttribute;
                }
                else if (eventAttribute.EventId <= 0)
                    throw new ArgumentException("Event IDs <= 0 are illegal."); 
                eventId++;
 
                if (eventAttribute.Opcode == EventOpcode.Info && eventAttribute.Task == EventTask.None) 
                    eventAttribute.Opcode = (EventOpcode)(10 + eventAttribute.EventId);
 
                manifest.StartEvent(method.Name, eventAttribute);
                for (int fieldIdx = 0; fieldIdx < args.Length; fieldIdx++)
                    manifest.AddEventParameter(args[fieldIdx].ParameterType, args[fieldIdx].Name);
                manifest.EndEvent(); 

                if (DoDebugChecks()) 
                    DebugCheckEvent(method, eventAttribute); 
                AddEventDescriptor(eventAttribute);
            } 
            TrimEventDescriptors();
            m_eventsByName = null;

            return manifest.CreateManifest(); 
        }
コード例 #2
0
        private byte[] CreateManifestAndDescriptors(string providerDllName)
        {
            Type type = base.GetType();

            MethodInfo[]   methods   = type.GetMethods(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly);
            EventAttribute attribute = new EventAttribute(0);
            int            num       = 1;

            this.m_eventData = new EventData[methods.Length];
            ManifestBuilder builder = new ManifestBuilder(this.Name, this.Guid, providerDllName);

            FieldInfo[] fields = type.GetFields(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static | BindingFlags.DeclaredOnly);
            if (fields.Length > 0)
            {
                foreach (FieldInfo info in fields)
                {
                    Type fieldType = info.FieldType;
                    if (fieldType == typeof(EventOpcode))
                    {
                        builder.AddOpcode(info.Name, (int)info.GetRawConstantValue());
                    }
                    else if (fieldType == typeof(EventTask))
                    {
                        builder.AddTask(info.Name, (int)info.GetRawConstantValue());
                    }
                    else if (fieldType == typeof(EventKeywords))
                    {
                        builder.AddKeyword(info.Name, (ulong)((long)info.GetRawConstantValue()));
                    }
                    else if (fieldType == typeof(EventChannel))
                    {
                        builder.AddChannel(info.Name, (int)info.GetRawConstantValue());
                    }
                }
            }
            for (int i = 0; i < methods.Length; i++)
            {
                MethodInfo      element        = methods[i];
                ParameterInfo[] parameters     = element.GetParameters();
                EventAttribute  eventAttribute = (EventAttribute)Attribute.GetCustomAttribute(element, typeof(EventAttribute), false);
                if (element.ReturnType != typeof(void))
                {
                    if ((eventAttribute != null) && this.DoDebugChecks())
                    {
                        throw new ArgumentException("Event attribute placed on method " + element.Name + " which does not return 'void'");
                    }
                }
                else
                {
                    if (!element.IsVirtual && !element.IsStatic)
                    {
                        if (eventAttribute == null)
                        {
                            if (Attribute.GetCustomAttribute(element, typeof(NonEventAttribute), false) != null)
                            {
                                goto Label_0297;
                            }
                            attribute.EventId = num;
                            attribute.Opcode  = EventOpcode.Info;
                            attribute.Task    = EventTask.None;
                            eventAttribute    = attribute;
                        }
                        else if (eventAttribute.EventId <= 0)
                        {
                            throw new ArgumentException("Event IDs <= 0 are illegal.");
                        }
                        num++;
                        if ((eventAttribute.Opcode == EventOpcode.Info) && (eventAttribute.Task == EventTask.None))
                        {
                            eventAttribute.Opcode = (EventOpcode)(10 + eventAttribute.EventId);
                        }
                        builder.StartEvent(element.Name, eventAttribute);
                        for (int j = 0; j < parameters.Length; j++)
                        {
                            builder.AddEventParameter(parameters[j].ParameterType, parameters[j].Name);
                        }
                        builder.EndEvent();
                        if (this.DoDebugChecks())
                        {
                            this.DebugCheckEvent(element, eventAttribute);
                        }
                        this.AddEventDescriptor(eventAttribute);
                    }
                    Label_0297 :;
                }
            }
            this.TrimEventDescriptors();
            this.m_eventsByName = null;
            return(builder.CreateManifest());
        }
 private byte[] CreateManifestAndDescriptors(string providerDllName)
 {
     Type type = base.GetType();
     MethodInfo[] methods = type.GetMethods(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly);
     EventAttribute attribute = new EventAttribute(0);
     int num = 1;
     this.m_eventData = new EventData[methods.Length];
     ManifestBuilder builder = new ManifestBuilder(this.Name, this.Guid, providerDllName);
     FieldInfo[] fields = type.GetFields(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static | BindingFlags.DeclaredOnly);
     if (fields.Length > 0)
     {
         foreach (FieldInfo info in fields)
         {
             Type fieldType = info.FieldType;
             if (fieldType == typeof(EventOpcode))
             {
                 builder.AddOpcode(info.Name, (int) info.GetRawConstantValue());
             }
             else if (fieldType == typeof(EventTask))
             {
                 builder.AddTask(info.Name, (int) info.GetRawConstantValue());
             }
             else if (fieldType == typeof(EventKeywords))
             {
                 builder.AddKeyword(info.Name, (ulong) ((long) info.GetRawConstantValue()));
             }
             else if (fieldType == typeof(EventChannel))
             {
                 builder.AddChannel(info.Name, (int) info.GetRawConstantValue());
             }
         }
     }
     for (int i = 0; i < methods.Length; i++)
     {
         MethodInfo element = methods[i];
         ParameterInfo[] parameters = element.GetParameters();
         EventAttribute eventAttribute = (EventAttribute) Attribute.GetCustomAttribute(element, typeof(EventAttribute), false);
         if (element.ReturnType != typeof(void))
         {
             if ((eventAttribute != null) && this.DoDebugChecks())
             {
                 throw new ArgumentException("Event attribute placed on method " + element.Name + " which does not return 'void'");
             }
         }
         else
         {
             if (!element.IsVirtual && !element.IsStatic)
             {
                 if (eventAttribute == null)
                 {
                     if (Attribute.GetCustomAttribute(element, typeof(NonEventAttribute), false) != null)
                     {
                         goto Label_0297;
                     }
                     attribute.EventId = num;
                     attribute.Opcode = EventOpcode.Info;
                     attribute.Task = EventTask.None;
                     eventAttribute = attribute;
                 }
                 else if (eventAttribute.EventId <= 0)
                 {
                     throw new ArgumentException("Event IDs <= 0 are illegal.");
                 }
                 num++;
                 if ((eventAttribute.Opcode == EventOpcode.Info) && (eventAttribute.Task == EventTask.None))
                 {
                     eventAttribute.Opcode = (EventOpcode) (10 + eventAttribute.EventId);
                 }
                 builder.StartEvent(element.Name, eventAttribute);
                 for (int j = 0; j < parameters.Length; j++)
                 {
                     builder.AddEventParameter(parameters[j].ParameterType, parameters[j].Name);
                 }
                 builder.EndEvent();
                 if (this.DoDebugChecks())
                 {
                     this.DebugCheckEvent(element, eventAttribute);
                 }
                 this.AddEventDescriptor(eventAttribute);
             }
         Label_0297:;
         }
     }
     this.TrimEventDescriptors();
     this.m_eventsByName = null;
     return builder.CreateManifest();
 }