System.ComponentModel.MemberDescriptor.FindMethod C# (CSharp) Method

FindMethod() protected static method

Finds the given method through reflection. This method only looks for public methods.

protected static FindMethod ( Type componentClass, string name, Type args, Type returnType ) : MethodInfo
componentClass Type
name string
args Type
returnType Type
return System.Reflection.MethodInfo
        protected static MethodInfo FindMethod(Type componentClass, string name, Type[] args, Type returnType)
        {
            return FindMethod(componentClass, name, args, returnType, true);
        }

Same methods

MemberDescriptor::FindMethod ( Type componentClass, string name, Type args, Type returnType, bool publicOnly ) : MethodInfo

Usage Example

 private void FillMethods()
 {
     if (!this.filledMethods)
     {
         if (this.realEvent == null)
         {
             this.realEvent = this.componentClass.GetEvent(this.Name);
             if (this.realEvent != null)
             {
                 this.FillMethods();
                 return;
             }
             Type[] args = new Type[] { this.type };
             this.addMethod    = MemberDescriptor.FindMethod(this.componentClass, "AddOn" + this.Name, args, typeof(void));
             this.removeMethod = MemberDescriptor.FindMethod(this.componentClass, "RemoveOn" + this.Name, args, typeof(void));
             if ((this.addMethod == null) || (this.removeMethod == null))
             {
                 throw new ArgumentException(SR.GetString("ErrorMissingEventAccessors", new object[] { this.Name }));
             }
         }
         else
         {
             this.addMethod    = this.realEvent.GetAddMethod();
             this.removeMethod = this.realEvent.GetRemoveMethod();
             EventInfo info = null;
             if ((this.addMethod == null) || (this.removeMethod == null))
             {
                 Type baseType = this.componentClass.BaseType;
                 while ((baseType != null) && (baseType != typeof(object)))
                 {
                     BindingFlags bindingAttr = BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance;
                     EventInfo    info2       = baseType.GetEvent(this.realEvent.Name, bindingAttr);
                     if (info2.GetAddMethod() != null)
                     {
                         info = info2;
                         break;
                     }
                 }
             }
             if (info != null)
             {
                 this.addMethod    = info.GetAddMethod();
                 this.removeMethod = info.GetRemoveMethod();
                 this.type         = info.EventHandlerType;
             }
             else
             {
                 this.type = this.realEvent.EventHandlerType;
             }
         }
         this.filledMethods = true;
     }
 }
All Usage Examples Of System.ComponentModel.MemberDescriptor::FindMethod