Skip to content
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

[StyleCleanUp] Addressing IDE warnings #10185

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
3 changes: 0 additions & 3 deletions src/Microsoft.DotNet.Wpf/src/.editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -275,9 +275,6 @@ dotnet_diagnostic.IDE0082.severity = suggestion
# IDE0100: Remove redundant equality
dotnet_diagnostic.IDE0100.severity = suggestion

# IDE0150: Prefer 'null' check over type check
dotnet_diagnostic.IDE0150.severity = suggestion

# IDE0180: Use tuple to swap values
dotnet_diagnostic.IDE0180.severity = suggestion

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,7 @@ private void AttachVisual(StrokeVisual visual, bool buildingStrokeCollection)
{
// Find or create a container visual for highlighter strokes of the color
ContainerVisual parent = GetContainerVisual(visual.Stroke.DrawingAttributes);
Debug.Assert(visual is StrokeVisual);
Debug.Assert(visual is not null);

//insert StrokeVisuals under any non-StrokeVisuals used for dynamic inking
int i = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ internal ReadOnlyCollection<ParagraphResult> FloatingElementResults
}

/// <summary>
/// Called when a UIElement-derived class which is hosted by a IContentHost changes its DesiredSize
/// Called when a UIElement-derived class which is hosted by a IContentHost changes it’s DesiredSize
/// </summary>
/// <param name="child">
/// Child element whose DesiredSize has changed
Expand Down Expand Up @@ -932,7 +932,7 @@ private TextPointer FindElementPosition(IInputElement e, bool isLimitedToTextVie
Debug.Assert(e != null);

// Validate that this function is only called when a TextContainer exists as complex content
Debug.Assert(_structuralCache.TextContainer is TextContainer);
Debug.Assert(_structuralCache.TextContainer is not null);

TextPointer elementPosition = null;

Expand All @@ -949,8 +949,8 @@ private TextPointer FindElementPosition(IInputElement e, bool isLimitedToTextVie
else
{
// Else: search for e in the complex content
if (!(_structuralCache.TextContainer.Start is TextPointer) ||
!(_structuralCache.TextContainer.End is TextPointer))
if (!(_structuralCache.TextContainer.Start is not null) ||
!(_structuralCache.TextContainer.End is not null))
{
// Invalid TextContainer, don't search
return null;
Expand Down Expand Up @@ -1220,7 +1220,7 @@ IEnumerator<IInputElement> IContentHost.HostedElements
}

/// <summary>
/// Called when a UIElement-derived class which is hosted by a IContentHost changes its DesiredSize
/// Called when a UIElement-derived class which is hosted by a IContentHost changes it’s DesiredSize
/// </summary>
/// <param name="child">
/// Child element whose DesiredSize has changed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,15 @@ public static bool TryUnwrapObject(object o, out IObjectReference objRef)

Type type = o.GetType();
ObjectReferenceWrapperAttribute objRefWrapper = type.GetCustomAttribute<ObjectReferenceWrapperAttribute>();
if (objRefWrapper is object)
if (objRefWrapper is not null)
{
objRef = (IObjectReference)type.GetField(objRefWrapper.ObjectReferenceField, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly).GetValue(o);
return true;
}

ProjectedRuntimeClassAttribute projectedClass = type.GetCustomAttribute<ProjectedRuntimeClassAttribute>();

if (projectedClass is object)
if (projectedClass is not null)
{
return TryUnwrapObject(
type.GetProperty(projectedClass.DefaultInterfaceProperty, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly).GetValue(o),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public static void ThrowExceptionForHR(int hr)
{
ExceptionDispatchInfo.Capture(ex).Throw();
}
else if (ex is object)
else if (ex is not null)
{
throw ex;
}
Expand Down Expand Up @@ -108,7 +108,7 @@ private static Exception GetExceptionForHR(int hr, bool useGlobalErrorState, out
{
ILanguageExceptionErrorInfo languageErrorInfo = new ABI.WinRT.Interop.ILanguageExceptionErrorInfo(languageErrorInfoRef);
using IObjectReference languageException = languageErrorInfo.GetLanguageException();
if (languageException is object)
if (languageException is not null)
{
if (languageException.IsReferenceToManagedObject)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ private static bool IsTypeWindowsRuntimeTypeNoArray(Type type)
|| type == typeof(string)
|| type == typeof(Guid)
|| type == typeof(object)
|| type.GetCustomAttribute<WindowsRuntimeTypeAttribute>() is object;
|| type.GetCustomAttribute<WindowsRuntimeTypeAttribute>() is not null;
}

public static bool TryGetCompatibleWindowsRuntimeTypeForVariantType(Type type, out Type compatibleType)
Expand Down Expand Up @@ -212,7 +212,7 @@ internal static bool TryGetMarshalerTypeForProjectedRuntimeClass(IObjectReferenc
{
IInspectable inspectable = inspectablePtr;
string runtimeClassName = inspectable.GetRuntimeClassName(true);
if (runtimeClassName is object)
if (runtimeClassName is not null)
{
if (ProjectedRuntimeClassNames.Contains(runtimeClassName))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public static Type FindHelperType(this Type type)
type = typeof(Exception);
}
Type customMapping = Projections.FindCustomHelperTypeMapping(type);
if (customMapping is object)
if (customMapping is not null)
{
return customMapping;
}
Expand All @@ -35,7 +35,7 @@ public static Type FindHelperType(this Type type)
public static Type GetHelperType(this Type type)
{
var helperType = type.FindHelperType();
if (helperType is object)
if (helperType is not null)
return helperType;
throw new InvalidOperationException($"Target type is not a projected type: {type.FullName}.");
}
Expand All @@ -52,7 +52,7 @@ public static Type FindVftblType(this Type helperType)
{
return null;
}
if (helperType.IsGenericType && vftblType is object)
if (helperType.IsGenericType && vftblType is not null)
{
vftblType = vftblType.MakeGenericType(helperType.GetGenericArguments());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ internal static void AttachUndoManager(DependencyObject scope, UndoManager undoM
ArgumentNullException.ThrowIfNull(scope);
ArgumentNullException.ThrowIfNull(undoManager);

if (undoManager is UndoManager && ((UndoManager)undoManager)._scope != null)
if (undoManager is not null && ((UndoManager)undoManager)._scope != null)
{
throw new InvalidOperationException(SR.UndoManagerAlreadyAttached);
}
Expand All @@ -115,7 +115,7 @@ internal static void AttachUndoManager(DependencyObject scope, UndoManager undoM

// Attach the service to the scope via private dependency property
scope.SetValue(UndoManager.UndoManagerInstanceProperty, undoManager);
if (undoManager is UndoManager)
if (undoManager is not null)
{
Debug.Assert(((UndoManager)undoManager)._scope == null);
((UndoManager)undoManager)._scope = scope;
Expand Down Expand Up @@ -150,7 +150,7 @@ internal static void DetachUndoManager(DependencyObject scope)
scope.ClearValue(UndoManager.UndoManagerInstanceProperty);

// Break the linkage to its scope
if (undoManager is UndoManager)
if (undoManager is not null)
{
Debug.Assert(((UndoManager)undoManager)._scope == scope);
((UndoManager)undoManager)._scope = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ internal RecyclableWrapper GetRecyclableWrapperPeer(object item)
return _recyclableWrapperCache;
}

// UpdateChildrenIntenal is called with ItemsInvalidateLimit to ensure we dont fire unnecessary structure change events when items are just scrolled in/out of view in case of
// UpdateChildrenIntenal is called with ItemsInvalidateLimit to ensure we don’t fire unnecessary structure change events when items are just scrolled in/out of view in case of
// virtualized controls.
override internal IDisposable UpdateChildren()
{
Expand Down Expand Up @@ -637,7 +637,7 @@ public T this[object item]
if (_hashtable == null)
_hashtable = new WeakDictionary<object,T>();

if(!_hashtable.ContainsKey(item) && value is T)
if(!_hashtable.ContainsKey(item) && value is not null)
_hashtable[item] = value;
else
Debug.Assert(false,"it must not add already present Item");
Expand All @@ -646,7 +646,7 @@ public T this[object item]
{
if (_list == null)
_list = new List<KeyValuePair<object, T>>();
if(value is T)
if(value is not null)
_list.Add(new KeyValuePair<object, T>(item, value));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -850,7 +850,7 @@ internal static uint GetDebugId()

internal static string ToString(DocumentSequenceTextPointer thisTp)
{
return $"{(thisTp is DocumentSequenceTextPointer ? "DSTP" : "DSTN")} Id={thisTp.DebugId} B={thisTp.ChildBlock.DebugId} G={thisTp.ChildPointer.LogicalDirection}";
return $"{(thisTp is not null ? "DSTP" : "DSTN")} Id={thisTp.DebugId} B={thisTp.ChildBlock.DebugId} G={thisTp.ChildPointer.LogicalDirection}";
}
#endif
#endregion Internal Methods
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -638,7 +638,7 @@ internal Accessible [] GetSelection()
children = new Accessible[1];
children[0] = AccessibleFromObject(obj, _acc);
}
else if (obj is object)
else if (obj is not null)
{
children = new Accessible[1];
children[0] = AccessibleFromObject(obj, _acc);
Expand Down