资 源 简 介
AutomaticPropertiesDefaultValues
Article_src.zip
PropertyInfo[] props = o.GetType().GetProperties(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static)
for (int i = 0 i < props.Length i++)
{
PropertyInfo prop = props[i]
if (prop.GetCustomAttributes(true).Length > 0)
{
object[] defaultValueAttribute = prop.GetCustomAttributes(typeof(DefaultValueAttribute), true)
if (defaultValueAttribute != null)
{
DefaultValueAttribute dva = defaultValueAttribute[0] as DefaultValueAttribute
if(dva != null)
prop.SetValue(o, dva.Value, null)
}