private static Expression CreateDefaultValueExpression(ParameterInfo parameter)
 {
     if (parameter.HasDefaultValue()) {
         return AstUtils.Constant(parameter.GetDefaultValue(), parameter.ParameterType);
     } else {
         throw new NotSupportedException("missing parameter value not supported");
     }
 }
Exemple #2
0
        public static void CopyParameterAttributes(ParameterInfo from, ParameterBuilder to)
        {
            if (from.IsDefined(typeof(ParamArrayAttribute), false)) {
                to.SetCustomAttribute(new CustomAttributeBuilder(
                    typeof(ParamArrayAttribute).GetConstructor(ReflectionUtils.EmptyTypes), ArrayUtils.EmptyObjects)
                );
            } else if (from.IsDefined(typeof(ParamDictionaryAttribute), false)) {
                to.SetCustomAttribute(new CustomAttributeBuilder(
                    typeof(ParamDictionaryAttribute).GetConstructor(ReflectionUtils.EmptyTypes), ArrayUtils.EmptyObjects)
                );
            }

            if (from.HasDefaultValue()) {
                to.SetConstant(from.GetDefaultValue());
            }
        }