1 namespace System.Web.Mvc {
3 using System.ComponentModel;
4 using System.Reflection;
6 internal static class ParameterInfoUtil {
8 public static bool TryGetDefaultValue(ParameterInfo parameterInfo, out object value) {
9 // this will get the default value as seen by the VB / C# compilers
10 // if no value was baked in, RawDefaultValue returns DBNull.Value
11 object defaultValue = parameterInfo.DefaultValue;
12 if (defaultValue != DBNull.Value) {
17 // if the compiler did not bake in a default value, check the [DefaultValue] attribute
18 DefaultValueAttribute[] attrs = (DefaultValueAttribute[])parameterInfo.GetCustomAttributes(typeof(DefaultValueAttribute), false);
19 if (attrs == null || attrs.Length == 0) {
20 value = default(object);
24 value = attrs[0].Value;