Skip to content
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

Should property patterns be capable of referencing an indexed property? #10600

Closed
gafter opened this issue Apr 15, 2016 · 4 comments
Closed

Should property patterns be capable of referencing an indexed property? #10600

gafter opened this issue Apr 15, 2016 · 4 comments

Comments

@gafter
Copy link
Member

gafter commented Apr 15, 2016

If we want property patterns to be capable of referencing an indexed property, we will need to extend the bound nodes that represent them. Similarly for dynamic indexers and events. See also #9515.

@AdamSpeight2008
Copy link
Contributor

What would (if any) be on the index?

  • Constants P { X[ 0 ] is var x }
  • Reference P { X[ index ] is var x }
  • What about the checking of the index bounds? Index <0 || Index >= X.Length
  • (VB) Is the dictionary lookup operator also allowed? P { X!foo is var x }

@gafter
Copy link
Member Author

gafter commented Apr 15, 2016

@AdamSpeight2008

If we do it, certainly constant indices would be allowed. However, given that indexed properties are not supported in a first-class way in C#, it seems unlikely we would do it.

We would not support VB operators in C#.

@AdamSpeight2008
Copy link
Contributor

My comment was more about, what would be allowed should pattern-matching be brought into VB

@alrz
Copy link
Member

alrz commented Apr 17, 2016

If we had support for indexer itself P { [0] is var x } then indexed properties can be matched with:

obj is P { X is T { [0] is var x } }

As long as it's analogous with indexer initializers, the following also makes sense,

obj is P { [0][1] is var x }

In addition to obj is P { X[0] is var x }, I think this on would be also helpful:

obj is P { Prop1.Prop2 is var x }
// instead of
obj is P { Prop1 is { Prop2 is var x } }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants