本文整理汇总了C#中IReflect.GetMethod方法的典型用法代码示例。如果您正苦于以下问题:C# IReflect.GetMethod方法的具体用法?C# IReflect.GetMethod怎么用?C# IReflect.GetMethod使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IReflect
的用法示例。
在下文中一共展示了IReflect.GetMethod方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Bind
static Func<string, object> Bind(IReflect factory)
{
var method = factory.GetMethod("GetGrain",
BindingFlags.Public | BindingFlags.Static, null,
new[]{typeof(long), typeof(string)}, null);
var argument = Expression.Parameter(typeof(string), "ext");
var call = Expression.Call(method, new Expression[]{Expression.Constant(0L), argument});
var lambda = Expression.Lambda<Func<string, object>>(call, argument);
return lambda.Compile();
}
示例2: GetAndWrapMember
private static MemberInfo[] GetAndWrapMember(IReflect reflect, Object namedItem, String name, BindingFlags bindingAttr){
PropertyInfo property = reflect.GetProperty(name, bindingAttr);
if (property != null){
MethodInfo getMethod = JSProperty.GetGetMethod(property, false);
MethodInfo setMethod = JSProperty.GetSetMethod(property, false);
if ((getMethod != null && !getMethod.IsStatic) || (setMethod != null && !setMethod.IsStatic)){
MethodInfo method = reflect.GetMethod(name, bindingAttr);
if (method != null && !method.IsStatic){
MemberInfo[] propMethods = new MemberInfo[1];
propMethods[0] = new JSWrappedPropertyAndMethod(property, method, namedItem);
return propMethods;
}
}
}
MemberInfo[] members = reflect.GetMember(name, bindingAttr);
if (members != null && members.Length > 0)
return ScriptObject.WrapMembers(members, namedItem);
return null;
}
示例3: GetAndWrapMember
private static MemberInfo[] GetAndWrapMember(IReflect reflect, object namedItem, string name, BindingFlags bindingAttr)
{
PropertyInfo property = reflect.GetProperty(name, bindingAttr);
if (property != null)
{
MethodInfo getMethod = JSProperty.GetGetMethod(property, false);
MethodInfo setMethod = JSProperty.GetSetMethod(property, false);
if (((getMethod != null) && !getMethod.IsStatic) || ((setMethod != null) && !setMethod.IsStatic))
{
MethodInfo method = reflect.GetMethod(name, bindingAttr);
if ((method != null) && !method.IsStatic)
{
return new MemberInfo[] { new JSWrappedPropertyAndMethod(property, method, namedItem) };
}
}
}
MemberInfo[] member = reflect.GetMember(name, bindingAttr);
if ((member != null) && (member.Length > 0))
{
return ScriptObject.WrapMembers(member, namedItem);
}
return null;
}
示例4: GetMethodExtended
private static object GetMethodExtended(
IReflect type,
string name,
bool staticMethod,
int parameterCount)
{
var haveMethodName = false;
BindingFlags flags = (staticMethod ? BindingFlags.Static :
BindingFlags.Instance) | BindingFlags.Public |
BindingFlags.NonPublic | BindingFlags.InvokeMethod;
foreach (var method in type.GetMethods(flags)) {
if (method.Name.Equals(name)) {
haveMethodName = true;
if (method.GetParameters().Length == parameterCount) {
return method;
}
}
}
return haveMethodName ? type.GetMethod(name, flags) : null;
}
示例5: RunMethod
/// <summary>
/// Runs the method.
/// </summary>
/// <param name="type">The type.</param>
/// <param name="strMethod">The STR method.</param>
/// <param name="objInstance">The obj instance.</param>
/// <param name="objParams">The obj params.</param>
/// <param name="eFlags">The e flags.</param>
/// <returns></returns>
private static object RunMethod(IReflect type, string strMethod, object objInstance, object [] objParams, BindingFlags eFlags)
{
MethodInfo method;
try
{
if ((eFlags == InstanceBindingFlags) && (objInstance == null))
{
throw new ArgumentException("The reflection non-static object argument was invalid");
}
if ((eFlags == StaticBindingFlags) && (objInstance != null))
{
throw new ArgumentException("The reflection static object argument was invalid");
}
if ((objInstance != null) && (objInstance.GetType() != (Type)type) && (objInstance.GetType().BaseType != (Type)type))
{
throw new ArgumentException("The object instance was of type '" + objInstance.GetType() + "' for type '" + type + "'.");
}
if (string.IsNullOrEmpty(strMethod))
{
throw new ArgumentException("The reflection method argument was invalid");
}
method = type.GetMethod(strMethod, eFlags);
if (method == null)
{
throw new ArgumentException("There is no method '" + strMethod + "' for type '" + type + "'.");
}
var objRet = method.Invoke(objInstance, objParams);
return objRet;
}
catch (Exception exception)
{
Console.WriteLine(exception.Message);
throw;
}
}
示例6: GetRegisteredEvents
private static IEnumerable<Type> GetRegisteredEvents(IReflect proxyType, object proxy)
{
return (IEnumerable<Type>)proxyType
.GetMethod("RegisteredEvents", BindingFlags.Instance | BindingFlags.NonPublic)
.Invoke(proxy, new object[] { });
}