예제 #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="GetAccessorFactory"/> class. 本质是初始化内部的委托函数
        /// </summary>
        /// <param name="allowCodeGeneration">if set to <c>true</c> [allow code generation].</param>
        public GetAccessorFactory(bool allowCodeGeneration)
        {
            if (allowCodeGeneration)
            {
                // Detect runtime environment and create the appropriate factory
                if (Environment.Version.Major >= 2)
                {
                    _createPropertyGetAccessor = new CreatePropertyGetAccessor(CreateDynamicPropertyGetAccessor);
                    _createFieldGetAccessor    = new CreateFieldGetAccessor(CreateDynamicFieldGetAccessor);
                }
                else
                {
                    AssemblyName assemblyName = new AssemblyName();
                    assemblyName.Name = "iBATIS.FastGetAccessor" + HashCodeProvider.GetIdentityHashCode(this);

                    // Create a new assembly with one module
                    _assemblyBuilder = AppDomain.CurrentDomain.DefineDynamicAssembly(assemblyName, AssemblyBuilderAccess.Run);
                    _moduleBuilder   = _assemblyBuilder.DefineDynamicModule(assemblyName.Name + ".dll");

                    _createPropertyGetAccessor = new CreatePropertyGetAccessor(CreatePropertyAccessor);
                    _createFieldGetAccessor    = new CreateFieldGetAccessor(CreateFieldAccessor);
                }
            }
            else
            {
                _createPropertyGetAccessor = new CreatePropertyGetAccessor(CreateReflectionPropertyGetAccessor);
                _createFieldGetAccessor    = new CreateFieldGetAccessor(CreateReflectionFieldGetAccessor);
            }
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="GetAccessorFactory"/> class.
        /// </summary>
        /// <param name="allowCodeGeneration">if set to <c>true</c> [allow code generation].</param>
        public GetAccessorFactory(bool allowCodeGeneration)
        {
            if (allowCodeGeneration)
            {
                // Detect runtime environment and create the appropriate factory
                if (Environment.Version.Major >= 2)
                {

                    _createPropertyGetAccessor = new CreatePropertyGetAccessor(CreateDynamicPropertyGetAccessor);
                    _createFieldGetAccessor = new CreateFieldGetAccessor(CreateDynamicFieldGetAccessor);

                }
                else
                {
                    AssemblyName assemblyName = new AssemblyName();
                    assemblyName.Name = "iBATIS.FastGetAccessor" + HashCodeProvider.GetIdentityHashCode(this).ToString();

                    // Create a new assembly with one module
                    _assemblyBuilder = AppDomain.CurrentDomain.DefineDynamicAssembly(assemblyName, AssemblyBuilderAccess.Run);
                    _moduleBuilder = _assemblyBuilder.DefineDynamicModule(assemblyName.Name + ".dll");

                    _createPropertyGetAccessor = new CreatePropertyGetAccessor(CreatePropertyAccessor);
                    _createFieldGetAccessor = new CreateFieldGetAccessor(CreateFieldAccessor);
                }
            }
            else
            {
                _createPropertyGetAccessor = new CreatePropertyGetAccessor(CreateReflectionPropertyGetAccessor);
                _createFieldGetAccessor = new CreateFieldGetAccessor(CreateReflectionFieldGetAccessor);
            }
        }
예제 #3
0
 public GetAccessorFactory(bool allowCodeGeneration)
 {
     if (allowCodeGeneration)
     {
         if (Environment.Version.Major >= 2)
         {
             this._createPropertyGetAccessor = new CreatePropertyGetAccessor(this.CreateDynamicPropertyGetAccessor);
             this._createFieldGetAccessor    = new CreateFieldGetAccessor(this.CreateDynamicFieldGetAccessor);
         }
         else
         {
             AssemblyName name = new AssemblyName {
                 Name = "iBATIS.FastGetAccessor" + HashCodeProvider.GetIdentityHashCode(this).ToString()
             };
             this._assemblyBuilder           = AppDomain.CurrentDomain.DefineDynamicAssembly(name, AssemblyBuilderAccess.Run);
             this._moduleBuilder             = this._assemblyBuilder.DefineDynamicModule(name.Name + ".dll");
             this._createPropertyGetAccessor = new CreatePropertyGetAccessor(this.CreatePropertyAccessor);
             this._createFieldGetAccessor    = new CreateFieldGetAccessor(this.CreateFieldAccessor);
         }
     }
     else
     {
         this._createPropertyGetAccessor = new CreatePropertyGetAccessor(this.CreateReflectionPropertyGetAccessor);
         this._createFieldGetAccessor    = new CreateFieldGetAccessor(this.CreateReflectionFieldGetAccessor);
     }
 }