反射相关

通过反射动态调用dll中的方法代码
public class CMSMemCache
{
        static Assembly _CMSMemCacheAssembly = null;
        static Type _CMSMemCacheType = null;

        static CMSMemCache()
        {
            _CMSMemCacheAssembly = Assembly.Load(new AssemblyName("CeairPortal.B2E.Components"));//加载程序集
            _CMSMemCacheType = _CMSMemCacheAssembly.GetType("CeairPortal.B2E.Components.MemCached.MemHandler");
        }

        public static void SetForFunCode(string memCode, object obj, params string[] funCode)
        {
            string[] c = funCode;
            MethodInfo method = _CMSMemCacheType.GetMethod("SetForFunCode");
            method.Invoke(_CMSMemCacheType, new object[] { memCode, obj, c });
        }
}

System.Reflection命名空间
(1)   AppDomain:应用程序域,可以将其理解为一组程序集的逻辑容器
(2)   Assembly:程序集类
(3)   Module:模块类
(4)   Type:使用反射得到类型信息的最核心的类
他们之间是一种从属关系,也就是说,一个AppDomain可以包含N个Assembly,一个Assembly可以包含N个Module,而一个Module可以包含N个Type
posted @ 2012-05-14 10:02  魔力鸟  阅读(164)  评论(0编辑  收藏  举报