Skip to content

Allows multiple types #6352

Aug 7, 2022 · 9 comments · 10 replies
Discussion options

You must be logged in to vote

One approach without runtime support but with strong typing is creating multiple parameters - one for each requested type, in metadata/IL, with special attributes. Then the language can interpret it and "make it look" like it's an intersection type:

void Foo(IDog & ICat dogCat)
{
  dogCat.Bark();
  dogCat.Meow();
}
var dogCat = new DogCat();
Foo(dogCat);
// becomes:
void Foo([IntersectsWith(nameof(dogCatCat))] IDog dogCatDog, [IntersectsWith(nameof(dogCatDog))] ICat dogCatCat)
{
  dogCatDog.Bark();
  dogCatCat.Meow();
}
var dogCat = new DogCat();
Foo(dogCat, dogCat);

Same idea for locals and fields.
Things like get-properties and method return values are not possible this way, though. To …

Replies: 9 comments 10 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
2 replies
@HaloFour
Comment options

@Aloento
Comment options

Comment options

You must be logged in to vote
1 reply
@Aloento
Comment options

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by Aloento

This comment was marked as off-topic.

@saint4eva
Comment options

This comment was marked as off-topic.

Comment options

You must be logged in to vote
5 replies
@DavidArno

This comment was marked as off-topic.

@DavidArno

This comment was marked as off-topic.

@DavidArno

This comment was marked as off-topic.

@CyrusNajmabadi
Comment options

@DavidArno

This comment was marked as off-topic.

Comment options

You must be logged in to vote
1 reply
@TahirAhmadov
Comment options

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