1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
|
//
// SyntaxExtensions.cs
//
// Author:
// Mike Krüger <mkrueger@xamarin.com>
//
// Copyright (c) 2014 Xamarin Inc. (http://xamarin.com)
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using Microsoft.CodeAnalysis.CSharp.Simplification;
using Microsoft.CodeAnalysis.CSharp.Symbols;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.CodeAnalysis.CSharp.Utilities;
using Microsoft.CodeAnalysis.Options;
using Microsoft.CodeAnalysis.Rename.ConflictEngine;
using Microsoft.CodeAnalysis.Shared.Extensions;
using Microsoft.CodeAnalysis.Shared.Utilities;
using Microsoft.CodeAnalysis.Simplification;
using Microsoft.CodeAnalysis.Text;
using Roslyn.Utilities;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Extensions;
using System;
using System.Reflection;
using System.Collections.Immutable;
using System.Runtime.ExceptionServices;
using MonoDevelop.Ide.TypeSystem;
namespace ICSharpCode.NRefactory6.CSharp
{
static class SyntaxExtensions
{
readonly static MethodInfo canRemoveParenthesesMethod;
// readonly static MethodInfo isLeftSideOfDotMethod;
// readonly static MethodInfo isRightSideOfDotMethod;
// readonly static MethodInfo getEnclosingNamedTypeMethod;
readonly static MethodInfo getLocalDeclarationMapMethod;
readonly static PropertyInfo localDeclarationMapIndexer;
readonly static MethodInfo getAncestorsMethod;
static SyntaxExtensions()
{
var typeInfo = Type.GetType("Microsoft.CodeAnalysis.CSharp.Extensions.ParenthesizedExpressionSyntaxExtensions" + ReflectionNamespaces.CSWorkspacesAsmName, true);
canRemoveParenthesesMethod = typeInfo.GetMethod("CanRemoveParentheses", new[] { typeof(ParenthesizedExpressionSyntax) });
// typeInfo = Type.GetType("Microsoft.CodeAnalysis.CSharp.Extensions.ExpressionSyntaxExtensions" + ReflectionNamespaces.CSWorkspacesAsmName, true);
// isLeftSideOfDotMethod = typeInfo.GetMethod("IsLeftSideOfDot", new[] { typeof(ExpressionSyntax) });
// isRightSideOfDotMethod = typeInfo.GetMethod("IsRightSideOfDot", new[] { typeof(ExpressionSyntax) });
//
// typeInfo = Type.GetType("Microsoft.CodeAnalysis.Shared.Extensions.SemanticModelExtensions" + ReflectionNamespaces.WorkspacesAsmName, true);
// getEnclosingNamedTypeMethod = typeInfo.GetMethod("GetEnclosingNamedType", new[] { typeof(SemanticModel), typeof(int), typeof(CancellationToken) });
//
typeInfo = Type.GetType("Microsoft.CodeAnalysis.CSharp.Extensions.MemberDeclarationSyntaxExtensions" + ReflectionNamespaces.CSWorkspacesAsmName, true);
getLocalDeclarationMapMethod = typeInfo.GetMethod("GetLocalDeclarationMap", new[] { typeof(MemberDeclarationSyntax) });
typeInfo = Type.GetType("Microsoft.CodeAnalysis.CSharp.Extensions.MemberDeclarationSyntaxExtensions+LocalDeclarationMap" + ReflectionNamespaces.CSWorkspacesAsmName, true);
localDeclarationMapIndexer = typeInfo.GetProperties().Single(p => p.GetIndexParameters().Any());
typeInfo = Type.GetType("Microsoft.CodeAnalysis.Shared.Extensions.SyntaxTokenExtensions" + ReflectionNamespaces.WorkspacesAsmName, true);
getAncestorsMethod = typeInfo.GetMethods().Single(m => m.Name == "GetAncestors" && m.IsGenericMethod && m.GetParameters().Length == 1);
}
/// <summary>
/// Look inside a trivia list for a skipped token that contains the given position.
/// </summary>
private static readonly Func<SyntaxTriviaList, int, SyntaxToken> s_findSkippedTokenBackward =
(l, p) => FindTokenHelper.FindSkippedTokenBackward(GetSkippedTokens(l), p);
/// <summary>
/// return only skipped tokens
/// </summary>
private static IEnumerable<SyntaxToken> GetSkippedTokens(SyntaxTriviaList list)
{
return list.Where(trivia => trivia.RawKind == (int)SyntaxKind.SkippedTokensTrivia)
.SelectMany(t => ((SkippedTokensTriviaSyntax)t.GetStructure()).Tokens);
}
/// <summary>
/// If the position is inside of token, return that token; otherwise, return the token to the left.
/// </summary>
public static SyntaxToken FindTokenOnLeftOfPosition(
this SyntaxNode root,
int position,
bool includeSkipped = true,
bool includeDirectives = false,
bool includeDocumentationComments = false)
{
var skippedTokenFinder = includeSkipped ? s_findSkippedTokenBackward : (Func<SyntaxTriviaList, int, SyntaxToken>)null;
return FindTokenHelper.FindTokenOnLeftOfPosition<CompilationUnitSyntax>(
root, position, skippedTokenFinder, includeSkipped, includeDirectives, includeDocumentationComments);
}
// public static bool IntersectsWith(this SyntaxToken token, int position)
// {
// return token.Span.IntersectsWith(position);
// }
// public static bool IsLeftSideOfDot(this ExpressionSyntax syntax)
// {
// return (bool)isLeftSideOfDotMethod.Invoke(null, new object[] { syntax });
// }
//
// public static bool IsRightSideOfDot(this ExpressionSyntax syntax)
// {
// return (bool)isRightSideOfDotMethod.Invoke(null, new object[] { syntax });
// }
// public static INamedTypeSymbol GetEnclosingNamedType(this SemanticModel semanticModel, int position, CancellationToken cancellationToken)
// {
// return (INamedTypeSymbol)getEnclosingNamedTypeMethod.Invoke(null, new object[] { semanticModel, position, cancellationToken });
// }
//
static ImmutableArray<SyntaxToken> GetLocalDeclarationMap(this MemberDeclarationSyntax member, string localName)
{
try {
object map = getLocalDeclarationMapMethod.Invoke(null, new object[] { member });
return (ImmutableArray<SyntaxToken>)localDeclarationMapIndexer.GetValue(map, new object[] { localName });
} catch (TargetInvocationException ex) {
ExceptionDispatchInfo.Capture(ex.InnerException).Throw();
return ImmutableArray<SyntaxToken>.Empty;
}
}
static IEnumerable<T> GetAncestors<T>(this SyntaxToken token) where T : SyntaxNode
{
try {
return (IEnumerable<T>)getAncestorsMethod.MakeGenericMethod(typeof(T)).Invoke(null, new object[] { token });
} catch (TargetInvocationException ex) {
ExceptionDispatchInfo.Capture(ex.InnerException).Throw();
return null;
}
}
public static ExpressionSyntax SkipParens(this ExpressionSyntax expression)
{
if (expression == null)
return null;
while (expression != null && expression.IsKind(SyntaxKind.ParenthesizedExpression)) {
expression = ((ParenthesizedExpressionSyntax)expression).Expression;
}
return expression;
}
public static SyntaxNode SkipArgument(this SyntaxNode expression)
{
if (expression is ArgumentSyntax)
return ((ArgumentSyntax)expression).Expression;
return expression;
}
public static bool CanRemoveParentheses(this ParenthesizedExpressionSyntax node)
{
try {
return (bool)canRemoveParenthesesMethod.Invoke(null, new object[] { node });
} catch (TargetInvocationException ex) {
ExceptionDispatchInfo.Capture(ex.InnerException).Throw();
return false;
}
}
public static bool IsParentKind(this SyntaxNode node, SyntaxKind kind)
{
return node != null && node.Parent.IsKind(kind);
}
public static bool IsParentKind(this SyntaxToken node, SyntaxKind kind)
{
return node.Parent != null && node.Parent.IsKind(kind);
}
public static bool CanReplaceWithReducedName(
this MemberAccessExpressionSyntax memberAccess,
ExpressionSyntax reducedName,
SemanticModel semanticModel,
CancellationToken cancellationToken)
{
if (!IsThisOrTypeOrNamespace(memberAccess, semanticModel)) {
return false;
}
var speculationAnalyzer = new SpeculationAnalyzer(memberAccess, reducedName, semanticModel, cancellationToken);
if (!speculationAnalyzer.SymbolsForOriginalAndReplacedNodesAreCompatible() ||
speculationAnalyzer.ReplacementChangesSemantics()) {
return false;
}
if (WillConflictWithExistingLocal(memberAccess, reducedName)) {
return false;
}
if (IsMemberAccessADynamicInvocation(memberAccess, semanticModel)) {
return false;
}
if (memberAccess.AccessMethodWithDynamicArgumentInsideStructConstructor(semanticModel)) {
return false;
}
if (memberAccess.Expression.Kind() == SyntaxKind.BaseExpression) {
var enclosingNamedType = semanticModel.GetEnclosingNamedType(memberAccess.SpanStart, cancellationToken);
var symbol = semanticModel.GetSymbolInfo(memberAccess.Name).Symbol;
if (enclosingNamedType != null &&
!enclosingNamedType.IsSealed &&
symbol != null &&
symbol.IsOverridable()) {
return false;
}
}
var invalidTransformation1 = ParserWouldTreatExpressionAsCast(reducedName, memberAccess);
return !invalidTransformation1;
}
internal static bool IsValidSymbolInfo(ISymbol symbol)
{
// name bound to only one symbol is valid
return symbol != null && !symbol.IsErrorType ();
}
private static bool IsThisOrTypeOrNamespace(MemberAccessExpressionSyntax memberAccess, SemanticModel semanticModel)
{
if (memberAccess.Expression.Kind() == SyntaxKind.ThisExpression) {
var previousToken = memberAccess.Expression.GetFirstToken().GetPreviousToken();
var symbol = semanticModel.GetSymbolInfo(memberAccess.Name).Symbol;
if (previousToken.Kind() == SyntaxKind.OpenParenToken &&
previousToken.IsParentKind(SyntaxKind.ParenthesizedExpression) &&
!previousToken.Parent.IsParentKind(SyntaxKind.ParenthesizedExpression) &&
((ParenthesizedExpressionSyntax)previousToken.Parent).Expression.Kind() == SyntaxKind.SimpleMemberAccessExpression &&
symbol != null && symbol.Kind == SymbolKind.Method) {
return false;
}
return true;
}
var expressionInfo = semanticModel.GetSymbolInfo(memberAccess.Expression);
if (IsValidSymbolInfo(expressionInfo.Symbol)) {
if (expressionInfo.Symbol is INamespaceOrTypeSymbol) {
return true;
}
if (expressionInfo.Symbol.IsThisParameter()) {
return true;
}
}
return false;
}
private static bool WillConflictWithExistingLocal(ExpressionSyntax expression, ExpressionSyntax simplifiedNode)
{
if (simplifiedNode.Kind() == SyntaxKind.IdentifierName && !SyntaxFacts.IsInNamespaceOrTypeContext(expression)) {
var identifierName = (IdentifierNameSyntax)simplifiedNode;
var enclosingDeclarationSpace = FindImmediatelyEnclosingLocalVariableDeclarationSpace(expression);
var enclosingMemberDeclaration = expression.FirstAncestorOrSelf<MemberDeclarationSyntax>();
if (enclosingDeclarationSpace != null && enclosingMemberDeclaration != null) {
var locals = enclosingMemberDeclaration.GetLocalDeclarationMap(identifierName.Identifier.ValueText);
foreach (var token in locals) {
if (GetAncestors<SyntaxNode>(token).Contains(enclosingDeclarationSpace)) {
return true;
}
}
}
}
return false;
}
private static SyntaxNode FindImmediatelyEnclosingLocalVariableDeclarationSpace(SyntaxNode syntax)
{
for (var declSpace = syntax; declSpace != null; declSpace = declSpace.Parent) {
switch (declSpace.Kind()) {
// These are declaration-space-defining syntaxes, by the spec:
case SyntaxKind.MethodDeclaration:
case SyntaxKind.IndexerDeclaration:
case SyntaxKind.OperatorDeclaration:
case SyntaxKind.ConstructorDeclaration:
case SyntaxKind.Block:
case SyntaxKind.ParenthesizedLambdaExpression:
case SyntaxKind.SimpleLambdaExpression:
case SyntaxKind.AnonymousMethodExpression:
case SyntaxKind.SwitchStatement:
case SyntaxKind.ForEachKeyword:
case SyntaxKind.ForStatement:
case SyntaxKind.UsingStatement:
// SPEC VIOLATION: We also want to stop walking out if, say, we are in a field
// initializer. Technically according to the wording of the spec it should be
// legal to use a simple name inconsistently inside a field initializer because
// it does not define a local variable declaration space. In practice of course
// we want to check for that. (As the native compiler does as well.)
case SyntaxKind.FieldDeclaration:
return declSpace;
}
}
return null;
}
private static bool ParserWouldTreatExpressionAsCast(ExpressionSyntax reducedNode, MemberAccessExpressionSyntax originalNode)
{
SyntaxNode parent = originalNode;
while (parent != null) {
if (parent.IsParentKind(SyntaxKind.SimpleMemberAccessExpression)) {
parent = parent.Parent;
continue;
}
if (!parent.IsParentKind(SyntaxKind.ParenthesizedExpression)) {
return false;
}
break;
}
var newExpression = parent.ReplaceNode((SyntaxNode)originalNode, reducedNode);
// detect cast ambiguities according to C# spec #7.7.6
if (IsNameOrMemberAccessButNoExpression(newExpression)) {
var nextToken = parent.Parent.GetLastToken().GetNextToken();
return nextToken.Kind() == SyntaxKind.OpenParenToken ||
nextToken.Kind() == SyntaxKind.TildeToken ||
nextToken.Kind() == SyntaxKind.ExclamationToken ||
(SyntaxFacts.IsKeywordKind(nextToken.Kind()) && !(nextToken.Kind() == SyntaxKind.AsKeyword || nextToken.Kind() == SyntaxKind.IsKeyword));
}
return false;
}
private static bool IsMemberAccessADynamicInvocation(MemberAccessExpressionSyntax memberAccess, SemanticModel semanticModel)
{
var ancestorInvocation = memberAccess.FirstAncestorOrSelf<InvocationExpressionSyntax>();
if (ancestorInvocation != null && ancestorInvocation.SpanStart == memberAccess.SpanStart) {
var typeInfo = semanticModel.GetTypeInfo(ancestorInvocation);
if (typeInfo.Type != null &&
typeInfo.Type.Kind == SymbolKind.DynamicType) {
return true;
}
}
return false;
}
private static bool IsNameOrMemberAccessButNoExpression(SyntaxNode node)
{
if (node.IsKind(SyntaxKind.SimpleMemberAccessExpression)) {
var memberAccess = (MemberAccessExpressionSyntax)node;
return memberAccess.Expression.IsKind(SyntaxKind.IdentifierName) ||
IsNameOrMemberAccessButNoExpression(memberAccess.Expression);
}
return node.IsKind(SyntaxKind.IdentifierName);
}
private static bool AccessMethodWithDynamicArgumentInsideStructConstructor(this MemberAccessExpressionSyntax memberAccess, SemanticModel semanticModel)
{
var constructor = memberAccess.Ancestors().OfType<ConstructorDeclarationSyntax>().SingleOrDefault();
if (constructor == null || constructor.Parent.Kind() != SyntaxKind.StructDeclaration) {
return false;
}
return semanticModel.GetSymbolInfo(memberAccess.Name).CandidateReason == CandidateReason.LateBound;
}
public static bool CanReplaceWithReducedName(this NameSyntax name, TypeSyntax reducedName, SemanticModel semanticModel, CancellationToken cancellationToken)
{
var speculationAnalyzer = new SpeculationAnalyzer(name, reducedName, semanticModel, cancellationToken);
if (speculationAnalyzer.ReplacementChangesSemantics())
{
return false;
}
return CanReplaceWithReducedNameInContext(name, reducedName, semanticModel, cancellationToken);
}
private static bool CanReplaceWithReducedNameInContext(this NameSyntax name, TypeSyntax reducedName, SemanticModel semanticModel, CancellationToken cancellationToken)
{
// Special case. if this new minimal name parses out to a predefined type, then we
// have to make sure that we're not in a using alias. That's the one place where the
// language doesn't allow predefined types. You have to use the fully qualified name
// instead.
var invalidTransformation1 = IsNonNameSyntaxInUsingDirective(name, reducedName);
var invalidTransformation2 = WillConflictWithExistingLocal(name, reducedName);
var invalidTransformation3 = IsAmbiguousCast(name, reducedName);
var invalidTransformation4 = IsNullableTypeInPointerExpression(name, reducedName);
var isNotNullableReplacable = name.IsNotNullableReplacable(reducedName);
if (invalidTransformation1 || invalidTransformation2 || invalidTransformation3 || invalidTransformation4
|| isNotNullableReplacable)
{
return false;
}
return true;
}
private static bool IsNullableTypeInPointerExpression(ExpressionSyntax expression, ExpressionSyntax simplifiedNode)
{
// Note: nullable type syntax is not allowed in pointer type syntax
if (simplifiedNode.Kind() == SyntaxKind.NullableType &&
simplifiedNode.DescendantNodes().Any(n => n is PointerTypeSyntax))
{
return true;
}
return false;
}
private static bool IsAmbiguousCast(ExpressionSyntax expression, ExpressionSyntax simplifiedNode)
{
// Can't simplify a type name in a cast expression if it would then cause the cast to be
// parsed differently. For example: (Foo::Bar)+1 is a cast. But if that simplifies to
// (Bar)+1 then that's an arithmetic expression.
if (expression.IsParentKind(SyntaxKind.CastExpression))
{
var castExpression = (CastExpressionSyntax)expression.Parent;
if (castExpression.Type == expression)
{
var newCastExpression = castExpression.ReplaceNode((SyntaxNode)castExpression.Type, simplifiedNode);
var reparsedCastExpression = SyntaxFactory.ParseExpression(newCastExpression.ToString());
if (!reparsedCastExpression.IsKind(SyntaxKind.CastExpression))
{
return true;
}
}
}
return false;
}
private static bool IsNonNameSyntaxInUsingDirective(ExpressionSyntax expression, ExpressionSyntax simplifiedNode)
{
return
expression.IsParentKind(SyntaxKind.UsingDirective) &&
!(simplifiedNode is NameSyntax);
}
private static bool IsNotNullableReplacable(this NameSyntax name, TypeSyntax reducedName)
{
var isNotNullableReplacable = false;
// var isLeftSideOfDot = name.IsLeftSideOfDot();
// var isRightSideOfDot = name.IsRightSideOfDot();
if (reducedName.Kind() == SyntaxKind.NullableType)
{
if (((NullableTypeSyntax)reducedName).ElementType.Kind() == SyntaxKind.OmittedTypeArgument)
{
isNotNullableReplacable = true;
}
else
{
isNotNullableReplacable = name.IsLeftSideOfDot() || name.IsRightSideOfDot();
}
}
return isNotNullableReplacable;
}
public static SyntaxTokenList GetModifiers (this MemberDeclarationSyntax member)
{
if (member == null)
throw new ArgumentNullException("member");
var method = member as BaseMethodDeclarationSyntax;
if (method != null)
return method.Modifiers;
var property = member as BasePropertyDeclarationSyntax;
if (property != null)
return property.Modifiers;
var field = member as BaseFieldDeclarationSyntax;
if (field != null)
return field.Modifiers;
return new SyntaxTokenList ();
}
public static ExplicitInterfaceSpecifierSyntax GetExplicitInterfaceSpecifierSyntax (this MemberDeclarationSyntax member)
{
if (member == null)
throw new ArgumentNullException("member");
var method = member as MethodDeclarationSyntax;
if (method != null)
return method.ExplicitInterfaceSpecifier;
var property = member as BasePropertyDeclarationSyntax;
if (property != null)
return property.ExplicitInterfaceSpecifier;
var evt = member as EventDeclarationSyntax;
if (evt != null)
return evt.ExplicitInterfaceSpecifier;
return null;
}
// public static bool IsKind(this SyntaxToken token, SyntaxKind kind)
// {
// return token.RawKind == (int)kind;
// }
//
// public static bool IsKind(this SyntaxTrivia trivia, SyntaxKind kind)
// {
// return trivia.RawKind == (int)kind;
// }
//
// public static bool IsKind(this SyntaxNode node, SyntaxKind kind)
// {
// return node?.RawKind == (int)kind;
// }
//
// public static bool IsKind(this SyntaxNodeOrToken nodeOrToken, SyntaxKind kind)
// {
// return nodeOrToken.RawKind == (int)kind;
// }
//
// public static SyntaxNode GetParent(this SyntaxNode node)
// {
// return node != null ? node.Parent : null;
// }
}
}
|