-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Description
A user defined literal expression would be defined as a new operator on a class or value type. The literal would be typed without quotes and must end with _TypeName This should help disambiguate it from existing literals.
Only one literal operator can be declared per type and it must return the type in question.
e.g.
public static TypeName operator Suffix(string input)A literal will be considered a constant expression, and as a result will also be allowed as a const and defaulted expression. Since IL will not view it as such, the compiler will emit an attribute when declared as a const or a defaulted parameter containing the string literal and on usage will emit an invoke to the TypeName.op_suffix(string).
Open questions:
How can the compiler not get confused by the literal? Should spaces and operators be disallowed?
(e.g. is 2015-12-31_MyDate is that going to translate to MyDate.op_suffix("2015-12-31") or will that be confused and thought of as 2015 - 12 - MyDate("31")?
The literals might become very unwieldy if generics are in the mix. Should we allow custom names? If so how to handle disambiguation?
While this is cool, what if I'm feeling very jealous of the VB guys and want a constant datetime how would I go about doing that. Will we be allowed to add them to existing types?
void Scheduler(DateTime start,DateTime cutOff= 2015-12-31T23:59:59Z_DateTime)
That could be really nice.