Skip to content

Commit

Permalink
Enable IDE0074 Use compound assignment
Browse files Browse the repository at this point in the history
  • Loading branch information
elachlan committed Oct 11, 2022
1 parent 0c64838 commit c6fffe9
Show file tree
Hide file tree
Showing 221 changed files with 550 additions and 2,079 deletions.
2 changes: 1 addition & 1 deletion eng/CodeAnalysis.src.globalconfig
Original file line number Diff line number Diff line change
Expand Up @@ -1642,7 +1642,7 @@ dotnet_diagnostic.IDE0072.severity = silent
dotnet_diagnostic.IDE0073.severity = warning

# IDE0074: Use compound assignment
dotnet_diagnostic.IDE0074.severity = none # TODO: warning
dotnet_diagnostic.IDE0074.severity = warning

# IDE0075: Simplify conditional expression
dotnet_diagnostic.IDE0075.severity = silent
Expand Down
3 changes: 1 addition & 2 deletions src/Common/tests/TestUtilities/TestAccessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,7 @@ public TDelegate CreateDelegate<TDelegate>(string methodName = null)

// To make it easier to write a class wrapper with a number of delegates,
// we'll take the name from the delegate itself when unspecified.
if (methodName is null)
methodName = type.Name;
methodName ??= type.Name;

MethodInfo methodInfo = s_type.GetMethod(
methodName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,8 @@ public override object EditValue(ITypeDescriptorContext context, IServiceProvide
return value;
}

if (_binaryUI is null)
{
// Child modal dialog- launching in SystemAware mode.
_binaryUI = DpiHelper.CreateInstanceInSystemAwareContext(() => new BinaryUI(this));
}
// Child modal dialog- launching in SystemAware mode.
_binaryUI ??= DpiHelper.CreateInstanceInSystemAwareContext(() => new BinaryUI(this));

_binaryUI.Value = value;
if (editorService.ShowDialog(_binaryUI) == DialogResult.OK)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,7 @@ private void AddDownMenu_click(object sender, EventArgs e)
/// </summary>
private void AddItems(IList instances)
{
if (_createdItems is null)
{
_createdItems = new ArrayList();
}
_createdItems ??= new ArrayList();

_listbox.BeginUpdate();
try
Expand Down Expand Up @@ -759,10 +756,7 @@ protected override void OnEditValueChanged()
}

// Remember these contents for cancellation
if (_originalItems is null)
{
_originalItems = new ArrayList();
}
_originalItems ??= new ArrayList();

_originalItems.Clear();

Expand Down Expand Up @@ -910,10 +904,7 @@ private void RemoveInternal(ListItem item)
{
if (CanRemoveInstance(item.Value))
{
if (_removedItems is null)
{
_removedItems = new ArrayList();
}
_removedItems ??= new ArrayList();

_removedItems.Add(item.Value);
_listbox.Items.Remove(item);
Expand Down Expand Up @@ -1376,10 +1367,7 @@ public UITypeEditor Editor
if (_uiTypeEditor is null)
{
_uiTypeEditor = TypeDescriptor.GetEditor(_value, typeof(UITypeEditor));
if (_uiTypeEditor is null)
{
_uiTypeEditor = this;
}
_uiTypeEditor ??= this;
}

if (_uiTypeEditor != this)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,7 @@ private PropertyDescriptor GetShadowedPropertyDescriptor(string propertyName)
_descriptors ??= new Hashtable();

PropertyDescriptor property = (PropertyDescriptor)_descriptors[propertyName];
if (property is null)
{
property = TypeDescriptor.GetProperties(_designer.Component.GetType())[propertyName];
//_descriptors[propertyName] = property ?? throw new ArgumentException(SR.GetResourceString(SR.DesignerPropNotFound, propertyName));
}
property ??= TypeDescriptor.GetProperties(_designer.Component.GetType())[propertyName];

return property;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -327,10 +327,7 @@ protected internal virtual object CreateInstance(Type type)
}
}

if (instance is null)
{
instance = Activator.CreateInstance(type, BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.CreateInstance, null, null, null);
}
instance ??= Activator.CreateInstance(type, BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.CreateInstance, null, null, null);

return instance;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,7 @@ protected ServiceContainer ServiceContainer
{
get
{
if (_serviceContainer is null)
{
_serviceContainer = new ServiceContainer(_parentProvider);
}
_serviceContainer ??= new ServiceContainer(_parentProvider);

return _serviceContainer;
}
Expand Down Expand Up @@ -461,10 +458,7 @@ object IServiceProvider.GetService(Type serviceType)

object service = _primaryProvider.GetService(serviceType);

if (service is null)
{
service = _secondaryProvider.GetService(serviceType);
}
service ??= _secondaryProvider.GetService(serviceType);

return service;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public DesignerActionItem(string displayName, string category, string descriptio

public virtual string DisplayName { get; }

public IDictionary Properties => _properties ?? (_properties = new HybridDictionary());
public IDictionary Properties => _properties ??= new HybridDictionary();

public bool ShowInSourceView { get; set; } = true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,7 @@ public DesignerActionMethodItem(DesignerActionList actionList, string memberName

public virtual void Invoke()
{
if (_methodInfo is null)
{
_methodInfo = _actionList?.GetType()?.GetMethod(MemberName, BindingFlags.Default | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
}
_methodInfo ??= _actionList?.GetType()?.GetMethod(MemberName, BindingFlags.Default | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);

if (_methodInfo is null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,7 @@ protected PropertyDescriptor PropertyDescriptor
{
get
{
if (_propDesc is null)
{
_propDesc = TypeDescriptor.GetProperties(_actionList)[_propertyItem.MemberName];
}
_propDesc ??= TypeDescriptor.GetProperties(_actionList)[_propertyItem.MemberName];

return _propDesc;
}
Expand All @@ -50,10 +47,7 @@ protected ITypeDescriptorContext TypeDescriptorContext
{
get
{
if (_typeDescriptorContext is null)
{
_typeDescriptorContext = new TypeDescriptorContext(ServiceProvider, PropertyDescriptor, _actionList);
}
_typeDescriptorContext ??= new TypeDescriptorContext(ServiceProvider, PropertyDescriptor, _actionList);

return _typeDescriptorContext;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,7 @@ public CommandID[] FilteredCommandIDs
{
get
{
if (_filteredCommandIDs is null)
{
_filteredCommandIDs = new CommandID[]
_filteredCommandIDs ??= new CommandID[]
{
StandardCommands.Copy,
StandardCommands.Cut,
Expand Down Expand Up @@ -192,7 +190,6 @@ public CommandID[] FilteredCommandIDs
MenuCommands.KeyShiftEnd,
MenuCommands.KeyShiftHome,
};
}

return _filteredCommandIDs;
}
Expand Down Expand Up @@ -287,10 +284,7 @@ private event EventHandler FormDeactivate
private static void AddToCategories(LineInfo lineInfo, ListDictionary categories)
{
string categoryName = lineInfo.Item.Category;
if (categoryName is null)
{
categoryName = string.Empty;
}
categoryName ??= string.Empty;

ListDictionary category = (ListDictionary)categories[categoryName];
if (category is null)
Expand Down Expand Up @@ -699,10 +693,7 @@ private IEnumerable<LineInfo> ProcessRelatedTaskItems(IComponent relatedComponen
{
// Try to use the component's service provider if it exists so that we end up getting the right IDesignerHost.
IServiceProvider serviceProvider = relatedComponent.Site;
if (serviceProvider is null)
{
serviceProvider = ServiceProvider;
}
serviceProvider ??= ServiceProvider;

IDesignerHost host = (IDesignerHost)serviceProvider.GetService(typeof(IDesignerHost));
if (host is not null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,10 +179,7 @@ internal DesignerActionGlyph GetDesignerActionGlyph(IComponent comp, DesignerAct
}

// we didnt get on, fetch it
if (dalColl is null)
{
dalColl = _designerActionService.GetComponentActions(comp);
}
dalColl ??= _designerActionService.GetComponentActions(comp);

if (dalColl is not null && dalColl.Count > 0)
{
Expand All @@ -207,11 +204,8 @@ internal DesignerActionGlyph GetDesignerActionGlyph(IComponent comp, DesignerAct
}

//either comp is a control or we failed to find a traycontrol (which could be the case for toolstripitem components) - in this case just create a standard glyph.
if (dag is null)
{
//if the related comp is a control, then this shortcut will be off its bounds
dag = new DesignerActionGlyph(dab, _designerActionAdorner);
}
//if the related comp is a control, then this shortcut will be off its bounds
dag ??= new DesignerActionGlyph(dab, _designerActionAdorner);

if (dag is not null)
{
Expand Down Expand Up @@ -650,10 +644,7 @@ private void ToolStripDropDown_Closing(object sender, ToolStripDropDownClosingEv

internal Point UpdateDAPLocation(IComponent component, DesignerActionGlyph glyph)
{
if (component is null)
{ // in case of a resize...
component = _lastPanelComponent;
}
component ??= _lastPanelComponent;

if (designerActionHost is null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,7 @@ internal void OnCreateDesigner(DesignSurface surface)
IDesignerHost host = surface.GetService(typeof(IDesignerHost)) as IDesignerHost;
Debug.Assert(host is not null, "Design surface did not provide us with a designer host");

if (_designerList is null)
{
_designerList = new ArrayList();
}
_designerList ??= new ArrayList();

_designerList.Add(host);

Expand Down Expand Up @@ -344,15 +341,9 @@ DesignerCollection IDesignerEventService.Designers
{
get
{
if (_designerList is null)
{
_designerList = new ArrayList();
}
_designerList ??= new ArrayList();

if (_designerCollection is null)
{
_designerCollection = new DesignerCollection(_designerList);
}
_designerCollection ??= new DesignerCollection(_designerList);

return _designerCollection;
}
Expand All @@ -366,10 +357,7 @@ event ActiveDesignerEventHandler IDesignerEventService.ActiveDesignerChanged
{
add
{
if (_events is null)
{
_events = new EventHandlerList();
}
_events ??= new EventHandlerList();

_events[s_eventActiveDesignerChanged] = Delegate.Combine(_events[s_eventActiveDesignerChanged], value);
}
Expand All @@ -391,10 +379,7 @@ event DesignerEventHandler IDesignerEventService.DesignerCreated
{
add
{
if (_events is null)
{
_events = new EventHandlerList();
}
_events ??= new EventHandlerList();

_events[s_eventDesignerCreated] = Delegate.Combine(_events[s_eventDesignerCreated], value);
}
Expand All @@ -416,10 +401,7 @@ event DesignerEventHandler IDesignerEventService.DesignerDisposed
{
add
{
if (_events is null)
{
_events = new EventHandlerList();
}
_events ??= new EventHandlerList();

_events[s_eventDesignerDisposed] = Delegate.Combine(_events[s_eventDesignerDisposed], value);
}
Expand All @@ -441,10 +423,7 @@ event EventHandler IDesignerEventService.SelectionChanged
{
add
{
if (_events is null)
{
_events = new EventHandlerList();
}
_events ??= new EventHandlerList();

_events[s_eventSelectionChanged] = Delegate.Combine(_events[s_eventSelectionChanged], value);
}
Expand Down
Loading

0 comments on commit c6fffe9

Please sign in to comment.