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); }
private static Dictionary <PropertyInfo, string> InitDbToEntityMapper <T>(DbDataReader reader, object propertyMatchList = null) where T : class { Dictionary <PropertyInfo, string> resultDict = new Dictionary <PropertyInfo, string>(); if (propertyMatchList != null) { Dictionary <string, object> propertyMatchDict = CommonHelper.GetParameterDict(propertyMatchList); ReflectionGenericHelper.Foreach <T>((PropertyInfo propertyInfo) => { string columnName = propertyInfo.Name; object propertyValue = propertyMatchDict[propertyInfo.Name]; if (propertyValue != null) { columnName = propertyValue.ToString(); } resultDict.Add(propertyInfo, columnName); }); return(resultDict); } string key = typeof(T).FullName; if (PropertyAttributeDict.ContainsKey(key)) { return(PropertyAttributeDict[key]); } lock (lockItem) { ReflectionGenericHelper.Foreach <T>((PropertyInfo propertyInfo) => { string columnName = ReflectionExtendHelper.GetAttributeValue <DataBaseTAttribute>(typeof(T), propertyInfo, p => p.Name); if (string.IsNullOrEmpty(columnName)) { columnName = propertyInfo.Name; } resultDict.Add(propertyInfo, columnName); }); if (!PropertyAttributeDict.ContainsKey(key)) { PropertyAttributeDict.Add(key, resultDict); } return(resultDict); } }
private static void ExecuteSetValue <T>(Action <List <string>, dynamic, XmlNode, string> callback, string xmlPath, string xPath, XmlDocument xmlDocument, string[] propertyList = null, ReflectionTypeEnum reflectionType = ReflectionTypeEnum.Expression) where T : class { List <string> filterNameList = null; if (propertyList != null && propertyList.Length > 0) { filterNameList = propertyList.ToList(); } dynamic propertyGetDict = null; if (reflectionType != ReflectionTypeEnum.Original) { propertyGetDict = ReflectionExtendHelper.PropertyGetCallDict <T>(reflectionType); } XmlNode xmlNode = GetNode(xPath, xmlDocument); if (xmlNode == null) { return; } string elementName = ReflectionExtendHelper.GetAttributeValue <XmlTAttribute>(typeof(T), p => p.Name); if (elementName == null) { elementName = typeof(T).Name; } if (callback != null) { callback(filterNameList, propertyGetDict, xmlNode, elementName); } if (!string.IsNullOrEmpty(xPath)) { xmlDocument.Save(xmlPath); } }