示例#1
0
        private static Dictionary <PropertyInfo, HtmlAttributeMapperItem> GetAttributeMapperDict <T>(object propertyMatchList) where T : class
        {
            Dictionary <string, object> propertyMatchDict = CommonHelper.GetParameterDict(propertyMatchList);
            Dictionary <PropertyInfo, HtmlAttributeMapperItem> propertyDict = new Dictionary <PropertyInfo, HtmlAttributeMapperItem>();

            ReflectionGenericHelper.Foreach <T>((PropertyInfo propertyInfo) =>
            {
                HtmlAttributeMapperItem mapperItem = new HtmlAttributeMapperItem();

                if (propertyMatchDict != null && propertyMatchDict.ContainsKey(propertyInfo.Name))
                {
                    mapperItem.AttributeName = propertyMatchDict[propertyInfo.Name].ToString();
                    mapperItem.AttributeEnum = HtmlAnalysisAttributeEnum.Attribute;
                }
                else
                {
                    HtmlAnalysisTAttribute attribute = propertyInfo.GetCustomAttribute <HtmlAnalysisTAttribute>();
                    if (attribute != null)
                    {
                        mapperItem.AttributeName = attribute.Name;
                        mapperItem.AttributeEnum = attribute.NameType;
                    }
                    else
                    {
                        mapperItem.AttributeName = propertyInfo.Name;
                        mapperItem.AttributeEnum = HtmlAnalysisAttributeEnum.Attribute;
                    }
                }
                propertyDict.Add(propertyInfo, mapperItem);
            });
            return(propertyDict);
        }
示例#2
0
        private static void SetEntityValue <T>(T t, HtmlNode htmlNode, PropertyInfo propertyInfo, HtmlAttributeMapperItem mapperItem, dynamic propertySetDict) where T : class
        {
            string attributeValue = GetNodeText(htmlNode, mapperItem.AttributeName, mapperItem.AttributeEnum);

            if (!string.IsNullOrEmpty(attributeValue))
            {
                if (propertySetDict != null && propertySetDict.ContainsKey(propertyInfo.Name))
                {
                    ReflectionGenericHelper.SetPropertyValue(propertySetDict[propertyInfo.Name], t, attributeValue, propertyInfo);
                }
                else
                {
                    ReflectionHelper.SetPropertyValue(t, attributeValue, propertyInfo);
                }
            }
        }