How to get the default value of an object property? [duplicate]
问题 This question already has answers here : Programmatic equivalent of default(Type) (13 answers) Closed 6 years ago . Some code: foreach (System.Reflection.PropertyInfo pi in myObject.GetType().GetProperties()) { if (pi.CanWrite) { object value = pi.GetValue(Properties, null); // if (value is not default) // { X.addAttribute(pi.Name, value); // } } } What I'm trying to do is not-call the line 'X.addAttribute...' if the property is at its DefaultValue. I assume there's some way of getting the