using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;
namespace Sb2.Extensions
{
public static class ReflectionExtensions
{
///
/// Invokes the method.
///
///
/// The obj.
/// Name of the method.
///
public static T InvokeMethod(this object obj, string methodName)
{
return InvokeMethod(obj, methodName, null);
}
///
/// Invokes the method.
///
///
/// The obj.
/// Name of the method.
/// The args.
///
public static T InvokeMethod(this object obj, string methodName, object[] args)
{
Type type = obj.GetType();
MethodInfo methodInfo = type.GetMethod(methodName);
if (methodInfo != null)
{
return (T)methodInfo.Invoke(obj, args);
}
return default(T);
}
}
}