zoukankan      html  css  js  c++  java
  • System.Reflection反序

    做项目需要用到一些反序

            /// <summary>
            /// 反序对象
            /// </summary>
            /// <param name="obj"></param>
            /// <returns></returns>
            public string ForeachParm(object obj)
            {
                string str = "";
                foreach (System.Reflection.PropertyInfo item in obj.GetType().GetProperties())
                {
                    
                    str += item.Name + ","+item.GetValue(obj,null)+";";
                }
    
                return str;
            }

    反序接口实现类

     /// <summary>
            /// 反序接口实现类
            /// </summary>
            /// <returns></returns>
            public static IFinanceManage CreateSysManage()
            {
                //dll物理路径
                string AssemblyPath = "U_HomeV3.1Server"; 
                //带命名空间的类全路径
                string classNamespace = "U_HomeV3_1Server.BLL.FinanceManage"; 
                object objType = CreateObject(AssemblyPath, classNamespace);
                
                return (IFinanceManage)objType;        
            }
    
            private static object CreateObject(string AssemblyPath, string classNamespace)
            {
                object objType = DataCache.GetCache(classNamespace);
                if (objType == null)
                {
                    try
                    {
                        objType = Assembly.Load(AssemblyPath).CreateInstance(classNamespace);
                        
                    }
                    catch(Exception ex)
                    {
                        //string str=ex.Message;// 记录错误日志
                        return null;
                    }
                }
                return objType;
            }
        }
    
        /// <summary>
        /// 缓存操作类
        /// </summary>
        public class DataCache
        {
            /// <summary>
            /// 获取当前应用程序指定CacheKey的Cache值
            /// </summary>
            /// <param name="CacheKey"></param>
            /// <returns></returns>
            public static object GetCache(string CacheKey)
            {
                System.Web.Caching.Cache objCache = HttpRuntime.Cache;
                return objCache[CacheKey];
            }
    
            /// <summary>
            /// 设置当前应用程序指定CacheKey的Cache值
            /// </summary>
            /// <param name="CacheKey"></param>
            /// <param name="objObject"></param>
            public static void SetCache(string CacheKey, object objObject)
            {
                System.Web.Caching.Cache objCache = HttpRuntime.Cache;
                objCache.Insert(CacheKey, objObject);
            }
        }
  • 相关阅读:
    Scrapy框架
    描述符类
    完整的blog设计过程
    钉钉机器人设置步骤
    homework登录和支付mock两个接口
    jsonpath的用法和nnlog的使用
    mp4格式文件转码后处理(qt-faststart).md
    html5视音频标签参考.md
    ffmpeg文档43-开发者
    ffmpeg文档42-参考/看
  • 原文地址:https://www.cnblogs.com/PLifeCopyDown/p/3016908.html
Copyright © 2011-2022 走看看