zoukankan      html  css  js  c++  java
  • 工厂示例

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Configuration;
    using System.Reflection;
    
    namespace Common.DALFactory
    {
        /// <summary>
        /// 数据层对象实例创建
        /// </summary>
        public partial class DbFactory
        {
            /// <summary>
            /// 做缓存
            /// </summary>
            private static Dictionary<string, object> dic = new Dictionary<string, object>();
    
            #region 程序集配置 -static readonly string DALAssembly
            /// <summary>
            /// 程序集配置
            /// </summary>
            private static readonly string DALAssembly = ConfigurationManager.AppSettings["dalAssembly"]; 
            #endregion
    
            #region 命名空间配置 -static readonly string DALNameSpace
            /// <summary>
            /// 命名空间配置
            /// </summary>
            private static readonly string DALNameSpace = ConfigurationManager.AppSettings["dalNameSpace"]; 
            #endregion
    
            #region 创建对象实例 -static object CreateInstance(string fullName, string assemblyName)
            /// <summary>
            /// 创建对象实例
            /// </summary>
            /// <param name="fullName">全名称 命名空间.类名</param>
            /// <param name="assemblyName">程序集名称</param>
            /// <returns></returns>
            private static object CreateInstance(string fullName, string assemblyName)
            {
                string key = string.Format("{0}+{1}", assemblyName, fullName);
                if (!dic.ContainsKey(key))
                {
                    Assembly assembly = Assembly.Load(assemblyName);    // 加载程序集
                    object obj = assembly.CreateInstance(fullName);
                    dic.Add(key, obj);
                }
                return dic[key];            
            } 
            #endregion
        }
    }
  • 相关阅读:
    表单元素的required,autocomplete,list用法
    通用triggerEvent方法
    通用addEventListener方法
    关于动态加载js
    Node路由简单的处理
    As3截图转换为ByteArray传送给后台node的一种方法
    JS中的“==”符号及布尔值转换规则
    解释JS变量作用域的范例
    .NET异步委托
    正则表达式入门
  • 原文地址:https://www.cnblogs.com/Tpf386/p/10001656.html
Copyright © 2011-2022 走看看