|
16 | 16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
17 | 17 | // DEALINGS IN THE SOFTWARE. |
18 | 18 |
|
19 | | -using System; |
20 | 19 | using System.Collections.Generic; |
21 | 20 | using System.Linq; |
22 | 21 |
|
23 | 22 | using ICSharpCode.Decompiler.CSharp.Syntax; |
24 | 23 | using ICSharpCode.Decompiler.CSharp.Syntax.PatternMatching; |
| 24 | +using ICSharpCode.Decompiler.Util; |
25 | 25 |
|
26 | 26 | namespace ICSharpCode.Decompiler.CSharp.Transforms |
27 | 27 | { |
@@ -54,12 +54,10 @@ void CombineQueries(AstNode node, Dictionary<string, object> fromOrLetIdentifier |
54 | 54 | next = child.NextSibling; |
55 | 55 | CombineQueries(child, fromOrLetIdentifiers); |
56 | 56 | } |
57 | | - QueryExpression query = node as QueryExpression; |
58 | | - if (query != null) |
| 57 | + if (node is QueryExpression query) |
59 | 58 | { |
60 | 59 | QueryFromClause fromClause = (QueryFromClause)query.Clauses.First(); |
61 | | - QueryExpression innerQuery = fromClause.Expression as QueryExpression; |
62 | | - if (innerQuery != null) |
| 60 | + if (fromClause.Expression is QueryExpression innerQuery) |
63 | 61 | { |
64 | 62 | if (TryRemoveTransparentIdentifier(query, fromClause, innerQuery, fromOrLetIdentifiers)) |
65 | 63 | { |
@@ -165,21 +163,17 @@ void RemoveTransparentIdentifierReferences(AstNode node, Dictionary<string, obje |
165 | 163 | { |
166 | 164 | RemoveTransparentIdentifierReferences(child, fromOrLetIdentifiers); |
167 | 165 | } |
168 | | - MemberReferenceExpression mre = node as MemberReferenceExpression; |
169 | | - if (mre != null) |
| 166 | + if (node is MemberReferenceExpression mre && mre.Target is IdentifierExpression ident |
| 167 | + && CSharpDecompiler.IsTransparentIdentifier(ident.Identifier)) |
170 | 168 | { |
171 | | - IdentifierExpression ident = mre.Target as IdentifierExpression; |
172 | | - if (ident != null && CSharpDecompiler.IsTransparentIdentifier(ident.Identifier)) |
173 | | - { |
174 | | - IdentifierExpression newIdent = new IdentifierExpression(mre.MemberName); |
175 | | - mre.TypeArguments.MoveTo(newIdent.TypeArguments); |
176 | | - newIdent.CopyAnnotationsFrom(mre); |
177 | | - newIdent.RemoveAnnotations<Semantics.MemberResolveResult>(); // remove the reference to the property of the anonymous type |
178 | | - if (fromOrLetIdentifiers.TryGetValue(mre.MemberName, out var annotation)) |
179 | | - newIdent.AddAnnotation(annotation); |
180 | | - mre.ReplaceWith(newIdent); |
181 | | - return; |
182 | | - } |
| 169 | + IdentifierExpression newIdent = new IdentifierExpression(mre.MemberName); |
| 170 | + mre.TypeArguments.MoveTo(newIdent.TypeArguments); |
| 171 | + newIdent.CopyAnnotationsFrom(mre); |
| 172 | + newIdent.RemoveAnnotations<Semantics.MemberResolveResult>(); // remove the reference to the property of the anonymous type |
| 173 | + if (fromOrLetIdentifiers.TryGetValue(mre.MemberName, out var annotation)) |
| 174 | + newIdent.AddAnnotation(annotation); |
| 175 | + mre.ReplaceWith(newIdent); |
| 176 | + return; |
183 | 177 | } |
184 | 178 | } |
185 | 179 | } |
|
0 commit comments