AssemblySlowXFunctions

2017-07-09 21:32:47  访问(1698) 赞(0) 踩(0)

using System;
using System.Collections.Generic;
using System.Reflection;
using System.Text;

namespace SlowX.Functions.Functions
{
    /// <summary>
    /// Assembly操作常用的方法 - AssemblySlowXFunctions
    /// </summary>
    public class AssemblySlowXFunctions 
    {
        /// <summary>
        /// 通过DLL的完整地址和className,获得Type的值 - GetTypeByDLLName +
        /// </summary>
        /// <param name="dllFullName"></param>
        /// <param name="className"></param>
        /// <returns></returns>
        public static Type GetTypeByDLLName
            (
                string dllFullName, 
                string className
            )
        {
            Assembly ass = Assembly.LoadFrom(dllFullName);

            if (ass == null)
                return null;

            Type theResult = ass.GetType(className, false, true);

            if (theResult == null)
            {
                return null;
            }

            return theResult;
        }

        /// <summary>
        /// 获得类的静态实体 instance - GetStaticFieldInstance +
        /// </summary>
        /// <param name="dllFullName"></param>
        /// <param name="className"></param>
        /// <returns></returns>
        public static object GetStaticFieldInstance
            (
                string dllFullName, 
                string className
            )
        {
            Assembly ass = Assembly.LoadFrom(dllFullName);

            if (ass == null)
                return null;

            Type typeValue = ass.GetType(className, false, true);

            if (typeValue == null)
            {
                return null;
            }

            FieldInfo info = typeValue.GetField("instance", BindingFlags.Static | BindingFlags.Public);

            if (info == null)
            {
                return null;
            }

            return info.GetValue(null);
        }
    }
}


上一条:

下一条:


 

相关评论

评论加载中……
 

发表评论

类型:
内容:
  (Alt+Enter)