FindMethod() 보호된 정적인 메소드

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
리턴 System.Reflection.MethodInfo
 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;
     }
 }
예제 #2
0
 /// <summary>Finds the given method through reflection, searching only for public methods.</summary>
 /// <returns>A <see cref="T:System.Reflection.MethodInfo" /> that represents the method, or null if the method is not found.</returns>
 /// <param name="componentClass">The component that contains the method. </param>
 /// <param name="name">The name of the method to find. </param>
 /// <param name="args">An array of parameters for the method, used to choose between overloaded methods. </param>
 /// <param name="returnType">The type to return for the method. </param>
 protected static MethodInfo FindMethod(Type componentClass, string name, Type[] args, Type returnType)
 {
     return(MemberDescriptor.FindMethod(componentClass, name, args, returnType, true));
 }