Skip to content

Instantly share code, notes, and snippets.

View controlflow's full-sized avatar

Alexander Shvedov controlflow

View GitHub Profile
var unaryExpression = selector.Body as UnaryExpression;
var binaryExpression = unaryExpression == null ? null : unaryExpression.Operand as BinaryExpression;
// vs.
var unaryExpression = selector.Body as UnaryExpression;
var binaryExpression = unaryExpression?.Operand as BinaryExpression;
// vs.
private static BodyKind InspectStatement([CanBeNull] ICSharpStatement statement) {
var ifStatement = statement as IIfStatement;
if (ifStatement != null) {
var thenResult = InspectStatement(ifStatement.Then);
if (thenResult == BodyKind.HasBreakOrGotoCase) return thenResult;
var elseResult = InspectStatement(ifStatement.Else);
if (elseResult == BodyKind.HasBreakOrGotoCase) return elseResult;
if (thenResult == BodyKind.ReturnAtEnd && elseResult == BodyKind.ReturnAtEnd)
var orExpression = condition as IConditionalOrExpression;
if (orExpression != null)
{
return ToSimpleConditions(leftOperand) && ToSimpleConditions(rightOperand);
}
var andExpression = condition as IConditionalAndExpression;
if (andExpression == null || myCSharpLanguageLevel < CSharpLanguageLevel.CSharp60)
return false;
public void Run(ITreeNode element, ElementProblemAnalyzerData data, IHighlightingConsumer consumer)
{
var warningDirective = element as IWarningDirective;
if (warningDirective != null)
{
var messageToken = "#warning directive";
var tokenNode = warningDirective.Message;
if (tokenNode != null) messageToken = tokenNode.GetText();
while (GetSomethingToUseTwice() is var x
&& x != null
&& UseOnceMore(x)
&& AndMore(x))
{
// ...
}
// C#'s 'is var t' var pattern to introduce a name for expression where statements are not allowed
// is somewhat similar to 'let-in' from functional languages:
while (ReferenceNameNavigator.GetByQualifier(referenceName) != null)
referenceName = ReferenceNameNavigator.GetByQualifier(referenceName);
/*
What is this? (int x, int y)
*/
(int x, int y) => x + y;
int M(int x, int y) => x + y;
(int x, int y) = (1, 2);
foreach ((int x, int y) in xs) { }
int M((int x, int y) t) => t.x + t.y;
foreach (var pair in myNotClosedTags)
{
consumer.AddHighlighting(new XmlTagIsNotClosedHighlighting2(pair.Value, pair.Key), pair.Key);
}
var typeCheckClassification = typeCheckType.ClassifyTypeAdvanced();
if (typeCheckClassification == TypeParameterOracle.Classification.REFERENCE_TYPE && sourceType.IsValueType())
return TypeCheckStaticAnalysisResult.AlwaysFalse;
if (typeCheckClassification == TypeParameterOracle.Classification.NON_NULLABLE_VALUE_TYPE && sourceType.IsReferenceType())
return TypeCheckStaticAnalysisResult.AlwaysFalse;
[Pure]
private static bool IsFullyDiscardedDeconstructionExpression([NotNull] ITupleCreationExpression tupleCreationExpression)
{
foreach (var tupleArgument in tupleCreationExpression.ArgumentsEnumerable)
{
if (tupleArgument.NameIdentifier != null) return false;
if (tupleArgument.Colon != null) return false;
var tupleArgumentValue = tupleArgument.Value;