Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions ICSharpCode.Decompiler.Tests/TestCases/Pretty/QueryExpressions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,20 @@ public static Maybe<T> Where<T>(this Maybe<T> a, Func<T, bool> predicate)

public class QueryExpressions
{
public class MaybeHolder
{
public Maybe<int> Value;

#if CS60
public Maybe<int> this[int index] => default(Maybe<int>);
#endif

public Func<Maybe<int>> Factory()
{
return () => default(Maybe<int>);
}
}

public class HbmParam
{
public string Name { get; set; }
Expand Down Expand Up @@ -217,6 +231,21 @@ private List<string> Issue2545(List<string> arglist)
{
return arglist?.OrderByDescending((string f) => f.Length).ThenBy((string f) => f.ToLower()).ToList();
}

public Maybe<string>? NullConditionalValueTypeQuery(MaybeHolder holder)
{
return holder?.Value.Where((int value) => value > 0).Select((int value) => value.ToString());
}

public Maybe<string>? NullConditionalNestedInvocationQuery(MaybeHolder holder)
{
return holder?.Factory()().Where((int value) => value > 0).Select((int value) => value.ToString());
}

public Maybe<string>? NullConditionalIndexerQuery(MaybeHolder holder)
{
return holder?[0].Where((int value) => value > 0).Select((int value) => value.ToString());
}
#endif

public static IEnumerable<char> Issue1310a(bool test)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -377,10 +377,13 @@ public override AstNode VisitIdentifier(Identifier identifier)
}
}

bool IsNullConditional(Expression target)
{
return target is UnaryOperatorExpression uoe && uoe.Operator == UnaryOperatorType.NullConditional;
}
bool IsNullConditional(Expression target) => target switch {
Comment thread
siegfriedpammer marked this conversation as resolved.
UnaryOperatorExpression { Operator: UnaryOperatorType.NullConditional } => true,
MemberReferenceExpression member => IsNullConditional(member.Target),
InvocationExpression invocation => IsNullConditional(invocation.Target),
IndexerExpression { Target: { } indexerTarget } => IsNullConditional(indexerTarget),
_ => false
};

/// <summary>
/// This fixes #437: Decompilation of query expression loses material parentheses
Expand Down
Loading