Replies: 20 comments
-
Deconstruction is another. |
Beta Was this translation helpful? Give feedback.
-
@tuespetre Tuple deconstruction is also pattern-based |
Beta Was this translation helpful? Give feedback.
-
Depending on what you consider a "pattern" you could probably include tuples and extension methods. Tuples require that the container type have the name Extension methods require that an attribute |
Beta Was this translation helpful? Give feedback.
-
This is in C# 7.3: https://github.com/dotnet/csharplang/blob/master/proposals/csharp-7.3/pattern-based-fixed.md
I think IDisposable is the odd one out, and there's a proposal on fixing that: #93 Not to mention FormattableString, ReadOnlyAttribute, ParamsAttribute, and such, and possibly caller info attributes. |
Beta Was this translation helpful? Give feedback.
-
Also, separate from |
Beta Was this translation helpful? Give feedback.
-
Collection initializers. |
Beta Was this translation helpful? Give feedback.
-
@ufcpp Are collection index initializers also pattern-based? |
Beta Was this translation helpful? Give feedback.
-
Umm..., indexer initializers can be used on any types which have an indexer. class Program
{
static void Main()
{
var x = new X { [0] = 1, [1] = 2, [2] = 3, };
var y = new Y { [0] = 1, [1] = 2, [2] = 3, };
}
}
class X
{
public int this[int index] { get => 0; set { } }
}
class Y
{
int _dummy;
public ref int this[int index] { get => ref _dummy; }
} but if you regard this as pattern-based, object initializers are also pattern-based? |
Beta Was this translation helpful? Give feedback.
-
True, never mind. |
Beta Was this translation helpful? Give feedback.
-
Thanks for the help everyone! 😄 Great stuff. @HaloFour I don't think I would consider @jnm2 I suppose the best way I can think of to put it now is I am considering 'pattern-based' constructs to be those where the language construct is looking at some type and attempting to resolve some instance or extension member according to a naming/signature convention. |
Beta Was this translation helpful? Give feedback.
-
No, the C# 7.2 features readonly ref and readonly struct. Roslyn actually declares these attribute classes in your code if you aren't referencing a BCL which contains them. See also #935 (I need to update and format the list).
Yes. Quite fair to keep that separate.
Our best guess is that the team will not have time to update the spec from the C# 6 draft for the quite a while. I would suggest the link https://github.com/dotnet/roslyn/blob/master/docs/features/deconstruction.md which the C# version history uses. |
Beta Was this translation helpful? Give feedback.
-
Along with FormattableString, Does |
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
I think that is entirely fair to call 'pattern-based'. One of the most basic and important ones and we recognize it last, huh? 😄 |
Beta Was this translation helpful? Give feedback.
-
Does it count that the syntax |
Beta Was this translation helpful? Give feedback.
-
Maybe, but while suffixing attribute types with |
Beta Was this translation helpful? Give feedback.
-
@Joe4evr I'm familiar with that. The |
Beta Was this translation helpful? Give feedback.
-
@tuespetre Will |
Beta Was this translation helpful? Give feedback.
-
@jnm2 If #1623 does make it into C# 8, |
Beta Was this translation helpful? Give feedback.
-
@tuespetre It's time :) |
Beta Was this translation helpful? Give feedback.
-
I am fascinated with the way some language features are interface-based whereas others are simply pattern-based.
Here is the list I have so far:
Main
(thanks @jnm2 and @yaakov-h)Are there any more than this, and is there some kind of unambiguous term that can be used to refer to this type of construct as a whole (something that 'Googles better than' the term 'c# language pattern'?) Would it be useful in general if there were a section in the spec devoted to listing such constructs (even the interface-based ones) and discussing the merits of pattern-versus-interface-based language constructs?
Beta Was this translation helpful? Give feedback.
All reactions