当前位置: 首页>>代码示例>>C#>>正文


C# ResultProperty.Initialize方法代码示例

本文整理汇总了C#中IBatisNet.DataMapper.Configuration.ResultMapping.ResultProperty.Initialize方法的典型用法代码示例。如果您正苦于以下问题:C# ResultProperty.Initialize方法的具体用法?C# ResultProperty.Initialize怎么用?C# ResultProperty.Initialize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IBatisNet.DataMapper.Configuration.ResultMapping.ResultProperty的用法示例。


在下文中一共展示了ResultProperty.Initialize方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: SetMapping

        /// <summary>
        /// Initilaize the underlying mapping
        /// </summary>
        /// <param name="configScope"></param>
        /// <param name="resultClass"></param>
        public void SetMapping(ConfigurationScope configScope, Type resultClass)
        {
            configScope.ErrorContext.MoreInfo = "Initialize discriminator mapping";
            _mapping = new ResultProperty();
            _mapping.ColumnName =  _columnName;
            _mapping.ColumnIndex = _columnIndex;
            _mapping.CLRType = _clrType;
            _mapping.CallBackName = _callBackName;
            _mapping.DbType = _dbType;
            _mapping.NullValue = _nullValue;

            _mapping.Initialize( configScope, resultClass );
        }
开发者ID:zuifengke,项目名称:windy-ibatisnet,代码行数:18,代码来源:Discriminator.cs

示例2: Build

        /// <summary>
        /// Builds a <see cref="ResultPropertyCollection"/> for an <see cref="AutoResultMap"/>.
        /// </summary>
        /// <param name="dataExchangeFactory">The data exchange factory.</param>
        /// <param name="reader">The reader.</param>
        /// <param name="resultObject">The result object.</param>
        public static ResultPropertyCollection Build(DataExchangeFactory dataExchangeFactory,
		                        IDataReader reader,
			                    ref object resultObject)
        {
            Type targetType = resultObject.GetType();
            ResultPropertyCollection properties = new ResultPropertyCollection();

            try
            {
                // Get all PropertyInfo from the resultObject properties
                ReflectionInfo reflectionInfo = ReflectionInfo.GetInstance(targetType);
                string[] membersName = reflectionInfo.GetWriteableMemberNames();

                Hashtable propertyMap = new Hashtable();
                int length = membersName.Length;
                for (int i = 0; i < length; i++)
                {
                    ISetAccessorFactory setAccessorFactory = dataExchangeFactory.AccessorFactory.SetAccessorFactory;
                    ISetAccessor setAccessor = setAccessorFactory.CreateSetAccessor(targetType, membersName[i]);
                    propertyMap.Add(membersName[i], setAccessor);
                }

                // Get all column Name from the reader
                // and build a resultMap from with the help of the PropertyInfo[].
                DataTable dataColumn = reader.GetSchemaTable();
                int count = dataColumn.Rows.Count;
                for (int i = 0; i < count; i++)
                {
                    string columnName = dataColumn.Rows[i][0].ToString();
                    ISetAccessor matchedSetAccessor = propertyMap[columnName] as ISetAccessor;

                    ResultProperty property = new ResultProperty();
                    property.ColumnName = columnName;
                    property.ColumnIndex = i;

                    if (resultObject is Hashtable)
                    {
                        property.PropertyName = columnName;
                        properties.Add(property);
                    }

                    Type propertyType = null;

                    if (matchedSetAccessor == null)
                    {
                        try
                        {
                            propertyType = ObjectProbe.GetMemberTypeForSetter(resultObject, columnName);
                        }
                        catch
                        {
                            _logger.Error("The column [" + columnName + "] could not be auto mapped to a property on [" + resultObject.ToString() + "]");
                        }
                    }
                    else
                    {
                        propertyType = matchedSetAccessor.MemberType;
                    }

                    if (propertyType != null || matchedSetAccessor != null)
                    {
                        property.PropertyName = (matchedSetAccessor != null ? matchedSetAccessor.Name : columnName);
                        if (matchedSetAccessor != null)
                        {
                            property.Initialize(dataExchangeFactory.TypeHandlerFactory, matchedSetAccessor);
                        }
                        else
                        {
                            property.TypeHandler = dataExchangeFactory.TypeHandlerFactory.GetTypeHandler(propertyType);
                        }

                        property.PropertyStrategy = PropertyStrategyFactory.Get(property);
                        properties.Add(property);
                    }
                }
            }
            catch (Exception e)
            {
                throw new DataMapperException("Error automapping columns. Cause: " + e.Message, e);
            }

            return properties;
        }
开发者ID:zuifengke,项目名称:windy-ibatisnet,代码行数:89,代码来源:ReaderAutoMapper.cs


注:本文中的IBatisNet.DataMapper.Configuration.ResultMapping.ResultProperty.Initialize方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。