以下代码中的 attribute?.Description中那个?是啥意思?
public static string GetDescription(Enum value, Boolean nameInstead = true) {
try {
Type type = value.GetType();
string name = Enum.GetName(type, value);
if (name == null) {
return null;
}
System.Reflection.FieldInfo field = type.GetField(name);
DescriptionAttribute attribute = System.Attribute.GetCustomAttribute(field, typeof(DescriptionAttribute)) as DescriptionAttribute;
if (attribute == null && nameInstead == true) {
return name;
}
return attribute?.Description;
} catch {
return string.Empty;
}
}