Imported Upstream version 3.6.0

Former-commit-id: da6be194a6b1221998fc28233f2503bd61dd9d14
This commit is contained in:
Jo Shields
2014-08-13 10:39:27 +01:00
commit a575963da9
50588 changed files with 8155799 additions and 0 deletions

View File

@ -0,0 +1,30 @@
namespace System.Web.Mvc {
using System;
using System.ComponentModel;
using System.Reflection;
internal static class ParameterInfoUtil {
public static bool TryGetDefaultValue(ParameterInfo parameterInfo, out object value) {
// this will get the default value as seen by the VB / C# compilers
// if no value was baked in, RawDefaultValue returns DBNull.Value
object defaultValue = parameterInfo.DefaultValue;
if (defaultValue != DBNull.Value) {
value = defaultValue;
return true;
}
// if the compiler did not bake in a default value, check the [DefaultValue] attribute
DefaultValueAttribute[] attrs = (DefaultValueAttribute[])parameterInfo.GetCustomAttributes(typeof(DefaultValueAttribute), false);
if (attrs == null || attrs.Length == 0) {
value = default(object);
return false;
}
else {
value = attrs[0].Value;
return true;
}
}
}
}