Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optional Parameter without static constant - allow static properties #3914

Closed
furesoft opened this issue Jul 12, 2015 · 3 comments
Closed

Optional Parameter without static constant - allow static properties #3914

furesoft opened this issue Jul 12, 2015 · 3 comments

Comments

@furesoft
Copy link

make an optional parameter without having a constand but like this:

public void Draw(Color c = Color.White) {

}

@HaloFour
Copy link

That is effectively a limitation inherited by the CLR. The default value must be encoded into the metadata of the parameter at compile time and available to allow any compiler to use that value in place of omitted arguments at the call site. There is no way to encode an expression that would be understood by the CLR or universally understood by CLR languages.

The argument could be made that for private or internal methods that the C# compiler could relax that restriction since the optional parameter metadata would never be a part of the public surface of the assembly. In those cases the compiler could contain a dictionary of the expressions and then replace the omitted arguments.

@dsaf
Copy link

dsaf commented Jul 13, 2015

Something similar is already requested (in a way): #263 (closed, but could be re-opened if requirements are met), #2401.

Is it mostly about user-defined types or constants in general?

PS: please spend a 5 minutes to format the question better.

@gafter
Copy link
Member

gafter commented Mar 20, 2017

We are now taking language feature discussion on https://github.com/dotnet/csharplang for C# specific issues, https://github.com/dotnet/vblang for VB-specific features, and https://github.com/dotnet/csharplang for features that affect both languages.

Part of the proposal dotnet/csharplang#39 would address the use case for this issue.

@gafter gafter closed this as completed Mar 20, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants