/// <summary> /// Initialize the PropertyInfo of the result property. /// </summary> /// <param name="resultClass"></param> /// <param name="configScope"></param> public void Initialize(ConfigurationScope configScope, Type resultClass) { if (_propertyName.Length > 0 && _propertyName != "value" && !typeof(IDictionary).IsAssignableFrom(resultClass)) { if (!_isComplexMemberName) { _setAccessor = configScope.DataExchangeFactory.AccessorFactory.SetAccessorFactory.CreateSetAccessor(resultClass, _propertyName); } else // complex member name FavouriteLineItem.Id { MemberInfo propertyInfo = ObjectProbe.GetMemberInfoForSetter(resultClass, _propertyName); string memberName = _propertyName.Substring(_propertyName.LastIndexOf('.') + 1); _setAccessor = configScope.DataExchangeFactory.AccessorFactory.SetAccessorFactory.CreateSetAccessor(propertyInfo.ReflectedType, memberName); } //#if dotnet2 _isGenericIList = TypeUtils.IsImplementGenericIListInterface(MemberType); //#endif _isIList = typeof(IList).IsAssignableFrom(MemberType); // set the list factory //#if dotnet2 if (_isGenericIList) { if (MemberType.IsArray) { _listFactory = _arrayListFactory; } else { Type[] typeArgs = MemberType.GetGenericArguments(); if (typeArgs.Length == 0)// Custom collection which derive from List<T> { _listFactory = configScope.DataExchangeFactory.ObjectFactory.CreateFactory(MemberType, Type.EmptyTypes); } else { Type genericIList = typeof(IList <>); Type interfaceListType = genericIList.MakeGenericType(typeArgs); Type genericList = typeof(List <>); Type listType = genericList.MakeGenericType(typeArgs); if ((interfaceListType == MemberType) || (listType == MemberType)) { Type constructedType = genericList.MakeGenericType(typeArgs); _listFactory = configScope.DataExchangeFactory.ObjectFactory.CreateFactory( constructedType, Type.EmptyTypes); } else // Custom collection which derive from List<T> { _listFactory = configScope.DataExchangeFactory.ObjectFactory.CreateFactory(MemberType, Type.EmptyTypes); } } } } else //#endif if (_isIList) { if (MemberType.IsArray) { _listFactory = _arrayListFactory; } else { if (MemberType == typeof(IList)) { _listFactory = _arrayListFactory; } else // custom collection { _listFactory = configScope.DataExchangeFactory.ObjectFactory.CreateFactory(MemberType, Type.EmptyTypes); } } } } if (CallBackName != null && CallBackName.Length > 0) { configScope.ErrorContext.MoreInfo = "Result property '" + _propertyName + "' check the typeHandler attribute '" + CallBackName + "' (must be a ITypeHandlerCallback implementation)."; try { Type type = configScope.SqlMapper.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 { configScope.ErrorContext.MoreInfo = "Result property '" + _propertyName + "' set the typeHandler attribute."; _typeHandler = configScope.ResolveTypeHandler(resultClass, _propertyName, _clrType, _dbType, true); } if (IsLazyLoad) { _lazyFactory = new LazyFactoryBuilder().GetLazyFactory(_setAccessor.MemberType); } }
public void Initialize(ConfigurationScope configScope, Type resultClass) { if (((this._propertyName.Length > 0) && (this._propertyName != "value")) && !typeof(IDictionary).IsAssignableFrom(resultClass)) { if (!this._isComplexMemberName) { this._setAccessor = configScope.DataExchangeFactory.AccessorFactory.SetAccessorFactory.CreateSetAccessor(resultClass, this._propertyName); } else { MemberInfo memberInfoForSetter = ObjectProbe.GetMemberInfoForSetter(resultClass, this._propertyName); string name = this._propertyName.Substring(this._propertyName.LastIndexOf('.') + 1); this._setAccessor = configScope.DataExchangeFactory.AccessorFactory.SetAccessorFactory.CreateSetAccessor(memberInfoForSetter.ReflectedType, name); } this._isGenericIList = TypeUtils.IsImplementGenericIListInterface(this.MemberType); this._isIList = typeof(IList).IsAssignableFrom(this.MemberType); if (this._isGenericIList) { if (this.MemberType.IsArray) { this._listFactory = _arrayListFactory; } else { Type[] genericArguments = this.MemberType.GetGenericArguments(); if (genericArguments.Length == 0) { this._listFactory = configScope.DataExchangeFactory.ObjectFactory.CreateFactory(this.MemberType, Type.EmptyTypes); } else { Type type2 = typeof(IList <>).MakeGenericType(genericArguments); Type type3 = typeof(List <>); Type type4 = type3.MakeGenericType(genericArguments); if ((type2 == this.MemberType) || (type4 == this.MemberType)) { Type typeToCreate = type3.MakeGenericType(genericArguments); this._listFactory = configScope.DataExchangeFactory.ObjectFactory.CreateFactory(typeToCreate, Type.EmptyTypes); } else { this._listFactory = configScope.DataExchangeFactory.ObjectFactory.CreateFactory(this.MemberType, Type.EmptyTypes); } } } } else if (this._isIList) { if (this.MemberType.IsArray) { this._listFactory = _arrayListFactory; } else if (this.MemberType == typeof(IList)) { this._listFactory = _arrayListFactory; } else { this._listFactory = configScope.DataExchangeFactory.ObjectFactory.CreateFactory(this.MemberType, Type.EmptyTypes); } } } if ((this.CallBackName != null) && (this.CallBackName.Length > 0)) { configScope.ErrorContext.MoreInfo = "Result property '" + this._propertyName + "' check the typeHandler attribute '" + this.CallBackName + "' (must be a ITypeHandlerCallback implementation)."; try { ITypeHandlerCallback callback = (ITypeHandlerCallback)Activator.CreateInstance(configScope.SqlMapper.TypeHandlerFactory.GetType(this.CallBackName)); this._typeHandler = new CustomTypeHandler(callback); goto Label_0320; } catch (Exception exception) { throw new ConfigurationException("Error occurred during custom type handler configuration. Cause: " + exception.Message, exception); } } configScope.ErrorContext.MoreInfo = "Result property '" + this._propertyName + "' set the typeHandler attribute."; this._typeHandler = configScope.ResolveTypeHandler(resultClass, this._propertyName, this._clrType, this._dbType, true); Label_0320: if (this.IsLazyLoad) { this._lazyFactory = new LazyFactoryBuilder().GetLazyFactory(this._setAccessor.MemberType); } }