LDM notes for April 27 2020 #3407
Replies: 10 comments
-
How will validators work with reflection? Namely @jaredpar indicated in #3376 (comment) that he wanted existing reflection based frameworks to work with However if validators are introduced, they will fail to call the validator after setting the initonly properties, possibly creating objects with an invalid state. Is this of concern? |
Beta Was this translation helpful? Give feedback.
-
I brought up a potential solution to this over at runtime: dotnet/runtime#34978 (comment) |
Beta Was this translation helpful? Give feedback.
-
@Joe4evr that works for new code, but existing frameworks won't call it. |
Beta Was this translation helpful? Give feedback.
-
The semantics of validators hasn't been designed yet, only the syntax. Hence the answer to this, and frankly how validators will work in standard C# code are unknown.
It's definitely one aspect that we are considering in this design. How and when validators run is a non-trivial design even for non-reflection code. Consider for example how the proposals around |
Beta Was this translation helpful? Give feedback.
-
Is there a proposal for validators somewhere? Also, have you guys yet discussed the proposed |
Beta Was this translation helpful? Give feedback.
-
I suppose user constructors are also able to call each other via
I think accessibility modifiers for none of these would make sense. The primary constructor is effectively as accessible as the type itself and the validator can't be referenced. That said, I don't think we need to invent completetly alien syntax here, we already use class TypeName(int X, int Y) {
public TypeName() {} // instance constructor
static TypeName() {} // static constructor
new TypeName() {} // primary constructor body
init TypeName() {} // final initializer aka validator
} |
Beta Was this translation helpful? Give feedback.
-
Scala allows private primary constructors. They're useful for static factory methods. |
Beta Was this translation helpful? Give feedback.
-
No. This feature is very much in the stage of rough idea with a rough outline of the problems it could solve. It's not to the point where we have a doc detailing how it works across the scenarios that we generally care about. Expectation is that we will be producing such a doc in the next month or two as we get into this part of records. |
Beta Was this translation helpful? Give feedback.
-
C# have a tradition of using Now primary constructor and validator will change this... I don't know. PS: what's the value of |
Beta Was this translation helpful? Give feedback.
-
@qrli that visual clue is already less reliable that you might think:
I believe the syntax This is a technique I use regularly when creating interceptible types, especially ones implementing standard interfaces. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
https://github.com/dotnet/csharplang/blob/master/meetings/2020/LDM-2020-04-27.md
Records: positional & primary constructors
Beta Was this translation helpful? Give feedback.
All reactions