Ejemplo n.º 1
0
 /// <summary>
 /// 检查转换器
 /// </summary>
 /// <param name="tempPropertyAttribute"></param>
 /// <returns></returns>
 private bool CheckTransformer(PropertyAttribute tempPropertyAttribute)
 {
     return(!string.IsNullOrWhiteSpace(tempPropertyAttribute.UseTransformerName) && m_useChangeDelDic.ContainsKey(tempPropertyAttribute.UseTransformerName) && null != m_useChangeDelDic[tempPropertyAttribute.UseTransformerName]);
 }
Ejemplo n.º 2
0
        /// <summary>
        /// 注册一个类
        /// </summary>
        /// <param name="inputType"></param>
        private void RegisteredType(Type inputType, bool ifIsWrite = false)
        {
            //若已存在
            if (CheckInput(inputType))
            {
                return;
            }

            //获取类特性
            var classAttributes = inputType.GetCustomAttributes(m_useClassAttributeType, false);

            //获取检查
            if (null == classAttributes || 1 != classAttributes.Length)
            {
                WriteToDic(inputType, null);
                return;
            }

            //获取使用的类特性
            var useClassAtrribute = (ClassAttribute)classAttributes[0];

            //判断特性是否可用
            //若写状态则不限制
            if ((0 > useClassAtrribute.SheetIndex && string.IsNullOrWhiteSpace(useClassAtrribute.SheetName)) && !ifIsWrite)
            {
                WriteToDic(inputType, null);
                return;
            }

            //临时局部变量
            PropertyAttribute tempPropertyAttribute = null;

            //属性-属性特性映射字典
            Dictionary <PropertyInfo, PropertyAttribute> tempPropertyMap
                = new Dictionary <PropertyInfo, PropertyAttribute>();

            //获取公开属性
            foreach (var oneProperty in inputType.GetProperties())
            {
                //不可读可写 跳过
                if (!oneProperty.CanRead || !oneProperty.CanWrite)
                {
                    continue;
                }

                //获取临时特性
                tempPropertyAttribute = oneProperty.GetCustomAttribute(m_usePropertyAttributeType) as PropertyAttribute;

                //没有特性跳过
                //特性属性检查
                //且非写模式
                if ((null == tempPropertyAttribute ||
                     (0 > tempPropertyAttribute.UseColumnIndex &&
                      string.IsNullOrWhiteSpace(tempPropertyAttribute.UseColumnName))) &&
                    !ifIsWrite)
                {
                    continue;
                }


                //若不是字符串类型且没有粘贴方法 且没有注册转换器
                if (!TypePropertyInfo.CheckProperty(oneProperty) && !CheckTransformer(tempPropertyAttribute))
                {
                    continue;
                }

                //若已注册转换器
                if (CheckTransformer(tempPropertyAttribute))
                {
                    //赋值转换器
                    tempPropertyAttribute.UseTransformer = m_useChangeDelDic[tempPropertyAttribute.UseTransformerName];
                }

                //添加到属性映射
                tempPropertyMap.Add(oneProperty, tempPropertyAttribute);
            }



            //注册
            if (0 != tempPropertyMap.Count)
            {
                WriteToDic(inputType, new TypeInfo(inputType, useClassAtrribute, tempPropertyMap));
            }
            else
            {
                WriteToDic(inputType, null);
            }
        }