Skip to content

Commit 58c2222

Browse files
Initial work on the proposal TypeOf Many.
1 parent a7afeb6 commit 58c2222

File tree

1 file changed

+74
-0
lines changed

1 file changed

+74
-0
lines changed

proposals/proposal-typeof-many.md

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
# TypeOf Many
2+
3+
* [x] Proposed
4+
* [ ] Prototype: [Complete](https://github.com/PROTOTYPE_OWNER/roslyn/BRANCH_NAME)
5+
* [ ] Implementation: [In Progress](https://github.com/dotnet/roslyn/BRANCH_NAME)
6+
* [ ] Specification: [Not Started](pr/1)
7+
8+
## Summary
9+
[summary]: #summary
10+
Extend the capability of `TypeOf obj Is ...` and `TypeOf obj IsNot ...` to check against many types.
11+
12+
## Motivation
13+
[motivation]: #motivation
14+
15+
**What cases does it support?**
16+
17+
This proposal is tightly focused on the two following forms, commonly used to check an object's type against multiple possible types.
18+
```vb.net
19+
dim result0 = (TypeOf obj Is T0) OrElse (TypeOf obj Is T1) OrElse (TypeOf obj Is T2) OrElse (TypeOf obj Is T3)
20+
dim result1 = (TypeOf obj IsNot T0) AndAlso (TypeOf obj IsNot T1) AndAlso (TypeOf obj IsNot T2) AndAlso (TypeOf obj IsNot T3)
21+
```
22+
**With Propose Syntax**
23+
```vb.net
24+
dim result0 = (TypeOf obj Is {T0,T1,T2,T3})
25+
dim result1 = (TypeOf obj IsNot {T0,T1,T2,T3})
26+
```
27+
**What is the expected outcome?**
28+
The proposed syntax is semantically equivalent to writing the previous form.
29+
30+
**Why are we doing this?**
31+
Reduces the visual noise when expressing this intent.
32+
33+
## Detailed design
34+
[design]: #detailed-design
35+
>*This is the bulk of the proposal. Explain the design in enough detail for somebody familiar
36+
with the language to understand, and for somebody familiar with the compiler to implement, and include examples of how the feature is used. This section can start out light before the prototyping phase but should get into specifics and corner-cases as the feature is iteratively designed and implemented.*
37+
38+
The grammar of a `TypeOf` expression is similar to the following BNF implementation
39+
```
40+
TypeOfExpression ::= TypeOfKeyword ws+ Expression TypeOfOperand ws+ Target
41+
TypeOfKeyword ::= "TypeOf"
42+
TypeOfOperand ::= (IsOperand | IsNotOperand )
43+
IsOperand ::= "Is"
44+
IsNotOperand ::= "IsNot"
45+
Target ::= TypeIdentifer
46+
```
47+
The proposal is to extend the rule `Target` to
48+
```
49+
Target ::= TypeIdentifer | TypeArray
50+
```
51+
52+
53+
#### TypeArray *(name may change)*
54+
55+
A `typeArray` is `collection initializer list` consisting only `type identifiers`.
56+
```
57+
TypeArray ::= BraceOpening ws* TypeIdentifer (WS* Comma WS* TypeIdentifer )* ws* Brace_Closing
58+
Brace_Opening ::= '{'
59+
Brace_Closing ::= '}'
60+
Comma ::= ','
61+
```
62+
63+
64+
## Drawbacks
65+
[drawbacks]: #drawbacks
66+
> Why should we *not* do this?
67+
68+
## Alternatives
69+
[alternatives]: #alternatives
70+
> What other designs have been considered? What is the impact of not doing this?
71+
72+
## Unresolved questions
73+
[unresolved]: #unresolved-questions
74+
> What parts of the design are still TBD?

0 commit comments

Comments
 (0)