C
cody
If I understand it correctly Microsoft implemented them by just filling
in the missing parameters as fixed values in the call site at compile time.
public class TextBoxInfo
{
public TextBoxInfo(
string text = "",
float size = 10.0f,
float width = 50.0f)
{
..
}
}
Currently a call to new TextBoxInfo(size: 35f) is compiled to:
new TextBoxInfo("", 35f, 50f)
So if the default value of a parameter is changed, the clients has be be
recompiled, otherwise we have a discrepancy here.
Wasn't this exactly the reason why they didn't include optional
parameters in the first place, because they couldn't solve this problem?
Why doesn't the compiler do it this way:
It should insert in the class where the method is defined 'unspeakable'
(that is you cannot use them in code directly by yourself) static
readonly fields which are containing the default values for the optional
parameters so the call will be converted to something like that:
new TextBoxInfo(TextBoxInfo.defaultvalue$ctor$text, 35f,
TextBoxInfo.default$width)
There should not be so much impact to performance, the code should
instead by smaller because you not only have references to the values
not the values itself hardcoded in the call.
What do you think about it?
in the missing parameters as fixed values in the call site at compile time.
public class TextBoxInfo
{
public TextBoxInfo(
string text = "",
float size = 10.0f,
float width = 50.0f)
{
..
}
}
Currently a call to new TextBoxInfo(size: 35f) is compiled to:
new TextBoxInfo("", 35f, 50f)
So if the default value of a parameter is changed, the clients has be be
recompiled, otherwise we have a discrepancy here.
Wasn't this exactly the reason why they didn't include optional
parameters in the first place, because they couldn't solve this problem?
Why doesn't the compiler do it this way:
It should insert in the class where the method is defined 'unspeakable'
(that is you cannot use them in code directly by yourself) static
readonly fields which are containing the default values for the optional
parameters so the call will be converted to something like that:
new TextBoxInfo(TextBoxInfo.defaultvalue$ctor$text, 35f,
TextBoxInfo.default$width)
There should not be so much impact to performance, the code should
instead by smaller because you not only have references to the values
not the values itself hardcoded in the call.
What do you think about it?