Example #1
0
        private string GetStringValue(IConfigValueConverter converter, object propertyInfoValue, PropertyInfo propertyInfo)
        {
            string strValue;

            if (converter != null)
            {
                strValue = converter.ConvertTo(propertyInfo, propertyInfoValue);
            }
            else
            {
                if (propertyInfoValue == null)
                {
                    strValue = string.Empty;
                }
                else
                {
                    if (propertyInfoValue is string)
                    {
                        strValue = (string)propertyInfoValue;
                    }
                    else
                    {
                        strValue = propertyInfoValue.ToString();
                    }
                }
            }

            return(strValue);
        }
Example #2
0
        private void ReadItem(XElement ele, IConfigValueConverter converter, PropertyInfo propertyInfo, object ownerObj)
        {
            if (!propertyInfo.CanWrite)
            {
                throw new ArgumentException($"属性{propertyInfo.DeclaringType.FullName}.{propertyInfo.Name}不支持set操作");
            }

            object value;
            string valueStr = XmlEx.GetXElementAttributeValue(ele, _VALUE, true);

            if (valueStr == null)
            {
                value = null;
            }
            else
            {
                if (converter != null)
                {
                    value = converter.ConvertFrom(propertyInfo, valueStr);
                }
                else
                {
                    value = this.StringToObject(valueStr, propertyInfo.PropertyType);
                }
            }

            propertyInfo.SetValue(ownerObj, value, null);
        }