Skip to content

[StyleCleanUp] Addressing CS warnings Part 1 #10121

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 17, 2024
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
6 changes: 0 additions & 6 deletions src/Microsoft.DotNet.Wpf/src/.editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -182,12 +182,6 @@ dotnet_diagnostic.CA5351.severity = suggestion
# CA5362: Potential reference cycle in deserialized object graph
dotnet_diagnostic.CA5362.severity = suggestion

# CSIsNull001: Use 'is' pattern check
dotnet_diagnostic.CSIsNull001.severity = suggestion

# CSIsNull002: Use 'is not' pattern check
dotnet_diagnostic.CSIsNull002.severity = suggestion

# IDE0005: Using directive is unnecessary.
dotnet_diagnostic.IDE0005.severity = suggestion

Expand Down
4 changes: 2 additions & 2 deletions src/Microsoft.DotNet.Wpf/src/Common/src/System/SR.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ internal static string GetResourceString(string resourceKey, string defaultStrin
{
string resourceString = GetResourceString(resourceKey);

if (defaultString != null && resourceKey.Equals(resourceString, StringComparison.Ordinal))
if (defaultString is not null && resourceKey.Equals(resourceString, StringComparison.Ordinal))
{
return defaultString;
}
Expand All @@ -63,7 +63,7 @@ internal static string GetResourceString(string resourceKey, string defaultStrin

internal static string Format(string resourceFormat, params object[] args)
{
if (args != null)
if (args is not null)
{
if (UsingResourceKeys())
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ internal static Exception Unwrap(Exception ex)
{
// for certain types of exceptions, we care more about the inner
// exception
while (ex.InnerException != null &&
while (ex.InnerException is not null &&
( ex is System.Reflection.TargetInvocationException
))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,9 @@ internal static Assembly GetLoadedAssembly(AssemblyName assemblyName)
byte[] curKeyToken = curAsmName.GetPublicKeyToken();

if (string.Equals(curAsmName.Name, assemblyName.Name, StringComparison.InvariantCultureIgnoreCase) &&
(reqVersion == null || reqVersion.Equals(curVersion)) &&
(reqCulture == null || reqCulture.Equals(curCulture)) &&
(reqKeyToken == null || IsSameKeyToken(reqKeyToken, curKeyToken)))
(reqVersion is null || reqVersion.Equals(curVersion)) &&
(reqCulture is null || reqCulture.Equals(curCulture)) &&
(reqKeyToken is null || IsSameKeyToken(reqKeyToken, curKeyToken)))
{
return assemblies[i];
}
Expand All @@ -160,7 +160,7 @@ static AssemblyName GetAssemblyName(Assembly assembly)
lock (syncObject)
{
AssemblyName result;
if (_assemblies == null)
if (_assemblies is null)
{
_assemblies = new Dictionary<object, AssemblyName>();
}
Expand Down Expand Up @@ -199,7 +199,7 @@ static void CleanupCollectedAssemblies(object state) // dummy parameter required
foreach (object key in _assemblies.Keys)
{
WeakReference weakRef = key as WeakReference;
if (weakRef == null)
if (weakRef is null)
{
continue;
}
Expand All @@ -211,14 +211,14 @@ static void CleanupCollectedAssemblies(object state) // dummy parameter required
else
{
// The target has been collected, add it to our list of keys to remove
if (keysToRemove == null)
if (keysToRemove is null)
{
keysToRemove = new List<object>();
}
keysToRemove.Add(key);
}
}
if (keysToRemove != null)
if (keysToRemove is not null)
{
foreach (object key in keysToRemove)
{
Expand Down Expand Up @@ -251,12 +251,12 @@ static bool IsSameKeyToken(byte[] reqKeyToken, byte[] curKeyToken)
{
bool isSame = false;

if (reqKeyToken == null && curKeyToken == null)
if (reqKeyToken is null && curKeyToken is null)
{
// Both Key Tokens are not set, treat them as same.
isSame = true;
}
else if (reqKeyToken != null && curKeyToken != null)
else if (reqKeyToken is not null && curKeyToken is not null)
{
// Both KeyTokens are set.
if (reqKeyToken.Length == curKeyToken.Length)
Expand Down Expand Up @@ -302,7 +302,7 @@ class WeakRefKey : WeakReference
public WeakRefKey(object target)
:base(target)
{
Debug.Assert(target != null);
Debug.Assert(target is not null);
_hashCode = target.GetHashCode();
}

Expand All @@ -314,12 +314,12 @@ public override int GetHashCode()
public override bool Equals(object o)
{
WeakRefKey weakRef = o as WeakRefKey;
if (weakRef != null)
if (weakRef is not null)
{
object target1 = Target;
object target2 = weakRef.Target;

if (target1 != null && target2 != null)
if (target1 is not null && target2 is not null)
{
return (target1 == target2);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public XamlContextStack(Func<T> creationDelegate)
_creationDelegate = creationDelegate;
Grow();
_depth = 0;
Debug.Assert(CurrentFrame != null);
Debug.Assert(CurrentFrame is not null);
Debug.Assert(CurrentFrame.Depth == Depth);
}

Expand All @@ -40,14 +40,14 @@ public XamlContextStack(XamlContextStack<T> source, bool copy)
{
T iteratorFrame = source.CurrentFrame;
T lastFrameInNewStack = null;
while (iteratorFrame != null)
while (iteratorFrame is not null)
{
T newFrame = (T)iteratorFrame.Clone();
if (_currentFrame == null)
if (_currentFrame is null)
{
_currentFrame = newFrame;
}
if (lastFrameInNewStack != null)
if (lastFrameInNewStack is not null)
{
lastFrameInNewStack.Previous = newFrame;
}
Expand Down Expand Up @@ -83,7 +83,7 @@ public T PreviousPreviousFrame
public T GetFrame(int depth)
{
T iteratorFrame = _currentFrame;
Debug.Assert(iteratorFrame != null);
Debug.Assert(iteratorFrame is not null);
while (iteratorFrame.Depth > depth)
{
iteratorFrame = (T)iteratorFrame.Previous;
Expand All @@ -95,7 +95,7 @@ public T GetFrame(int depth)
// or we'll grab one from our recycled linked list.
public void PushScope()
{
if (_recycledFrame == null)
if (_recycledFrame is null)
{
Grow();
}
Expand Down Expand Up @@ -141,17 +141,17 @@ public string Frames
{
StringBuilder sb = new StringBuilder();
T iteratorFrame = _currentFrame;
sb.AppendLine(CultureInfo.InvariantCulture, $"Stack: {(_currentFrame == null ? -1 : _currentFrame.Depth + 1)} frames");
sb.AppendLine(CultureInfo.InvariantCulture, $"Stack: {(_currentFrame is null ? -1 : _currentFrame.Depth + 1)} frames");
ShowFrame(sb, _currentFrame);
return sb.ToString();
}
}

private void ShowFrame(StringBuilder sb, T iteratorFrame)
{
if (iteratorFrame == null)
if (iteratorFrame is null)
return;
if (iteratorFrame.Previous != null)
if (iteratorFrame.Previous is not null)
ShowFrame(sb, (T)iteratorFrame.Previous);
sb.AppendLine($" {iteratorFrame.Depth} {iteratorFrame}");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public XamlFrame Previous
set
{
_previous = value;
_depth = (_previous == null) ? 0 : _previous._depth + 1;
_depth = (_previous is null) ? 0 : _previous._depth + 1;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ internal SpecialBracketCharacters()
internal SpecialBracketCharacters(IReadOnlyDictionary<char,char> attributeList)
{
BeginInit();
if (attributeList != null && attributeList.Count > 0)
if (attributeList is not null && attributeList.Count > 0)
{
Tokenize(attributeList);
}
Expand Down
Loading