Exemple #1
0
        private static Dictionary <PropertyInfo, int> InitTxtToEntityMapper <T>(Dictionary <string, object> propertyMatch = null, TxtTypeEnum typeEnum = TxtTypeEnum.Normal) where T : class
        {
            int propertyIndex = 0;
            Dictionary <PropertyInfo, int> propertyDict = new Dictionary <PropertyInfo, int>();

            ReflectionGenericHelper.Foreach <T>((PropertyInfo propertyInfo) =>
            {
                if (propertyMatch != null && propertyMatch.ContainsKey(propertyInfo.Name))
                {
                    propertyDict.Add(propertyInfo, int.Parse(propertyMatch[propertyInfo.Name].ToString()));
                }
                else
                {
                    if (typeEnum == TxtTypeEnum.Attribute)
                    {
                        TxtTAttribute attribute = propertyInfo.GetCustomAttribute <TxtTAttribute>();
                        if (attribute != null && (attribute.Type == AttributeReadAndWriteTypeEnum.ReadAndWrite || attribute.Type == AttributeReadAndWriteTypeEnum.Read))
                        {
                            propertyDict.Add(propertyInfo, attribute.Index);
                        }
                    }
                    else
                    {
                        propertyDict.Add(propertyInfo, propertyIndex);
                        propertyIndex++;
                    }
                }
            });
            return(propertyDict);
        }
Exemple #2
0
        private static Dictionary <int, PropertyInfo> InitEntityToTxtMapper <T>(object propertyMatchList = null, TxtTypeEnum typeEnum = TxtTypeEnum.Normal, string[] propertyList = null, bool propertyContain = true) where T : class
        {
            List <string> filterNameList = null;

            if (propertyList != null)
            {
                filterNameList = propertyList.ToList <string>();
            }

            int propertyIndex = 0;

            Dictionary <string, object>    propertyMatchDict = CommonHelper.GetParameterDict(propertyMatchList);
            Dictionary <int, PropertyInfo> propertyNameDict  = new Dictionary <int, PropertyInfo>();

            ReflectionGenericHelper.Foreach <T>((PropertyInfo propertyInfo) =>
            {
                if (filterNameList == null || (propertyContain && filterNameList.IndexOf(propertyInfo.Name) >= 0) || (!propertyContain && filterNameList.IndexOf(propertyInfo.Name) < 0))
                {
                    if (propertyMatchDict != null && propertyMatchDict.ContainsKey(propertyInfo.Name))
                    {
                        propertyNameDict.Add(int.Parse(propertyMatchDict[propertyInfo.Name].ToString()), propertyInfo);
                    }
                    else
                    {
                        if (typeEnum == TxtTypeEnum.Attribute)
                        {
                            TxtTAttribute attribute = propertyInfo.GetCustomAttribute <TxtTAttribute>();
                            if (attribute != null && (attribute.Type == AttributeReadAndWriteTypeEnum.ReadAndWrite || attribute.Type == AttributeReadAndWriteTypeEnum.Write))
                            {
                                object attributeIndex = ReflectionExtendHelper.GetAttributeValue <TxtTAttribute>(typeof(T), propertyInfo, p => p.Index);
                                if (attributeIndex != null)
                                {
                                    propertyNameDict.Add(int.Parse(attributeIndex.ToString()), propertyInfo);
                                }
                            }
                        }
                        else
                        {
                            propertyNameDict.Add(propertyIndex, propertyInfo);
                            propertyIndex++;
                        }
                    }
                }
            });
            return(propertyNameDict);
        }