-
Notifications
You must be signed in to change notification settings - Fork 4k
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
Allow ctor's with optional parameters to be used with generic type arguments that contain : new()
qualifier
#4505
Comments
This is a limitation of the CLR. First, the CLR only recognizes the constructor constraint as having no parameters. While the parameters of the type are decorated to be optional they do exist in the signature which makes that constructor not parameterless. Attempting to set Second, optional parameters aren't really optional, they just declare metadata that they have default values and supporting compilers can read those default values from the metadata in order to construct the actual argument values during compile time. The emitted IL to call the constructor actually does push |
@kensykora How do you suggest this be mapped to the CLR? |
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. See also #18002 for a general discussion of closing and/or moving language issues out of this repo. |
When trying to create a type argument that requires an object to have a public parameterless constructor, the compiler should allow types that, if no public parameterless constructor is defined but contain a single constructor that has all optional parameters, allows this type to be used with the constructor with all defaults used.
Example:
The text was updated successfully, but these errors were encountered: