Skip to content

Commit

Permalink
!= null -> is not null, == null -> is null
Browse files Browse the repository at this point in the history
  • Loading branch information
WhiteBlackGoose authored and colombod committed Apr 16, 2021
1 parent e96dccb commit 4c03a63
Show file tree
Hide file tree
Showing 111 changed files with 290 additions and 290 deletions.
10 changes: 5 additions & 5 deletions src/Microsoft.DotNet.Interactive.CSharp/CSharpKernel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ public async Task HandleAsync(RequestHoverText command, KernelInvocationContext
var service = QuickInfoService.GetService(document);
var info = await service.GetQuickInfoAsync(document, cursorPosition, context.CancellationToken);

if (info == null)
if (info is null)
{
return;
}
Expand Down Expand Up @@ -283,13 +283,13 @@ await RunAsync(
}

// Report the compilation failure or exception
if (exception != null)
if (exception is not null)
{
context.Fail(exception, message);
}
else
{
if (ScriptState != null && HasReturnValue)
if (ScriptState is not null && HasReturnValue)
{
var formattedValues = FormattedValue.FromObject(ScriptState.ReturnValue);
context.Publish(
Expand Down Expand Up @@ -320,7 +320,7 @@ private async Task RunAsync(
_currentDirectory));
}

if (ScriptState == null)
if (ScriptState is null)
{
ScriptState = await CSharpScript.RunAsync(
code,
Expand Down Expand Up @@ -429,7 +429,7 @@ await _extensionLoader.LoadFromDirectoryAsync(
public PackageRestoreContext PackageRestoreContext => _packageRestoreContext.Value;

private bool HasReturnValue =>
ScriptState != null &&
ScriptState is not null &&
(bool)_hasReturnValueMethod.Invoke(ScriptState.Script, null);

void ISupportNuget.AddRestoreSource(string source) => _packageRestoreContext.Value.AddRestoreSource(source);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ private Solution CreateProjectAndAddToSolution(

solution = solution.AddProject(projectInfo);

if (projectReferenceProjectId != null)
if (projectReferenceProjectId is not null)
{
solution = solution.AddProjectReference(
projectId,
Expand Down Expand Up @@ -211,7 +211,7 @@ private ProjectId AddProjectWithPreviousSubmissionToSolution(Compilation compila
#if DEBUG
debugName += $": {code}";
#endif
if (projectId == null)
if (projectId is null)
{
projectId = ProjectId.CreateNewId(debugName: debugName);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ internal static class CheckForStaticExtension
public static bool IsInStaticContext(this SyntaxNode node)
{
// this/base calls are always static.
if (node.FirstAncestorOrSelf<ConstructorInitializerSyntax>() != null)
if (node.FirstAncestorOrSelf<ConstructorInitializerSyntax>() is not null)
{
return true;
}

var memberDeclaration = node.FirstAncestorOrSelf<MemberDeclarationSyntax>();
if (memberDeclaration == null)
if (memberDeclaration is null)
{
return false;
}
Expand All @@ -49,7 +49,7 @@ public static bool IsInStaticContext(this SyntaxNode node)
}

// Global statements are not a static context.
if (node.FirstAncestorOrSelf<GlobalStatementSyntax>() != null)
if (node.FirstAncestorOrSelf<GlobalStatementSyntax>() is not null)
{
return false;
}
Expand All @@ -60,7 +60,7 @@ public static bool IsInStaticContext(this SyntaxNode node)

public static SyntaxTokenList GetModifiers(SyntaxNode member)
{
if (member != null)
if (member is not null)
{
switch (member.Kind())
{
Expand Down Expand Up @@ -107,7 +107,7 @@ public static bool IsFoundUnder<TParent>(this SyntaxNode node, Func<TParent, Syn
where TParent : SyntaxNode
{
var ancestor = node.GetAncestor<TParent>();
if (ancestor == null)
if (ancestor is null)
{
return false;
}
Expand All @@ -122,7 +122,7 @@ public static TNode GetAncestor<TNode>(this SyntaxNode node)
where TNode : SyntaxNode
{
var current = node.Parent;
while (current != null)
while (current is not null)
{
if (current is TNode tNode)
{
Expand All @@ -144,7 +144,7 @@ public static IEnumerable<TNode> GetAncestorsOrThis<TNode>(this SyntaxNode node)
where TNode : SyntaxNode
{
var current = node;
while (current != null)
while (current is not null)
{
if (current is TNode tNode)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ private static string TrimMultiLineString(string input, string lineEnding)

private static string GetCref(string cref)
{
if (cref == null || cref.Trim().Length == 0)
if (cref is null || cref.Trim().Length == 0)
{
return "";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@ public static async Task<SignatureHelpProduced> GenerateSignatureInformation(Doc
var throughExpression = ((MemberAccessExpressionSyntax)invocation.Receiver).Expression;
var throughSymbol = invocation.SemanticModel.GetSpeculativeSymbolInfo(invocation.Position, throughExpression, SpeculativeBindingOption.BindAsExpression).Symbol;
ISymbol throughType = invocation.SemanticModel.GetSpeculativeTypeInfo(invocation.Position, throughExpression, SpeculativeBindingOption.BindAsTypeOrNamespace).Type;
var includeInstance = (throughSymbol != null && !(throughSymbol is ITypeSymbol)) ||
var includeInstance = (throughSymbol is not null && !(throughSymbol is ITypeSymbol)) ||
throughExpression is LiteralExpressionSyntax ||
throughExpression is TypeOfExpressionSyntax;
var includeStatic = (throughSymbol is INamedTypeSymbol) || throughType != null;
var includeStatic = (throughSymbol is INamedTypeSymbol) || throughType is not null;
methodGroup = methodGroup.Where(m => (m.IsStatic && includeStatic) || (!m.IsStatic && includeInstance));
}
else if (invocation.Receiver is SimpleNameSyntax && invocation.IsInStaticContext)
Expand Down Expand Up @@ -90,7 +90,7 @@ private static async Task<InvocationContext> GetInvocation(Document document, Li
var node = root.FindToken(position).Parent;

// Walk up until we find a node that we're interested in.
while (node != null)
while (node is not null)
{
if (node is InvocationExpressionSyntax invocation && invocation.ArgumentList.Span.Contains(position))
{
Expand Down Expand Up @@ -129,7 +129,7 @@ private static int InvocationScore(IMethodSymbol symbol, IEnumerable<CodeAnalysi
var definitionEnum = parameters.GetEnumerator();
while (invocationEnum.MoveNext() && definitionEnum.MoveNext())
{
if (invocationEnum.Current.ConvertedType == null)
if (invocationEnum.Current.ConvertedType is null)
{
// 1 point for having a parameter
score += 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ private void DisassembleAndWriteMembers(JitWriteContext context, TypeInfo type,

private bool TryDisassembleAndWriteMembersOfGeneric(JitWriteContext context, TypeInfo type, ImmutableArray<Type>? parentArgumentTypes = null)
{
if (parentArgumentTypes != null)
if (parentArgumentTypes is not null)
{
var genericInstance = type.MakeGenericType(parentArgumentTypes.Value.ToArray());
DisassembleAndWriteMembers(context, genericInstance.GetTypeInfo(), parentArgumentTypes);
Expand Down Expand Up @@ -182,22 +182,22 @@ private void DisassembleAndWriteSimpleMethod(JitWriteContext context, MethodBase
var clrMethod = context.Runtime.GetMethodByHandle((ulong)handle.Value.ToInt64());
var regions = FindNonEmptyHotColdInfo(clrMethod);

if (clrMethod == null || regions == null)
if (clrMethod is null || regions is null)
{
context.Runtime.Flush();
clrMethod = context.Runtime.GetMethodByHandle((ulong)handle.Value.ToInt64());
regions = FindNonEmptyHotColdInfo(clrMethod);
}

if (clrMethod == null || regions == null)
if (clrMethod is null || regions is null)
{
var address = (ulong)handle.GetFunctionPointer().ToInt64();
clrMethod = context.Runtime.GetMethodByAddress(address);
regions = FindNonEmptyHotColdInfo(clrMethod);
}

var writer = context.Writer;
if (clrMethod != null)
if (clrMethod is not null)
{
writer.WriteLine();
writer.WriteLine(clrMethod.GetFullSignature());
Expand All @@ -207,7 +207,7 @@ private void DisassembleAndWriteSimpleMethod(JitWriteContext context, MethodBase
WriteSignatureFromReflection(context, method);
}

if (regions == null)
if (regions is null)
{
if (method.IsGenericMethod || (method.DeclaringType?.IsGenericType ?? false))
{
Expand Down Expand Up @@ -264,7 +264,7 @@ private static void WriteSignatureFromReflection(JitWriteContext context, Method

private HotColdRegions FindNonEmptyHotColdInfo(ClrMethod method)
{
if (method == null)
if (method is null)
return null;

// I can't really explain this, but it seems that some methods
Expand All @@ -273,7 +273,7 @@ private HotColdRegions FindNonEmptyHotColdInfo(ClrMethod method)
if (method.HotColdInfo.HotSize > 0)
return method.HotColdInfo;

if (method.Type == null)
if (method.Type is null)
return null;

var methodSignature = method.GetFullSignature();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public bool TryGetSymbol(in Instruction instruction, int operand, int instructio
}

var method = _runtime.GetMethodByAddress(address);
if (method == null)
if (method is null)
{
symbol = default;
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ private static void AppendJsCode(this StringBuilder stringBuilder,
libraryVersion ??= "1.0.0";
stringBuilder.AppendLine($@"
let {functionName} = () => {{");
if (libraryUri != null)
if (libraryUri is not null)
{
var libraryAbsoluteUri = libraryUri.AbsoluteUri.Replace(".js", string.Empty);
cacheBuster ??= libraryAbsoluteUri.GetHashCode().ToString("0");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ private static void AppendWidgetCode(StringBuilder stringBuilder, TabularDataRes
libraryVersion ??= "1.0.0";
stringBuilder.AppendLine($@"
let {functionName} = () => {{");
if (libraryUri != null)
if (libraryUri is not null)
{
var libraryAbsoluteUri = libraryUri.AbsoluteUri.Replace(".js", string.Empty);
cacheBuster ??= libraryAbsoluteUri.GetHashCode().ToString("0");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ private static void AppendWidgetCode(StringBuilder stringBuilder, TabularDataRes
libraryVersion ??= "1.0.0";
stringBuilder.AppendLine($@"
let {functionName} = () => {{");
if (libraryUri != null)
if (libraryUri is not null)
{
var libraryAbsoluteUri = libraryUri.AbsoluteUri.Replace(".js", string.Empty);
cacheBuster ??= libraryAbsoluteUri.GetHashCode().ToString("0");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ internal class DefaultHtmlFormatterSet

// This is approximate
var isKnownDocType =
type.Namespace != null &&
type.Namespace is not null &&
(type.Namespace == "System" ||
type.Namespace.StartsWith("System.") ||
type.Namespace.StartsWith("Microsoft."));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ private static void InitializeCache()

public static IDestructurer GetOrCreate(Type type)
{
if (type == null)
if (type is null)
{
return NonDestructurer.Instance;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@ public Destructurer()

private static void EnsureInitialized()
{
if (getters != null)
if (getters is not null)
{
return;
}

lock (lockObj)
{
// while the double-checked lock is not 100% reliable, multiple initialization is safe in this case. the static setters are not modified (per T) after initialization, so this is a performance optimization to avoid taking locks during read operations.
if (getters != null)
if (getters is not null)
{
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public static IDictionary<TKey, TValue> Merge<TKey, TValue>(
IEqualityComparer<TKey> comparer = null)
{
IDictionary<TKey, TValue> result;
if (comparer == null)
if (comparer is null)
{
result = new Dictionary<TKey, TValue>();
}
Expand Down
12 changes: 6 additions & 6 deletions src/Microsoft.DotNet.Interactive.Formatting/Formatter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ internal static void ClearComputedState()

public static void SetPreferredMimeTypeFor(Type type, string preferredMimeType)
{
if (type == null)
if (type is null)
{
throw new ArgumentNullException(nameof(type));
}
Expand Down Expand Up @@ -222,7 +222,7 @@ public static string ToDisplayString(
this object obj,
string mimeType = PlainTextFormatter.MimeType)
{
if (mimeType == null)
if (mimeType is null)
{
throw new ArgumentNullException(nameof(mimeType));
}
Expand All @@ -237,7 +237,7 @@ public static string ToDisplayString(
this object obj,
ITypeFormatter formatter)
{
if (formatter == null)
if (formatter is null)
{
throw new ArgumentNullException(nameof(formatter));
}
Expand All @@ -263,7 +263,7 @@ public static void FormatTo<T>(
TextWriter writer,
string mimeType = PlainTextFormatter.MimeType)
{
if (obj != null)
if (obj is not null)
{
var actualType = obj.GetType();

Expand Down Expand Up @@ -324,7 +324,7 @@ internal static void Join<T>(
TextWriter writer,
int? listExpansionLimit = null)
{
if (list == null)
if (list is null)
{
writer.Write(NullString);
return;
Expand Down Expand Up @@ -383,7 +383,7 @@ public static IEnumerable<string> RegisteredMimeTypesFor(Type type)
/// </summary>
public static void Register(ITypeFormatter formatter)
{
if (formatter == null)
if (formatter is null)
{
throw new ArgumentNullException(nameof(formatter));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public static void FormatTo(
TextWriter writer,
string mimeType = PlainTextFormatter.MimeType)
{
if (obj == null)
if (obj is null)
{
var formatter = Formatter.GetPreferredFormatterFor(typeof(T), mimeType);
formatter.Format(context, null, writer);
Expand Down
2 changes: 1 addition & 1 deletion src/Microsoft.DotNet.Interactive.Formatting/Html.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace Microsoft.DotNet.Interactive.Formatting
public static class Html
{
internal static IHtmlContent EnsureHtmlAttributeEncoded(this object source) =>
source == null
source is null
? HtmlString.Empty
: source as IHtmlContent ?? source.ToString().HtmlAttributeEncode();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ public override string ToString()
{
// don't write out empty id attributes
if (string.Equals(pair.Key, "id", StringComparison.Ordinal) &&
(pair.Value == null || pair.Value.ToString() == string.Empty))
(pair.Value is null || pair.Value.ToString() == string.Empty))
{
continue;
}
Expand Down
Loading

0 comments on commit 4c03a63

Please sign in to comment.