zoukankan      html  css  js  c++  java
  • DNN学习笔记代码学习:Reflection 荣

    using System;

    namespace WebApplication1
    {
     /// <summary>
     /// 映射,根据传入的参数,生成相应的对象类型及对象,
     /// 并且把取得的类型、键值对放入到缓存中。
     /// </summary>
     public class Reflection
     {
      public Reflection()
      {
       //
       // TODO: 在此处添加构造函数逻辑
       //
      }

      /// <summary>
      /// 取得相关对象
      /// </summary>
      /// <param name="objectProviderType">配置文件名称</param>
      /// <returns>相关对象</returns>
      public static object CreateObject(string objectProviderType)
      {
       return CreateObject(objectProviderType, "", "");
      }

      /// <summary>
      /// 创建相应对象
      /// </summary>
      /// <param name="objectProviderType">配置文件名称</param>
      /// <param name="objectNamespace">创建对象的命名空间</param>
      /// <param name="objectAssemblyName"></param>
      /// <returns>相应对象</returns>
      public static object CreateObject(string objectProviderType,
       string objectNamespace,
       string objectAssemblyName)
      {
       string TypeName = "";
       string CacheKey = "";

       // 根据配置信息取得ProviderConfiguration对象[defaultProvider/(objectProviderType)]
       ProviderConfiguration objProviderConfiguration = ProviderConfiguration.GetProviderConfiguration(objectProviderType);

       if (objectNamespace != "" && objectAssemblyName != "")
       {
        // 取得缓存中的类型名称  中间用分号是什么意思?以前没有见过?
        // objectNamespace是命名空间吗?DefaultProvider是类型吗?
        // objectAssemblyName是干什么的?
        TypeName = objectNamespace + "." + objProviderConfiguration.DefaultProvider + ", " + objectAssemblyName + "." + objProviderConfiguration.DefaultProvider;

        // 取得缓存的键值
        CacheKey = objectNamespace + "." + objectProviderType + "provider";
       }
       else
       {
        // 读取哈希表中的值
        TypeName = ((Provider)objProviderConfiguration.Providers[objProviderConfiguration.DefaultProvider]).Type;

        CacheKey = objectProviderType + "provider";
       }

       // 取得TypeName类型的对象.
       return CreateObject(TypeName, CacheKey);
      }

      /// <summary>
      /// 取得TypeName类型的对象。
      /// </summary>
      /// <param name="TypeName">对象类型名称</param>
      /// <param name="CacheKey">该类型缓存键值</param>
      /// <returns></returns>
      public static object CreateObject(string TypeName, string CacheKey)
      {
    //   object objectObject;
       if (CacheKey == "")
       {
        CacheKey = TypeName;
       }

       #region 根据Type取得对象类型

       // 从缓存中取得对象类型
       Type objType = (Type)DataCache.GetCache(CacheKey);

       // 如果缓存中不存在该对象类型,重新取得对象类型,并放入缓存
       if (objType == null)
       {
        try
        {
         // 向缓存中添加数据
         objType = Type.GetType(TypeName, true);
         DataCache.SetCache(CacheKey, objType);
        }
        catch(Exception exc)
        {
         LogException(exc);
        }
       }
       #endregion

       // 生成对象
       return Activator.CreateInstance(objType);
      }

      public static void LogException(Exception exc)
      {
       ExceptionLogController objExceptionLog = new ExceptionLogController();
       objExceptionLog.AddLog(exc, ExceptionLogController.ExceptionLogType.GENERAL_EXCEPTION);
      }
     }
    }

  • 相关阅读:
    latin1
    分享:Django博客开发笔记之博客摘要
    分享:RethinkDB 1.3 发布,分布式 JSON 数据库
    分享:RethinkDB 1.3 发布,分布式 JSON 数据库
    分享:RethinkDB 1.3 发布,分布式 JSON 数据库
    网络神采 最专业的网络信息采集系统! 采集软件_网站采集器_采集程序_新闻采集系统_网络信息采集_文章采集
    分享:RethinkDB 1.3 发布,分布式 JSON 数据库
    分享:RethinkDB 1.3 发布,分布式 JSON 数据库
    'module' object has no attribute 'setdefaultencoding'_阿King's blog_百度空间
    QTreeWidget Class Reference
  • 原文地址:https://www.cnblogs.com/admin11/p/193287.html
Copyright © 2011-2022 走看看