This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public override bool Match(ITreeNode element, IMatchingContext context) | |
{ | |
if (element == null) | |
return false; | |
if (element is ICSharpArgument arg) | |
element = arg.Value; | |
if (element is IExpressionInitializer exprInitializer) | |
element = exprInitializer.Value; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var s = x as string; | |
if (s == null) { | |
s = DefaultValue(); | |
} | |
Console.WriteLine(s); | |
// ==> | |
if (!(x is string s)) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
interface ITreeNode { } | |
interface IScope { } | |
class C | |
{ | |
public bool InteriorShouldBeProcessed(ITreeNode element) | |
{ | |
return !(element is IScope) || ScopeShouldBeVisited((IScope) element); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[Pure, ContractAnnotation("null => null")] | |
public static ICSharpTreeNode GetCodeBody([CanBeNull] this ICSharpDeclaration declaration) | |
{ | |
if (declaration == null) return null; | |
var functionDeclaration = declaration as ICSharpFunctionDeclaration; | |
if (functionDeclaration != null && functionDeclaration.Body != null) | |
{ | |
return functionDeclaration.Body; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private void RenderCaseLabel( | |
[NotNull] ICSharpExpression conditionExpression, [NotNull] ISwitchCaseLabel switchCaseLabel, | |
ref FactoryArgumentsBuilder builder, bool expressionIsPartOfDisjunction) | |
{ | |
var guardClause = switchCaseLabel.Guard; | |
var emitParentheses = expressionIsPartOfDisjunction || (guardClause != null && guardClause.Condition != null); | |
if (emitParentheses) builder.Append('('); | |
switch (switchCaseLabel.Pattern) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ITreeNode holdingNode = holder is ICSharpFile ? (ITreeNode) holder : ((ICSharpNamespaceDeclaration) holder).Body; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// good old if-then-throw | |
if (foo == null) | |
throw new ArgumentNullException("foo"); | |
// nameof-flavored if-then-throw | |
if (foo == null) | |
throw new ArgumentNullException(nameof(foo)); | |
// reference equality to avoid operator== overload | |
if (ReferenceEquals(foo, null)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[Pure] | |
private static bool IsNegativeInfinity([NotNull] ICSharpExpression expression) | |
{ | |
var constantValue = expression.ConstantValue.Value; | |
if (constantValue is double) | |
return double.IsNegativeInfinity((double) constantValue); | |
if (constantValue is float) | |
return float.IsNegativeInfinity((float) constantValue); | |
return false; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"System.Collections.Generic": { | |
"IReadOnlyList`2": { | |
"P:Keys": "NotNull", | |
"P:Values": "NotNull", | |
"M:TryGetValue(`0,`1@)": [ | |
"Pure", | |
["ContractAnnotation", "=> true; => false, value: null"], | |
{ "key": "NotNull" } | |
], |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// C# specs paragraph 18.4 | |
if (from is IPointerType && to is IPointerType) | |
{ | |
IType toElementType = ((IPointerType)to).ElementType; | |
return predefinedType.Void.Equals(toElementType) || | |
((IPointerType)from).ElementType.Equals(toElementType); | |
} |