ljw1004 / csharpspec Goto Github PK
View Code? Open in Web Editor NEWC# language specification
License: Other
C# language specification
License: Other
The way the specification defines object initializers is incorrect. Specifically, it lowers all initializers into property sets, when this is not always accurate. Fundamentally, object initializers should initialize. The fact that sometimes this may involve assignment should be an implementation detail. The main area where this distinction produces surprising behaviour is in the case of readonly fields. Consider the following program:
using System;
public class Test
{
public readonly int num;
}
public class Program
{
public static void Main()
{
var test = new Test { num = 1 };
}
}
This produces the error that you can't assign to the field outside a variable initializer or constructor because it's readonly, despite the fact that the assignment clearly occurs inside an initializer.
The main issue I see with fixing this is interaction with legacy code, e.g. if Test had a meaningful default constructor that set the field. Previously this would have been a fixed value but now callers of Test can mutate it.
Therefore I'd suggest that, strictly in the case where the class declaring the property or field has no user-defined default constructor, and the object initializer does not call a custom constructor, and if a property the property has no user-defined setter, and the field or property is accessible for reading, then the assignment should be permitted.
method.The
should be method. The
object
and dynamic
should be in backtickstraining
should be trailing
(2 times)arguments.The
should be arguments. The
criteria.The
should be criteria. The
0 <= *c* < 2^96
should be 0 <= c < 2^96
The word "training" should be replaced with "trailing".
Do you intend on adding them to the spec (and maybe other modifications relevant to the script language kind)? Thanks
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.