[IronPython] DefaultParameterValue for keyword arguments

Korbinian Abenthum lists.ironpython.com at ka.weltenschmiede.com
Thu Apr 24 12:33:23 CEST 2008


I have a problem declaring a C# method with Nullable parameters having 
DefaultParameterValue attributes:

public void SomeMethod([DefaultParameterValue(1f)] float f) { } //works
public void SomeMethod([DefaultParameterValue(1f)] float? f) { } //fails
public void SomeMethod([DefaultParameterValue(null)] int? i) { } //fails
public void SomeMethod([DefaultParameterValue((byte?)1)] byte? f) { } //fails

The second and third fail with Compiler Error CS1908: "The type of the 
argument to the DefaultValue attribute must match the parameter type", 
the last one with  CS0182: "An attribute argument must be a constant 
expression, typeof expression or array creation expression of an 
attribute parameter type"

Is that a bug in the compiler that he doesn't recognize "1f" or "null" 
as valid values of "float?", or am I making a mistake?

I realize that it's not exactly OT, but I guess that many IronPython 
users will use DefaultParameterValue attributes to get nice pythonic 
C# methods exposed to IronPython, and maybe one of you has already 
encountered this problem?

Best regards,

More information about the Ironpython-users mailing list