Ejemplo n.º 1
0
        public IGetAccessor CreateGetAccessor(Type targetType, string name)
        {
            string key = new StringBuilder(targetType.FullName).Append(".").Append(name).ToString();

            if (this._cachedIGetAccessor.Contains(key))
            {
                return((IGetAccessor)this._cachedIGetAccessor[key]);
            }
            IGetAccessor accessor = null;

            lock (this._syncObject)
            {
                if (!this._cachedIGetAccessor.Contains(key))
                {
                    MemberInfo getter = ReflectionInfo.GetInstance(targetType).GetGetter(name);
                    if (getter == null)
                    {
                        throw new ProbeException(string.Format("No property or field named \"{0}\" exists for type {1}.", name, targetType));
                    }
                    if (getter is PropertyInfo)
                    {
                        accessor = this._createPropertyGetAccessor(targetType, name);
                        this._cachedIGetAccessor[key] = accessor;
                        return(accessor);
                    }
                    accessor = this._createFieldGetAccessor(targetType, name);
                    this._cachedIGetAccessor[key] = accessor;
                    return(accessor);
                }
                return((IGetAccessor)this._cachedIGetAccessor[key]);
            }
        }
 public void Initialize(IScope scope, Type parameterClass)
 {
     if (this._directionAttribute.Length > 0)
     {
         this._direction = (ParameterDirection)Enum.Parse(typeof(ParameterDirection), this._directionAttribute, true);
     }
     if ((!typeof(IDictionary).IsAssignableFrom(parameterClass) && (parameterClass != null)) && !scope.DataExchangeFactory.TypeHandlerFactory.IsSimpleType(parameterClass))
     {
         if (!this._isComplexMemberName)
         {
             this._getAccessor = scope.DataExchangeFactory.AccessorFactory.GetAccessorFactory.CreateGetAccessor(parameterClass, this._propertyName);
         }
         else
         {
             string name                = this._propertyName.Substring(this._propertyName.LastIndexOf('.') + 1);
             string memberName          = this._propertyName.Substring(0, this._propertyName.LastIndexOf('.'));
             Type   memberTypeForGetter = ObjectProbe.GetMemberTypeForGetter(parameterClass, memberName);
             this._getAccessor = scope.DataExchangeFactory.AccessorFactory.GetAccessorFactory.CreateGetAccessor(memberTypeForGetter, name);
         }
     }
     scope.ErrorContext.MoreInfo = "Check the parameter mapping typeHandler attribute '" + this.CallBackName + "' (must be a ITypeHandlerCallback implementation).";
     if (this.CallBackName.Length > 0)
     {
         try
         {
             ITypeHandlerCallback callback = (ITypeHandlerCallback)Activator.CreateInstance(scope.DataExchangeFactory.TypeHandlerFactory.GetType(this.CallBackName));
             this._typeHandler = new CustomTypeHandler(callback);
             return;
         }
         catch (Exception exception)
         {
             throw new ConfigurationException("Error occurred during custom type handler configuration.  Cause: " + exception.Message, exception);
         }
     }
     if (this.CLRType.Length == 0)
     {
         if ((this._getAccessor != null) && scope.DataExchangeFactory.TypeHandlerFactory.IsSimpleType(this._getAccessor.MemberType))
         {
             this._typeHandler = scope.DataExchangeFactory.TypeHandlerFactory.GetTypeHandler(this._getAccessor.MemberType, this._dbType);
         }
         else
         {
             this._typeHandler = scope.DataExchangeFactory.TypeHandlerFactory.GetUnkownTypeHandler();
         }
     }
     else
     {
         Type type = TypeUtils.ResolveType(this.CLRType);
         if (scope.DataExchangeFactory.TypeHandlerFactory.IsSimpleType(type))
         {
             this._typeHandler = scope.DataExchangeFactory.TypeHandlerFactory.GetTypeHandler(type, this._dbType);
         }
         else
         {
             type = ObjectProbe.GetMemberTypeForGetter(type, this.PropertyName);
             this._typeHandler = scope.DataExchangeFactory.TypeHandlerFactory.GetTypeHandler(type, this._dbType);
         }
     }
 }
Ejemplo n.º 3
0
        public void TestGetPropertyOverrideByNew()
        {
            IGetAccessor accessorGet = factoryGet.CreateGetAccessor(typeof(PropertySon), "Float");

            PropertySon son = new PropertySon();

            son.Float = -99;

            Assert.AreEqual(-99 * 2, accessorGet.Get(son));
        }
Ejemplo n.º 4
0
        public void TestMultipleMemberAccessorFactory()
        {
            Property     prop      = new Property();
            IGetAccessor accessor1 = factoryGet.CreateGetAccessor(typeof(Property), "Int");

            IGetAccessorFactory factory2  = new GetAccessorFactory(true);
            IGetAccessor        accessor2 = factory2.CreateGetAccessor(typeof(Property), "Int");

            Assert.AreEqual(int.MinValue, accessor1.Get(prop));
            Assert.AreEqual(int.MinValue, accessor2.Get(prop));
        }
Ejemplo n.º 5
0
        public void TestVirtualIMemberAccessor3()
        {
            IGetAccessor accessorGet = factoryGet.CreateGetAccessor(typeof(PropertySon), "DateTime");
            ISetAccessor accessorSet = factorySet.CreateSetAccessor(typeof(PropertySon), "DateTime");

            PropertySon son  = new PropertySon();
            DateTime    date = (DateTime)accessorGet.Get(son);

            Assert.AreEqual(new DateTime(2000, 1, 1), date);
            accessorSet.Set(son, DateTime.Now);
        }
Ejemplo n.º 6
0
        public void TestVirtualIMemberAccessor2()
        {
            IGetAccessor accessorGet = factoryGet.CreateGetAccessor(typeof(PropertySon), "Int");
            ISetAccessor accessorSet = factorySet.CreateSetAccessor(typeof(PropertySon), "Int");

            PropertySon son = new PropertySon();
            Int32       i   = (Int32)accessorGet.Get(son);

            Assert.IsTrue(i == -88);
            accessorSet.Set(son, 9);
        }
Ejemplo n.º 7
0
        public void TestVirtualIMemberAccessor1()
        {
            IGetAccessor accessorGet = factoryGet.CreateGetAccessor(typeof(PropertySon), "Account");
            ISetAccessor accessorSet = factorySet.CreateSetAccessor(typeof(PropertySon), "Account");

            PropertySon son     = new PropertySon();
            Account     account = (Account)accessorGet.Get(son);

            Assert.IsTrue(account.Days == Days.Wed);
            accessorSet.Set(son, new Account());
        }
Ejemplo n.º 8
0
        public void TestMemberAccessorFactory()
        {
            IGetAccessor accessor11 = factoryGet.CreateGetAccessor(typeof(Property), "Int");
            IGetAccessor accessor12 = factoryGet.CreateGetAccessor(typeof(Property), "Int");

            Assert.AreEqual(HashCodeProvider.GetIdentityHashCode(accessor11), HashCodeProvider.GetIdentityHashCode(accessor12));

            ISetAccessor accessor21 = factorySet.CreateSetAccessor(typeof(Property), "Int");
            ISetAccessor accessor22 = factorySet.CreateSetAccessor(typeof(Property), "Int");

            Assert.AreEqual(HashCodeProvider.GetIdentityHashCode(accessor21), HashCodeProvider.GetIdentityHashCode(accessor22));
        }
Ejemplo n.º 9
0
        //[ExpectedException(typeof(InvalidOperationException), ExpectedMessage = "Test virtual")]
        public void TestVirtualIMemberAccessor2()
        {
            IGetAccessor accessorGet = factoryGet.CreateGetAccessor(typeof(PropertySon), "Int");
            ISetAccessor accessorSet = factorySet.CreateSetAccessor(typeof(PropertySon), "Int");

            PropertySon son = new PropertySon();
            Int32       i   = (Int32)accessorGet.Get(son);

            Assert.IsTrue(i == -88);

            Assert.That(() => accessorSet.Set(son, 9), Throws.TypeOf <InvalidOperationException>().With.Message.EqualTo("Test virtual"));
        }
Ejemplo n.º 10
0
        //[ExpectedException(typeof(InvalidOperationException), ExpectedMessage = "Test virtual")]
        public void TestVirtualIMemberAccessor3()
        {
            IGetAccessor accessorGet = factoryGet.CreateGetAccessor(typeof(PropertySon), "DateTime");
            ISetAccessor accessorSet = factorySet.CreateSetAccessor(typeof(PropertySon), "DateTime");

            PropertySon son  = new PropertySon();
            DateTime    date = (DateTime)accessorGet.Get(son);

            Assert.AreEqual(new DateTime(2000, 1, 1), date);

            Assert.That(() => accessorSet.Set(son, DateTime.Now), Throws.TypeOf <InvalidOperationException>().With.Message.EqualTo("Test virtual"));
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Gets the member's value on the specified object.
        /// </summary>
        /// <param name="obj">The obj.</param>
        /// <param name="memberName">Name of the member.</param>
        /// <param name="accessorFactory">The accessor factory.</param>
        /// <returns>The member's value</returns>
        public static object GetMember(object obj, string memberName,
                                       AccessorFactory accessorFactory)
        {
            try
            {
                object value = null;

                if (memberName.IndexOf("[") > -1)
                {
                    value = GetArrayMember(obj, memberName, accessorFactory);
                }
                else
                {
                    if (obj is IDictionary)
                    {
                        value = ((IDictionary)obj)[memberName];
                    }
                    else if (obj is IDictionary <string, object> )
                    {
                        value = ((IDictionary <string, object>)obj)[memberName];
                    }
                    else
                    {
                        Type targetType = obj.GetType();
                        IGetAccessorFactory getAccessorFactory = accessorFactory.GetAccessorFactory;
                        IGetAccessor        getAccessor        = getAccessorFactory.CreateGetAccessor(targetType, memberName);

                        if (getAccessor == null)
                        {
                            throw new ProbeException("No Get method for member " + memberName + " on instance of " + obj.GetType().Name);
                        }
                        try
                        {
                            value = getAccessor.Get(obj);
                        }
                        catch (Exception ae)
                        {
                            throw new ProbeException(ae);
                        }
                    }
                }
                return(value);
            }
            catch (ProbeException)
            {
                throw;
            }
            catch (Exception e)
            {
                throw new ProbeException("Could not Set property '" + memberName + "' for " + obj.GetType().Name + ".  Cause: " + e.Message, e);
            }
        }
Ejemplo n.º 12
0
        //[ExpectedException(typeof(InvalidOperationException), ExpectedMessage = "Test virtual")]
        public void TestVirtualIMemberAccessor1()
        {
            IGetAccessor accessorGet = factoryGet.CreateGetAccessor(typeof(PropertySon), "Account");
            ISetAccessor accessorSet = factorySet.CreateSetAccessor(typeof(PropertySon), "Account");

            PropertySon son     = new PropertySon();
            Account     account = (Account)accessorGet.Get(son);

            Assert.IsTrue(account.Days == Days.Wed);
            ;

            Assert.That(() => accessorSet.Set(son, new Account()), Throws.TypeOf <InvalidOperationException>().With.Message.EqualTo("Test virtual"));
        }
Ejemplo n.º 13
0
        public void TestPrivateGetterOnGenericProperty2()
        {
            IGetAccessor accessorGet = factoryGet.CreateGetAccessor(typeof(SpecialReference <Account>), "_value");

            SpecialReference <Account> referenceAccount = new SpecialReference <Account>();
            Account account = new Account(5);

            referenceAccount.Value = account;

            Account acc = accessorGet.Get(referenceAccount) as Account;

            Assert.AreEqual(referenceAccount.Value, acc);
            Assert.AreEqual(referenceAccount.Value.Id, acc.Id);
        }
Ejemplo n.º 14
0
        /// <summary>
        /// 复制
        /// </summary>
        /// <param name="obj">源对象</param>
        /// <param name="value">目的对象</param>
        public void Copy(object obj, object value)
        {
            lock (this)
            {
                if (this.propertyDic == null)
                {
                    this.propertyDic = new Dictionary <string, PropertyInfo>();
                    if (obj != null)
                    {
                        Type t = obj.GetType();
                        foreach (PropertyInfo propertyInfo in t.GetProperties())
                        {
                            if (propertyInfo.CanWrite && propertyInfo.CanRead)
                            {
                                this.propertyDic.Add(propertyInfo.Name, propertyInfo);
                            }
                        }
                    }
                }
            }
            IGetAccessor valueGetAccessor = null;

            if (value is IGetAccessor)
            {
                valueGetAccessor = value as IGetAccessor;
            }
            ISetAccessor objSetAccessor = null;

            if (obj is ISetAccessor)
            {
                objSetAccessor = obj as ISetAccessor;
            }

            foreach (KeyValuePair <string, PropertyInfo> kp in this.propertyDic)
            {
                if (objSetAccessor != null && valueGetAccessor != null)
                {
                    objSetAccessor.SetValue(kp.Key, valueGetAccessor.GetValue(kp.Key));
                }
                else if (objSetAccessor != null && valueGetAccessor == null)
                {
                    objSetAccessor.SetValue(kp.Key, kp.Value.GetValue(value, null));
                }
                else if (objSetAccessor == null && valueGetAccessor == null)
                {
                    kp.Value.SetValue(obj, kp.Value.GetValue(value, null), null);
                }
            }
        }
Ejemplo n.º 15
0
        public void TestPrivateGetterOnGenericProperty()
        {
            IGetAccessor accessorGet = factoryGet.CreateGetAccessor(typeof(PropertySon), "_referenceAccount");

            PropertySon son = new PropertySon();

            son.ReferenceAccount = new SpecialReference <Account>();
            Account account = new Account(5);

            son.ReferenceAccount.Value = account;

            SpecialReference <Account> acc = accessorGet.Get(son) as SpecialReference <Account>;

            Assert.AreEqual(account, acc.Value);
            Assert.AreEqual(account.Id, acc.Value.Id);
        }
Ejemplo n.º 16
0
        public IGetAccessor CreateGetAccessor(Type targetType, string name)
        {
            string key = new StringBuilder(targetType.FullName).Append(".").Append(name).ToString();

            if (_cachedIGetAccessor.Contains(key))
            {
                return((IGetAccessor)_cachedIGetAccessor[key]);
            }
            else
            {
                IGetAccessor getAccessor = null;
                lock (_syncObject)
                {
                    if (!_cachedIGetAccessor.Contains(key))
                    {
                        // Property
                        ReflectionInfo reflectionCache = ReflectionInfo.GetInstance(targetType);
                        MemberInfo     memberInfo      = reflectionCache.GetGetter(name);

                        if (memberInfo != null)
                        {
                            if (memberInfo is PropertyInfo)
                            {
                                getAccessor = _createPropertyGetAccessor(targetType, name);
                                _cachedIGetAccessor[key] = getAccessor;
                            }
                            else
                            {
                                getAccessor = _createFieldGetAccessor(targetType, name);
                                _cachedIGetAccessor[key] = getAccessor;
                            }
                        }
                        else
                        {
                            throw new ProbeException(
                                      string.Format("No property or field named \"{0}\" exists for type "
                                                    + "{1}.", name, targetType));
                        }
                    }
                    else
                    {
                        getAccessor = (IGetAccessor)_cachedIGetAccessor[key];
                    }
                }
                return(getAccessor);
            }
        }
Ejemplo n.º 17
0
        public static object GetMember(object obj, string memberName, AccessorFactory accessorFactory)
        {
            object obj3;

            try
            {
                object obj2 = null;
                if (memberName.IndexOf("[") > -1)
                {
                    obj2 = GetArrayMember(obj, memberName, accessorFactory);
                }
                else if (obj is IDictionary)
                {
                    obj2 = ((IDictionary)obj)[memberName];
                }
                else
                {
                    Type         targetType = obj.GetType();
                    IGetAccessor accessor   = accessorFactory.GetAccessorFactory.CreateGetAccessor(targetType, memberName);
                    if (accessor == null)
                    {
                        throw new ProbeException("No Get method for member " + memberName + " on instance of " + obj.GetType().Name);
                    }
                    try
                    {
                        obj2 = accessor.Get(obj);
                    }
                    catch (Exception exception)
                    {
                        throw new ProbeException(exception);
                    }
                }
                obj3 = obj2;
            }
            catch (ProbeException exception2)
            {
                throw exception2;
            }
            catch (Exception exception3)
            {
                throw new ProbeException("Could not Set property '" + memberName + "' for " + obj.GetType().Name + ".  Cause: " + exception3.Message, exception3);
            }
            return(obj3);
        }
Ejemplo n.º 18
0
        public void TestJIRA210OnGet()
        {
            //----------------------------
            IGetAccessor addressGet = factoryGet.CreateGetAccessor(typeof(User), "Address");

            User user = new User();

            user.Address = new Address();
            Guid newGuid = Guid.NewGuid();

            user.Address.Id = newGuid;

            IAddress address = (IAddress)addressGet.Get(user);

            Assert.IsNotNull(address);
            Assert.AreEqual(newGuid, address.Id);

            IGetAccessor domainGet = factoryGet.CreateGetAccessor(typeof(IAddress), "Id");

            Guid guid = (Guid)domainGet.Get(address);

            Assert.AreEqual(newGuid, guid);
        }
Ejemplo n.º 19
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ParameterProperty"/> class.
        /// </summary>
        /// <param name="propertyName">Name of the property.</param>
        /// <param name="columnName">Name of the column.</param>
        /// <param name="callBackName">Name of the call back.</param>
        /// <param name="clrType">Type of the CLR.</param>
        /// <param name="dbType">Type of the db.</param>
        /// <param name="directionAttribute">The direction attribute.</param>
        /// <param name="nullValue">The null value.</param>
        /// <param name="precision">The precision.</param>
        /// <param name="scale">The scale.</param>
        /// <param name="size">The size.</param>
        /// <param name="parameterClass">The parameter class.</param>
        /// <param name="dataExchangeFactory">The data exchange factory.</param>
        public ParameterProperty(
            string propertyName,
            string columnName,
            string callBackName,
            string clrType,
            string dbType,
            string directionAttribute,
            string nullValue,
            Byte precision,
            Byte scale,
            int size,
            Type parameterClass,
            DataExchangeFactory dataExchangeFactory
            )
        {
            Contract.Require.That(propertyName, Is.Not.Null & Is.Not.Empty).When("retrieving argument propertyName in ParameterProperty constructor");

            this.columnName           = columnName;
            this.callBackName         = callBackName;
            this.clrType              = clrType;
            this.dbType               = dbType;
            this.nullValue            = nullValue;
            this.precision            = precision;
            this.scale                = scale;
            this.size                 = size;
            this._parameterClass      = parameterClass;
            this._dataExchangeFactory = dataExchangeFactory;

            #region Direction

            if (directionAttribute.Length > 0)
            {
                direction = (ParameterDirection)Enum.Parse(typeof(ParameterDirection), directionAttribute, true);
                this.directionAttribute = direction.ToString();
            }

            #endregion Direction

            #region Property Name

            this._currentPropertyName = propertyName;
            this._propertyPlaceholder = propertyName;

            if (propertyName.IndexOf('.') < 0)
            {
                isComplexMemberName = false;
            }
            else // complex member name FavouriteLineItem.Id
            {
                isComplexMemberName = true;
            }

            #endregion Property Name

            #region GetAccessor

            if (!typeof(IDictionary).IsAssignableFrom(parameterClass) && // Hashtable parameter map
                parameterClass != null && // value property
                !dataExchangeFactory.TypeHandlerFactory.IsSimpleType(parameterClass))    // value property
            {
                if (!isComplexMemberName)
                {
                    IGetAccessorFactory getAccessorFactory = dataExchangeFactory.AccessorFactory.GetAccessorFactory;
                    getAccessor = getAccessorFactory.CreateGetAccessor(parameterClass, propertyName);
                }
                else // complex member name FavouriteLineItem.Id
                {
                    string memberName = propertyName.Substring(propertyName.LastIndexOf('.') + 1);
                    string parentName = propertyName.Substring(0, propertyName.LastIndexOf('.'));
                    Type   parentType = ObjectProbe.GetMemberTypeForGetter(parameterClass, parentName);

                    IGetAccessorFactory getAccessorFactory = dataExchangeFactory.AccessorFactory.GetAccessorFactory;
                    getAccessor = getAccessorFactory.CreateGetAccessor(parentType, memberName);
                }
            }

            #endregion GetAccessor

            #region TypeHandler

            if (CallBackName.Length > 0)
            {
                try
                {
                    Type type = dataExchangeFactory.TypeHandlerFactory.GetType(CallBackName);
                    ITypeHandlerCallback typeHandlerCallback = (ITypeHandlerCallback)Activator.CreateInstance(type);
                    typeHandler = new CustomTypeHandler(typeHandlerCallback);
                }
                catch (Exception e)
                {
                    throw new ConfigurationException("Error occurred during custom type handler configuration.  Cause: " + e.Message, e);
                }
            }
            else
            {
                if (CLRType.Length == 0)  // Unknown
                {
                    if (getAccessor != null &&
                        dataExchangeFactory.TypeHandlerFactory.IsSimpleType(getAccessor.MemberType))
                    {
                        // Primitive
                        typeHandler = dataExchangeFactory.TypeHandlerFactory.GetTypeHandler(getAccessor.MemberType, dbType);
                    }
                    else
                    {
                        typeHandler = dataExchangeFactory.TypeHandlerFactory.GetUnkownTypeHandler();
                    }
                }
                else // If we specify a CLR type, use it
                {
                    Type type = TypeUtils.ResolveType(CLRType);

                    if (dataExchangeFactory.TypeHandlerFactory.IsSimpleType(type))
                    {
                        // Primitive
                        typeHandler = dataExchangeFactory.TypeHandlerFactory.GetTypeHandler(type, dbType);
                    }
                    else
                    {
                        // .NET object
                        type        = ObjectProbe.GetMemberTypeForGetter(parameterClass, PropertyName);
                        typeHandler = dataExchangeFactory.TypeHandlerFactory.GetTypeHandler(type, dbType);
                    }
                }
            }

            #endregion TypeHandler
        }
Ejemplo n.º 20
0
        /// <summary>
        /// Initializes the parameter property
        /// </summary>
        /// <param name="scope">The scope.</param>
        /// <param name="parameterClass">The parameter class.</param>
        public void Initialize(IScope scope, Type parameterClass)
        {
            if (_directionAttribute.Length > 0)
            {
                _direction = (ParameterDirection)Enum.Parse(typeof(ParameterDirection), _directionAttribute, true);
            }

            if (!typeof(IDictionary).IsAssignableFrom(parameterClass) &&          // Hashtable parameter map
                parameterClass != null &&                // value property
                !scope.DataExchangeFactory.TypeHandlerFactory.IsSimpleType(parameterClass))                     // value property
            {
                if (!_isComplexMemberName)
                {
                    IGetAccessorFactory getAccessorFactory = scope.DataExchangeFactory.AccessorFactory.GetAccessorFactory;
                    _getAccessor = getAccessorFactory.CreateGetAccessor(parameterClass, _propertyName);
                }
                else                 // complex member name FavouriteLineItem.Id
                {
                    string memberName = _propertyName.Substring(_propertyName.LastIndexOf('.') + 1);
                    string parentName = _propertyName.Substring(0, _propertyName.LastIndexOf('.'));
                    Type   parentType = ObjectProbe.GetMemberTypeForGetter(parameterClass, parentName);

                    IGetAccessorFactory getAccessorFactory = scope.DataExchangeFactory.AccessorFactory.GetAccessorFactory;
                    _getAccessor = getAccessorFactory.CreateGetAccessor(parentType, memberName);
                }
            }

            scope.ErrorContext.MoreInfo = "Check the parameter mapping typeHandler attribute '" + this.CallBackName + "' (must be a ITypeHandlerCallback implementation).";
            if (this.CallBackName.Length > 0)
            {
                try
                {
                    Type type = scope.DataExchangeFactory.TypeHandlerFactory.GetType(this.CallBackName);
                    ITypeHandlerCallback typeHandlerCallback = (ITypeHandlerCallback)Activator.CreateInstance(type);
                    _typeHandler = new CustomTypeHandler(typeHandlerCallback);
                }
                catch (Exception e)
                {
                    throw new ConfigurationException("Error occurred during custom type handler configuration.  Cause: " + e.Message, e);
                }
            }
            else
            {
                if (this.CLRType.Length == 0)                   // Unknown
                {
                    if (_getAccessor != null &&
                        scope.DataExchangeFactory.TypeHandlerFactory.IsSimpleType(_getAccessor.MemberType))
                    {
                        // Primitive
                        _typeHandler = scope.DataExchangeFactory.TypeHandlerFactory.GetTypeHandler(_getAccessor.MemberType, _dbType);
                    }
                    else
                    {
                        _typeHandler = scope.DataExchangeFactory.TypeHandlerFactory.GetUnkownTypeHandler();
                    }
                }
                else                 // If we specify a CLR type, use it
                {
                    Type type = TypeUtils.ResolveType(this.CLRType);

                    if (scope.DataExchangeFactory.TypeHandlerFactory.IsSimpleType(type))
                    {
                        // Primitive
                        _typeHandler = scope.DataExchangeFactory.TypeHandlerFactory.GetTypeHandler(type, _dbType);
                    }
                    else
                    {
                        // .NET object
                        type         = ObjectProbe.GetMemberTypeForGetter(type, this.PropertyName);
                        _typeHandler = scope.DataExchangeFactory.TypeHandlerFactory.GetTypeHandler(type, _dbType);
                    }
                }
            }
        }
        public void SetUp()
        {
            intSetAccessor = factorySet.CreateSetAccessor(typeof(Property), "protectedInt");
            intGetAccessor = factoryGet.CreateGetAccessor(typeof(Property), "protectedInt");

            longSetAccessor = factorySet.CreateSetAccessor(typeof(Property), "protectedLong");
            longGetAccessor = factoryGet.CreateGetAccessor(typeof(Property), "protectedLong");

            sbyteSetAccessor = factorySet.CreateSetAccessor(typeof(Property), "protectedSbyte");
            sbyteGetAccessor = factoryGet.CreateGetAccessor(typeof(Property), "protectedSbyte");

            stringSetAccessor = factorySet.CreateSetAccessor(typeof(Property), "protectedString");
            stringGetAccessor = factoryGet.CreateGetAccessor(typeof(Property), "protectedString");

            datetimeSetAccessor = factorySet.CreateSetAccessor(typeof(Property), "protectedDateTime");
            datetimeGetAccessor = factoryGet.CreateGetAccessor(typeof(Property), "protectedDateTime");

            decimalSetAccessor = factorySet.CreateSetAccessor(typeof(Property), "protectedDecimal");
            decimalGetAccessor = factoryGet.CreateGetAccessor(typeof(Property), "protectedDecimal");

            byteSetAccessor = factorySet.CreateSetAccessor(typeof(Property), "protectedByte");
            byteGetAccessor = factoryGet.CreateGetAccessor(typeof(Property), "protectedByte");

            charSetAccessor = factorySet.CreateSetAccessor(typeof(Property), "protectedChar");
            charGetAccessor = factoryGet.CreateGetAccessor(typeof(Property), "protectedChar");

            shortSetAccessor = factorySet.CreateSetAccessor(typeof(Property), "protectedShort");
            shortGetAccessor = factoryGet.CreateGetAccessor(typeof(Property), "protectedShort");

            ushortSetAccessor = factorySet.CreateSetAccessor(typeof(Property), "protectedUshort");
            ushortGetAccessor = factoryGet.CreateGetAccessor(typeof(Property), "protectedUshort");

            uintSetAccessor = factorySet.CreateSetAccessor(typeof(Property), "protectedUint");
            uintGetAccessor = factoryGet.CreateGetAccessor(typeof(Property), "protectedUint");

            ulongSetAccessor = factorySet.CreateSetAccessor(typeof(Property), "protectedUlong");
            ulongGetAccessor = factoryGet.CreateGetAccessor(typeof(Property), "protectedUlong");

            boolSetAccessor = factorySet.CreateSetAccessor(typeof(Property), "protectedBool");
            boolGetAccessor = factoryGet.CreateGetAccessor(typeof(Property), "protectedBool");

            doubleSetAccessor = factorySet.CreateSetAccessor(typeof(Property), "protectedDouble");
            doubleGetAccessor = factoryGet.CreateGetAccessor(typeof(Property), "protectedDouble");

            floatSetAccessor = factorySet.CreateSetAccessor(typeof(Property), "protectedFloat");
            floatGetAccessor = factoryGet.CreateGetAccessor(typeof(Property), "protectedFloat");

            guidSetAccessor = factorySet.CreateSetAccessor(typeof(Property), "protectedGuid");
            guidGetAccessor = factoryGet.CreateGetAccessor(typeof(Property), "protectedGuid");

            timespanSetAccessor = factorySet.CreateSetAccessor(typeof(Property), "protectedTimeSpan");
            timespanGetAccessor = factoryGet.CreateGetAccessor(typeof(Property), "protectedTimeSpan");

            accountSetAccessor = factorySet.CreateSetAccessor(typeof(Property), "protectedAccount");
            accountGetAccessor = factoryGet.CreateGetAccessor(typeof(Property), "protectedAccount");

            enumSetAccessor = factorySet.CreateSetAccessor(typeof(Property), "protectedDay");
            enumGetAccessor = factoryGet.CreateGetAccessor(typeof(Property), "protectedDay");

            nullableSetAccessor = factorySet.CreateSetAccessor(typeof(Property), "protectedintNullable");
            nullableGetAccessor = factoryGet.CreateGetAccessor(typeof(Property), "protectedintNullable");
        }
Ejemplo n.º 22
0
        public void SetUp()
        {
            intSetAccessor = factorySet.CreateSetAccessor(typeof(Property), "publicInt");
            intGetAccessor = factoryGet.CreateGetAccessor(typeof(Property), "publicInt");

            longSetAccessor = factorySet.CreateSetAccessor(typeof(Property), "publicLong");
            longGetAccessor = factoryGet.CreateGetAccessor(typeof(Property), "publicLong");

            sbyteSetAccessor = factorySet.CreateSetAccessor(typeof(Property), "publicSbyte");
            sbyteGetAccessor = factoryGet.CreateGetAccessor(typeof(Property), "publicSbyte");

            stringSetAccessor = factorySet.CreateSetAccessor(typeof(Property), "publicString");
            stringGetAccessor = factoryGet.CreateGetAccessor(typeof(Property), "publicString");

            datetimeSetAccessor = factorySet.CreateSetAccessor(typeof(Property), "publicDateTime");
            datetimeGetAccessor = factoryGet.CreateGetAccessor(typeof(Property), "publicDateTime");

            decimalSetAccessor = factorySet.CreateSetAccessor(typeof(Property), "publicDecimal");
            decimalGetAccessor = factoryGet.CreateGetAccessor(typeof(Property), "publicDecimal");

            byteSetAccessor = factorySet.CreateSetAccessor(typeof(Property), "publicByte");
            byteGetAccessor = factoryGet.CreateGetAccessor(typeof(Property), "publicByte");

            charSetAccessor = factorySet.CreateSetAccessor(typeof(Property), "publicChar");
            charGetAccessor = factoryGet.CreateGetAccessor(typeof(Property), "publicChar");

            shortSetAccessor = factorySet.CreateSetAccessor(typeof(Property), "publicShort");
            shortGetAccessor = factoryGet.CreateGetAccessor(typeof(Property), "publicShort");

            ushortSetAccessor = factorySet.CreateSetAccessor(typeof(Property), "publicUshort");
            ushortGetAccessor = factoryGet.CreateGetAccessor(typeof(Property), "publicUshort");

            uintSetAccessor = factorySet.CreateSetAccessor(typeof(Property), "publicUint");
            uintGetAccessor = factoryGet.CreateGetAccessor(typeof(Property), "publicUint");

            ulongSetAccessor = factorySet.CreateSetAccessor(typeof(Property), "publicUlong");
            ulongGetAccessor = factoryGet.CreateGetAccessor(typeof(Property), "publicUlong");

            boolSetAccessor = factorySet.CreateSetAccessor(typeof(Property), "publicBool");
            boolGetAccessor = factoryGet.CreateGetAccessor(typeof(Property), "publicBool");

            doubleSetAccessor = factorySet.CreateSetAccessor(typeof(Property), "publicDouble");
            doubleGetAccessor = factoryGet.CreateGetAccessor(typeof(Property), "publicDouble");

            floatSetAccessor = factorySet.CreateSetAccessor(typeof(Property), "publicFloat");
            floatGetAccessor = factoryGet.CreateGetAccessor(typeof(Property), "publicFloat");

            guidSetAccessor = factorySet.CreateSetAccessor(typeof(Property), "publicGuid");
            guidGetAccessor = factoryGet.CreateGetAccessor(typeof(Property), "publicGuid");

            timespanSetAccessor = factorySet.CreateSetAccessor(typeof(Property), "publicTimeSpan");
            timespanGetAccessor = factoryGet.CreateGetAccessor(typeof(Property), "publicTimeSpan");

            accountSetAccessor = factorySet.CreateSetAccessor(typeof(Property), "publicAccount");
            accountGetAccessor = factoryGet.CreateGetAccessor(typeof(Property), "publicAccount");

            enumSetAccessor = factorySet.CreateSetAccessor(typeof(Property), "publicDay");
            enumGetAccessor = factoryGet.CreateGetAccessor(typeof(Property), "publicDay");

            nullableSetAccessor = factorySet.CreateSetAccessor(typeof(Property), "publicintNullable");
            nullableGetAccessor = factoryGet.CreateGetAccessor(typeof(Property), "publicintNullable");
        }
Ejemplo n.º 23
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ParameterProperty"/> class.
        /// </summary>
        /// <param name="propertyName">Name of the property.</param>
        /// <param name="columnName">Name of the column.</param>
        /// <param name="callBackName">Name of the call back.</param>
        /// <param name="clrType">Type of the CLR.</param>
        /// <param name="dbType">Type of the db.</param>
        /// <param name="directionAttribute">The direction attribute.</param>
        /// <param name="nullValue">The null value.</param>
        /// <param name="precision">The precision.</param>
        /// <param name="scale">The scale.</param>
        /// <param name="size">The size.</param>
        /// <param name="parameterClass">The parameter class.</param>
        /// <param name="dataExchangeFactory">The data exchange factory.</param>
        public ParameterProperty(
            string propertyName,
            string columnName,
            string callBackName,
            string clrType,
            string dbType,
            string directionAttribute,
            string nullValue,
            Byte precision,
            Byte scale,
            int size,
            Type parameterClass,
            DataExchangeFactory dataExchangeFactory 
            )
        {
            Contract.Require.That(propertyName, Is.Not.Null & Is.Not.Empty).When("retrieving argument propertyName in ParameterProperty constructor");

            this.columnName = columnName;
            this.callBackName = callBackName;
            this.clrType = clrType;
            this.dbType = dbType;
            this.nullValue = nullValue;
            this.precision = precision;
            this.scale = scale;
            this.size = size;

            #region Direction
            if (directionAttribute.Length > 0)
            {
                direction = (ParameterDirection)Enum.Parse(typeof(ParameterDirection), directionAttribute, true);
                this.directionAttribute = direction.ToString();
            }
            #endregion

            #region Property Name
            this.propertyName = propertyName;
            if (propertyName.IndexOf('.') < 0)
            {
                isComplexMemberName = false;
            }
            else // complex member name FavouriteLineItem.Id
            {
                isComplexMemberName = true;
            }
            #endregion

            #region GetAccessor
            if (!typeof(IDictionary).IsAssignableFrom(parameterClass) // Hashtable parameter map
                && parameterClass != null // value property
                && !dataExchangeFactory.TypeHandlerFactory.IsSimpleType(parameterClass)) // value property
            {
                if (!isComplexMemberName)
                {
                    IGetAccessorFactory getAccessorFactory = dataExchangeFactory.AccessorFactory.GetAccessorFactory;
                    getAccessor = getAccessorFactory.CreateGetAccessor(parameterClass, propertyName);
                }
                else // complex member name FavouriteLineItem.Id
                {
                    string memberName = propertyName.Substring(propertyName.LastIndexOf('.') + 1);
                    string parentName = propertyName.Substring(0, propertyName.LastIndexOf('.'));
                    Type parentType = ObjectProbe.GetMemberTypeForGetter(parameterClass, parentName);

                    IGetAccessorFactory getAccessorFactory = dataExchangeFactory.AccessorFactory.GetAccessorFactory;
                    getAccessor = getAccessorFactory.CreateGetAccessor(parentType, memberName);
                }
            }
            #endregion

            #region TypeHandler
            if (CallBackName.Length > 0)
            {
                try
                {
                    Type type = dataExchangeFactory.TypeHandlerFactory.GetType(CallBackName);
                    ITypeHandlerCallback typeHandlerCallback = (ITypeHandlerCallback)Activator.CreateInstance(type);
                    typeHandler = new CustomTypeHandler(typeHandlerCallback);
                }
                catch (Exception e)
                {
                    throw new ConfigurationException("Error occurred during custom type handler configuration.  Cause: " + e.Message, e);
                }
            }
            else
            {
                if (CLRType.Length == 0)  // Unknown
                {
                    if (getAccessor != null &&
                        dataExchangeFactory.TypeHandlerFactory.IsSimpleType(getAccessor.MemberType))
                    {
                        // Primitive
                        typeHandler = dataExchangeFactory.TypeHandlerFactory.GetTypeHandler(getAccessor.MemberType, dbType);
                    }
                    else
                    {
                        typeHandler = dataExchangeFactory.TypeHandlerFactory.GetUnkownTypeHandler();
                    }
                }
                else // If we specify a CLR type, use it
                {
                    Type type = TypeUtils.ResolveType(CLRType);

                    if (dataExchangeFactory.TypeHandlerFactory.IsSimpleType(type))
                    {
                        // Primitive
                        typeHandler = dataExchangeFactory.TypeHandlerFactory.GetTypeHandler(type, dbType);
                    }
                    else
                    {
                        // .NET object
                        type = ObjectProbe.GetMemberTypeForGetter(parameterClass, PropertyName);
                        typeHandler = dataExchangeFactory.TypeHandlerFactory.GetTypeHandler(type, dbType);
                    }
                }
            }

            #endregion
        }
Ejemplo n.º 24
0
        /// <summary>
        /// 根据属性名验证
        /// </summary>
        /// <param name="propertyName">属性名称</param>
        /// <param name="validateObj">待验证对象</param>
        /// <returns>验证错误集合</returns>
        public List <ValidationError> ValidateProperty(string propertyName, object validateObj)
        {
            this.InitializePropertyCache();
            List <ValidationError> errorList = new List <ValidationError>();

            if (validateObj != null)
            {
                IEnumerable <Validator> vs = null;

                lock (this)
                {
                    if (this.propertyDic.ContainsKey(propertyName))
                    {
                        PropertyInfo propertyInfo = this.propertyDic[propertyName];

                        if (this.validatorDic.ContainsKey(propertyName))
                        {
                            vs = this.validatorDic[propertyName];
                        }
                        else
                        {
                            object[] attributes = propertyInfo.GetCustomAttributes(typeof(ValidatorAttribute), true);
                            if (attributes != null && attributes.Length > 0)
                            {
                                List <Validator> vds = new List <Validator>();
                                foreach (ValidatorAttribute validatorAttribute in attributes)
                                {
                                    vds.Add(validatorAttribute.CreateValidator());
                                }
                                this.validatorDic.Add(propertyName, vds);
                                vs = vds;
                            }
                        }
                    }
                }

                if (vs != null)
                {
                    IGetAccessor getAccessor = null;
                    if (validateObj is IGetAccessor)
                    {
                        getAccessor = validateObj as IGetAccessor;
                    }
                    foreach (Validator validator in vs)
                    {
                        ValidationError error = null;
                        if (getAccessor == null)
                        {
                            error = validator.Validate(validateObj.GetType().GetProperty(propertyName).GetValue(validateObj, null), validateObj);
                        }
                        else
                        {
                            error = validator.Validate(getAccessor.GetValue(propertyName), validateObj);
                        }
                        if (error != null)
                        {
                            errorList.Add(error);
                        }
                    }
                }
            }
            return(errorList);
        }
Ejemplo n.º 25
0
        /// <summary>
        /// Initializes the parameter property
        /// </summary>
        /// <param name="scope">The scope.</param>
        /// <param name="parameterClass">The parameter class.</param>
        public void Initialize(IScope scope, Type parameterClass)
        {
            if(_directionAttribute.Length >0)
            {
                _direction = (ParameterDirection)Enum.Parse( typeof(ParameterDirection), _directionAttribute, true );
            }

            if (!typeof(IDictionary).IsAssignableFrom(parameterClass) // Hashtable parameter map
                && parameterClass !=null // value property
                && !scope.DataExchangeFactory.TypeHandlerFactory.IsSimpleType(parameterClass) ) // value property
            {
                if (!_isComplexMemberName)
                {
                    IGetAccessorFactory getAccessorFactory = scope.DataExchangeFactory.AccessorFactory.GetAccessorFactory;
                    _getAccessor = getAccessorFactory.CreateGetAccessor(parameterClass, _propertyName);
                }
                else // complex member name FavouriteLineItem.Id
                {
                    string memberName = _propertyName.Substring( _propertyName.LastIndexOf('.')+1);
                    string parentName = _propertyName.Substring(0,_propertyName.LastIndexOf('.'));
                    Type parentType = ObjectProbe.GetMemberTypeForGetter(parameterClass, parentName);

                    IGetAccessorFactory getAccessorFactory = scope.DataExchangeFactory.AccessorFactory.GetAccessorFactory;
                    _getAccessor = getAccessorFactory.CreateGetAccessor(parentType, memberName);
                }
            }

            scope.ErrorContext.MoreInfo = "Check the parameter mapping typeHandler attribute '" + this.CallBackName + "' (must be a ITypeHandlerCallback implementation).";
            if (this.CallBackName.Length >0)
            {
                try
                {
                    Type type = scope.DataExchangeFactory.TypeHandlerFactory.GetType(this.CallBackName);
                    ITypeHandlerCallback typeHandlerCallback = (ITypeHandlerCallback) Activator.CreateInstance( type );
                    _typeHandler = new CustomTypeHandler(typeHandlerCallback);
                }
                catch (Exception e)
                {
                    throw new ConfigurationException("Error occurred during custom type handler configuration.  Cause: " + e.Message, e);
                }
            }
            else
            {
                if (this.CLRType.Length == 0 )  // Unknown
                {
                    if (_getAccessor!= null &&
                        scope.DataExchangeFactory.TypeHandlerFactory.IsSimpleType(_getAccessor.MemberType))
                    {
                        // Primitive
                        _typeHandler = scope.DataExchangeFactory.TypeHandlerFactory.GetTypeHandler(_getAccessor.MemberType, _dbType);
                    }
                    else
                    {
                        _typeHandler = scope.DataExchangeFactory.TypeHandlerFactory.GetUnkownTypeHandler();
                    }
                }
                else // If we specify a CLR type, use it
                {
                    Type type = TypeUtils.ResolveType(this.CLRType);

                    if (scope.DataExchangeFactory.TypeHandlerFactory.IsSimpleType(type))
                    {
                        // Primitive
                        _typeHandler = scope.DataExchangeFactory.TypeHandlerFactory.GetTypeHandler(type, _dbType);
                    }
                    else
                    {
                        // .NET object
                        type = ObjectProbe.GetMemberTypeForGetter(type, this.PropertyName);
                        _typeHandler = scope.DataExchangeFactory.TypeHandlerFactory.GetTypeHandler(type, _dbType);
                    }
                }
            }
        }
Ejemplo n.º 26
0
        public void SetUp()
        {
            intSetAccessor = factorySet.CreateSetAccessor(typeof(Property), "protectedInt");
            intGetAccessor = factoryGet.CreateGetAccessor(typeof(Property), "protectedInt");

            longSetAccessor = factorySet.CreateSetAccessor(typeof(Property), "protectedLong");
            longGetAccessor = factoryGet.CreateGetAccessor(typeof(Property), "protectedLong");

            sbyteSetAccessor = factorySet.CreateSetAccessor(typeof(Property), "protectedSbyte");
            sbyteGetAccessor = factoryGet.CreateGetAccessor(typeof(Property), "protectedSbyte");

            stringSetAccessor = factorySet.CreateSetAccessor(typeof(Property), "protectedString");
            stringGetAccessor = factoryGet.CreateGetAccessor(typeof(Property), "protectedString");

            datetimeSetAccessor = factorySet.CreateSetAccessor(typeof(Property), "protectedDateTime");
            datetimeGetAccessor = factoryGet.CreateGetAccessor(typeof(Property), "protectedDateTime");

            decimalSetAccessor = factorySet.CreateSetAccessor(typeof(Property), "protectedDecimal");
            decimalGetAccessor = factoryGet.CreateGetAccessor(typeof(Property), "protectedDecimal");

            byteSetAccessor = factorySet.CreateSetAccessor(typeof(Property), "protectedByte");
            byteGetAccessor = factoryGet.CreateGetAccessor(typeof(Property), "protectedByte");

            charSetAccessor = factorySet.CreateSetAccessor(typeof(Property), "protectedChar");
            charGetAccessor = factoryGet.CreateGetAccessor(typeof(Property), "protectedChar");

            shortSetAccessor = factorySet.CreateSetAccessor(typeof(Property), "protectedShort");
            shortGetAccessor = factoryGet.CreateGetAccessor(typeof(Property), "protectedShort");

            ushortSetAccessor = factorySet.CreateSetAccessor(typeof(Property), "protectedUshort");
            ushortGetAccessor = factoryGet.CreateGetAccessor(typeof(Property), "protectedUshort");

            uintSetAccessor = factorySet.CreateSetAccessor(typeof(Property), "protectedUint");
            uintGetAccessor = factoryGet.CreateGetAccessor(typeof(Property), "protectedUint");

            ulongSetAccessor = factorySet.CreateSetAccessor(typeof(Property), "protectedUlong");
            ulongGetAccessor = factoryGet.CreateGetAccessor(typeof(Property), "protectedUlong");

            boolSetAccessor = factorySet.CreateSetAccessor(typeof(Property), "protectedBool");
            boolGetAccessor = factoryGet.CreateGetAccessor(typeof(Property), "protectedBool");

            doubleSetAccessor = factorySet.CreateSetAccessor(typeof(Property), "protectedDouble");
            doubleGetAccessor = factoryGet.CreateGetAccessor(typeof(Property), "protectedDouble");

            floatSetAccessor = factorySet.CreateSetAccessor(typeof(Property), "protectedFloat");
            floatGetAccessor = factoryGet.CreateGetAccessor(typeof(Property), "protectedFloat");

            guidSetAccessor = factorySet.CreateSetAccessor(typeof(Property), "protectedGuid");
            guidGetAccessor = factoryGet.CreateGetAccessor(typeof(Property), "protectedGuid");

            timespanSetAccessor = factorySet.CreateSetAccessor(typeof(Property), "protectedTimeSpan");
            timespanGetAccessor = factoryGet.CreateGetAccessor(typeof(Property), "protectedTimeSpan");

            accountSetAccessor = factorySet.CreateSetAccessor(typeof(Property), "protectedAccount");
            accountGetAccessor = factoryGet.CreateGetAccessor(typeof(Property), "protectedAccount");

            enumSetAccessor = factorySet.CreateSetAccessor(typeof(Property), "protectedDay");
            enumGetAccessor = factoryGet.CreateGetAccessor(typeof(Property), "protectedDay");

#if dotnet2
            nullableSetAccessor = factorySet.CreateSetAccessor(typeof(Property), "protectedintNullable");
            nullableGetAccessor = factoryGet.CreateGetAccessor(typeof(Property), "protectedintNullable");
#endif
        }
Ejemplo n.º 27
0
        public void SetUp()
        {
            intSetAccessor = factorySet.CreateSetAccessor(typeof(Property), "publicInt");
            intGetAccessor = factoryGet.CreateGetAccessor(typeof(Property), "publicInt");

            longSetAccessor = factorySet.CreateSetAccessor(typeof(Property), "publicLong");
            longGetAccessor = factoryGet.CreateGetAccessor(typeof(Property), "publicLong");

            sbyteSetAccessor = factorySet.CreateSetAccessor(typeof(Property), "publicSbyte");
            sbyteGetAccessor = factoryGet.CreateGetAccessor(typeof(Property), "publicSbyte");

            stringSetAccessor = factorySet.CreateSetAccessor(typeof(Property), "publicString");
            stringGetAccessor = factoryGet.CreateGetAccessor(typeof(Property), "publicString");

            datetimeSetAccessor = factorySet.CreateSetAccessor(typeof(Property), "publicDateTime");
            datetimeGetAccessor = factoryGet.CreateGetAccessor(typeof(Property), "publicDateTime");

            decimalSetAccessor = factorySet.CreateSetAccessor(typeof(Property), "publicDecimal");
            decimalGetAccessor = factoryGet.CreateGetAccessor(typeof(Property), "publicDecimal");

            byteSetAccessor = factorySet.CreateSetAccessor(typeof(Property), "publicByte");
            byteGetAccessor = factoryGet.CreateGetAccessor(typeof(Property), "publicByte");

            charSetAccessor = factorySet.CreateSetAccessor(typeof(Property), "publicChar");
            charGetAccessor = factoryGet.CreateGetAccessor(typeof(Property), "publicChar");

            shortSetAccessor = factorySet.CreateSetAccessor(typeof(Property), "publicShort");
            shortGetAccessor = factoryGet.CreateGetAccessor(typeof(Property), "publicShort");

            ushortSetAccessor = factorySet.CreateSetAccessor(typeof(Property), "publicUshort");
            ushortGetAccessor = factoryGet.CreateGetAccessor(typeof(Property), "publicUshort");

            uintSetAccessor = factorySet.CreateSetAccessor(typeof(Property), "publicUint");
            uintGetAccessor = factoryGet.CreateGetAccessor(typeof(Property), "publicUint");

            ulongSetAccessor = factorySet.CreateSetAccessor(typeof(Property), "publicUlong");
            ulongGetAccessor = factoryGet.CreateGetAccessor(typeof(Property), "publicUlong");

            boolSetAccessor = factorySet.CreateSetAccessor(typeof(Property), "publicBool");
            boolGetAccessor = factoryGet.CreateGetAccessor(typeof(Property), "publicBool");

            doubleSetAccessor = factorySet.CreateSetAccessor(typeof(Property), "publicDouble");
            doubleGetAccessor = factoryGet.CreateGetAccessor(typeof(Property), "publicDouble");

            floatSetAccessor = factorySet.CreateSetAccessor(typeof(Property), "publicFloat");
            floatGetAccessor = factoryGet.CreateGetAccessor(typeof(Property), "publicFloat");

            guidSetAccessor = factorySet.CreateSetAccessor(typeof(Property), "publicGuid");
            guidGetAccessor = factoryGet.CreateGetAccessor(typeof(Property), "publicGuid");

            timespanSetAccessor = factorySet.CreateSetAccessor(typeof(Property), "publicTimeSpan");
            timespanGetAccessor = factoryGet.CreateGetAccessor(typeof(Property), "publicTimeSpan");

            accountSetAccessor = factorySet.CreateSetAccessor(typeof(Property), "publicAccount");
            accountGetAccessor = factoryGet.CreateGetAccessor(typeof(Property), "publicAccount");

            enumSetAccessor = factorySet.CreateSetAccessor(typeof(Property), "publicDay");
            enumGetAccessor = factoryGet.CreateGetAccessor(typeof(Property), "publicDay");

#if dotnet2
            nullableSetAccessor = factorySet.CreateSetAccessor(typeof(Property), "publicintNullable");
            nullableGetAccessor = factoryGet.CreateGetAccessor(typeof(Property), "publicintNullable");
#endif
        }
        public void TestGetIntegerPerformance()
        {
            const int TEST_ITERATIONS = 1000000;
            Property  prop            = new Property();
            int       test            = -1;
            Timer     timer           = new Timer();

            #region Direct access (fastest)
            GC.Collect();
            GC.WaitForPendingFinalizers();

            timer.Start();
            for (int i = 0; i < TEST_ITERATIONS; i++)
            {
                test = -1;
                test = prop.Int;
                Assert.AreEqual(int.MinValue, test);
            }
            timer.Stop();
            double directAccessDuration = 1000000 * (timer.Duration / (double)TEST_ITERATIONS);
            #endregion

            #region IL Property accessor
            GC.Collect();
            GC.WaitForPendingFinalizers();

            IGetAccessorFactory factory          = new GetAccessorFactory(true);
            IGetAccessor        propertyAccessor = factory.CreateGetAccessor(typeof(Property), "Int");
            timer.Start();
            for (int i = 0; i < TEST_ITERATIONS; i++)
            {
                test = -1;
                test = (int)propertyAccessor.Get(prop);
                Assert.AreEqual(int.MinValue, test);
            }
            timer.Stop();
            double propertyAccessorDuration = 1000000 * (timer.Duration / (double)TEST_ITERATIONS);
            double propertyAccessorRatio    = propertyAccessorDuration / directAccessDuration;
            #endregion

            #region SqlBatis.DataMapper.Utilities.Object.ReflectionInfo
            GC.Collect();
            GC.WaitForPendingFinalizers();

            ReflectionInfo reflectionInfo = ReflectionInfo.GetInstance(prop.GetType());
            timer.Start();
            for (int i = 0; i < TEST_ITERATIONS; i++)
            {
                test = -1;
                PropertyInfo propertyInfo = (PropertyInfo)reflectionInfo.GetGetter("Int");
                test = (int)propertyInfo.GetValue(prop, null);
                Assert.AreEqual(int.MinValue, test);
            }
            timer.Stop();
            double reflectionInfoDuration = 1000000 * (timer.Duration / (double)TEST_ITERATIONS);
            double reflectionInfoRatio    = (float)reflectionInfoDuration / directAccessDuration;
            #endregion

            #region Reflection
            GC.Collect();
            GC.WaitForPendingFinalizers();

            Type type = prop.GetType();
            timer.Start();
            for (int i = 0; i < TEST_ITERATIONS; i++)
            {
                test = -1;
                PropertyInfo propertyInfo = type.GetProperty("Int", BindingFlags.Public | BindingFlags.SetProperty | BindingFlags.Instance);
                test = (int)propertyInfo.GetValue(prop, null);
                Assert.AreEqual(int.MinValue, test);
            }
            timer.Stop();
            double reflectionDuration = 1000000 * (timer.Duration / (double)TEST_ITERATIONS);
            double reflectionRatio    = reflectionDuration / directAccessDuration;
            #endregion

            #region ReflectionInvokeMember (slowest)
            GC.Collect();
            GC.WaitForPendingFinalizers();

            timer.Start();
            for (int i = 0; i < TEST_ITERATIONS; i++)
            {
                test = -1;
                test = (int)type.InvokeMember("Int",
                                              BindingFlags.Public | BindingFlags.GetProperty | BindingFlags.Instance,
                                              null, prop, null);
                Assert.AreEqual(int.MinValue, test);
            }
            timer.Stop();
            double reflectionInvokeMemberDuration = 1000000 * (timer.Duration / (double)TEST_ITERATIONS);
            double reflectionInvokeMemberRatio    = reflectionInvokeMemberDuration / directAccessDuration;
            #endregion

            // Print results
            Console.WriteLine("{0} property gets on integer...", TEST_ITERATIONS);
            Console.WriteLine("Direct access: \t\t{0} ", directAccessDuration.ToString("F3"));
            Console.WriteLine("IMemberAccessor: \t\t{0} Ratio: {1}", propertyAccessorDuration.ToString("F3"), propertyAccessorRatio.ToString("F3"));
            Console.WriteLine("IBatisNet ReflectionInfo: \t{0} Ratio: {1}", reflectionInfoDuration.ToString("F3"), reflectionInfoRatio.ToString("F3"));
            Console.WriteLine("ReflectionInvokeMember: \t{0} Ratio: {1}", reflectionInvokeMemberDuration.ToString("F3"), reflectionInvokeMemberRatio.ToString("F3"));
            Console.WriteLine("Reflection: \t\t\t{0} Ratio: {1}", reflectionDuration.ToString("F3"), reflectionRatio.ToString("F3"));
        }