using System;
using System.Collections.Generic;
using System.Text;
using System.Reflection;
namespace SPaDevToolkit.StsAdm.Commands.Utilities
{
internal static class Reflection
{
public static object InvokeMember(object src, string strName, BindingFlags type, object[] args)
{
bool bStatic = (src is Type);
Type t = bStatic ? (Type)src : src.GetType();
BindingFlags bindingFlags = BindingFlags.NonPublic | BindingFlags.Public |
BindingFlags.DeclaredOnly |
(bStatic ? BindingFlags.Static : BindingFlags.Instance) |
type;
object target = (bStatic ? null : src);
return (t.InvokeMember(strName, bindingFlags, null, target, args));
}
public static object GetProperty(object src, string strName)
{
return (InvokeMember(src, strName, BindingFlags.GetProperty, null));
}
public static object SetProperty(object src, string strName, object[] args)
{
return (InvokeMember(src, strName, BindingFlags.SetProperty, args));
}
public static object GetField(object src, string strName)
{
return (InvokeMember(src, strName, BindingFlags.GetField, null));
}
public static object SetField(object src, string strName, object[] args)
{
return (InvokeMember(src, strName, BindingFlags.SetField, args));
}
}
}