[IronPython] Default-valued arguments to C# functions

Dino Viehland dinov at microsoft.com
Sat Apr 24 03:01:05 CEST 2010

Jeff wrote:
> I've got some functions implemented in C# that need to have optional,
> defaulted parameters. So far I've been declaring them similar to:
>     public object cursor(CodeContext context,
> [Optional][DefaultValue(null)]object factory)
> However, if factory is not specified, instead of being set to null,
> it's a System.Reflection.Missing instance. Removing the DefaultValue
> or changing the order doesn't change the outcome. Is this expected
> behaviour?

I think removing optional should give you the correct behavior - if that
Works then yes it is the expected behavior :).  

I guess we're checking for Optional before DefaultValue and for Optional we 
are matching the reflection behavior of passing Missing.Value.  It also gives
you a way to disambiguate whether the user passed None/null or if they 
didn't provide the parameter.

More information about the Ironpython-users mailing list