C
♪ ParseWord You're talking. enumerator.Current without prior call enumerator.MoveNext - and, strictly speaking, the state enumerator.Current You have no definition of it. I mean. ParseWord Hope's someone in advance, to him, brought him in. enumerator I don't know.As a result of the discussion comments:You see the ISP principle as "several methods for a few." That's not exactly the correct interpretation. The essence of the ISP method in Enumerator-a.There's some kind of class that can do. Move forwardMoveNext)Repeat the current componentCurrent)To predict whether there is another element in sequence (HasNext)There are two categories of code(s) using this object:Clients A - they only need to move forward and read the current element.B-liners need to move forward, read the current element, and know if they can read the next. Thus, principle ISP states that the facility should provide two separate (segregated) interfaces.Interface A, which is provided to clients A - MoveNext + CurrentInterface B, which is provided to clients B - MoveNext + Current + HasNextIt's done to ensure that clients A don't depend on the interface they don't use. Defining the principle:Client should be forced to depend on methods it does not use.For your example, clients A who do not use HasNextshould not depend on the interface in which there is a method HasNext♪So, IEnumerator - it's an interface for category A clients. Standard interface for B clients, no. Accordingly, it is not implemented in standard enumerators.You wrote the B.'s client code client's class that only operates the category A interface. Of course it causes some. inconveniences♪ But this has nothing to do with the ISP violation - the problem is caused by the use of a specific class not by appointment. Any code using IEnumerableshall not make assumptions about the state of sequence. I mean, he should call first. MoveNextand then it's Current. In practice, it means you can't use the same element. Current A few methods - what does IEnumerable in a pure form, not applicable to a sausage.You're gonna have to do a lapse. IEnumerablewhich would clash the outcome of the last challenge MoveNext♪ That's what it's decided, for example. https://github.com/dotnet/roslyn/blob/faddd31a6bfc066861c2c45597dcb14484af49d4/src/Compilers/CSharp/Portable/Parser/Lexer.cs#L406 ♪It uses the rib. https://github.com/dotnet/roslyn/blob/56f605c41915317ccdb925f66974ee52282609e7/src/Compilers/CSharp/Portable/Parser/SlidingTextWindow.cs allowing, if necessary, a reversal:/// Keeps a sliding buffer over the SourceText of a file for the lexer. Also
/// provides the lexer with the ability to keep track of a current "lexeme"
/// by leaving a marker and advancing ahead the offset. The lexer can then
/// decide to "keep" the lexeme by erasing the marker, or abandon the current
/// lexeme by moving the offset back to the marker.
And the first thing that's announced is the end of the file. With a very detailed comment on your problem:/// <summary>
/// In many cases, e.g. PeekChar, we need the ability to indicate that there are
/// no characters left and we have reached the end of the stream, or some other
/// invalid or not present character was asked for. Due to perf concerns, things
/// like nullable or out variables are not viable. Instead we need to choose a
/// char value which can never be legal.
///
/// In .NET, all characters are represented in 16 bits using the UTF-16 encoding.
/// Fortunately for us, there are a variety of different bit patterns which
/// are *not* legal UTF-16 characters. 0xffff (char.MaxValue) is one of these
/// characters -- a legal Unicode code point, but not a legal UTF-16 bit pattern.
/// </summary>
public const char InvalidCharacter = char.MaxValue;
I mean, they've solved the problem problem of ghosts. Current Not known to be incapable + type verifications TextWindow.PeekChar == SlidingTextWindow.InvalidCharacter in the calling code.