Code style - Omit the type in a new expressions

This commit is contained in:
SpoinkyNL committed 2020-12-18 17:54:01 +01:00
1 parent 099f56f4fe
commit 10e6cdc54b
117 files changed
+251 -252

No files matched your search

@@ -35,7 +35,7 @@ namespace Artemis.UI.Screens.ProfileEditor.Conditions
LeftSideSelectionViewModel.LoadEventChildren = false;
IReadOnlyCollection<DataModelVisualizationRegistration> editors = _dataModelUIService.RegisteredDataModelEditors;
List<Type> supportedInputTypes = new List<Type> {typeof(DataModelEvent), typeof(DataModelEvent<>)};
List<Type> supportedInputTypes = new() {typeof(DataModelEvent), typeof(DataModelEvent<>)};
LeftSideSelectionViewModel.FilterTypes = supportedInputTypes.ToArray();
LeftSideSelectionViewModel.ButtonBrush = new SolidColorBrush(Color.FromRgb(185, 164, 10));
@@ -54,7 +54,7 @@ namespace Artemis.UI.Screens.ProfileEditor.Conditions
if (DataModelConditionEvent.EventPath == null || !DataModelConditionEvent.EventPath.IsValid)
return;
List<DataModelConditionViewModel> viewModels = new List<DataModelConditionViewModel>();
List<DataModelConditionViewModel> viewModels = new();
foreach (DataModelConditionPart childModel in Model.Children)
{
if (Items.Any(c => c.Model == childModel))
@@ -181,7 +181,7 @@ namespace Artemis.UI.Screens.ProfileEditor.Conditions
DataModelConditionGroup.RemoveChild(predicateViewModel.Model);
// Insert a list in the same position
DataModelConditionList list = new DataModelConditionList(DataModelConditionGroup);
DataModelConditionList list = new(DataModelConditionGroup);
list.UpdateList(predicateViewModel.LeftSideSelectionViewModel.DataModelPath);
DataModelConditionGroup.AddChild(list, index);
@@ -196,7 +196,7 @@ namespace Artemis.UI.Screens.ProfileEditor.Conditions
DataModelConditionGroup.RemoveChild(listViewModel.Model);
// Insert a list in the same position
DataModelConditionGeneralPredicate predicate = new DataModelConditionGeneralPredicate(DataModelConditionGroup, ProfileRightSideType.Dynamic);
DataModelConditionGeneralPredicate predicate = new(DataModelConditionGroup, ProfileRightSideType.Dynamic);
predicate.UpdateLeftSide(listViewModel.LeftSideSelectionViewModel.DataModelPath);
DataModelConditionGroup.AddChild(predicate, index);
@@ -104,7 +104,7 @@ namespace Artemis.UI.Screens.ProfileEditor.Conditions
if (DataModelConditionList.ListPath == null || !DataModelConditionList.ListPath.IsValid)
return;
List<DataModelConditionViewModel> viewModels = new List<DataModelConditionViewModel>();
List<DataModelConditionViewModel> viewModels = new();
foreach (DataModelConditionPart childModel in Model.Children)
{
if (Items.Any(c => c.Model == childModel))
@@ -84,8 +84,8 @@
<materialDesign:Card Grid.Row="3" Grid.ColumnSpan="2" Margin="0 5 0 0">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
@@ -95,7 +95,12 @@
<TextBlock Grid.Row="0" Margin="10 10 0 0">
Data binding result
</TextBlock>
<TextBlock Grid.Row="0" Grid.Column="1" Margin="0 10 10 0" TextAlignment="Right" ToolTip="Click Play to ensure all other data bindings update as well." Cursor="Help">
<TextBlock Grid.Row="0"
Grid.Column="1"
Margin="0 10 10 0"
Visibility="{Binding AlwaysApplyDataBindings.Value, Converter={x:Static s:BoolToVisibilityConverter.InverseInstance}}"
ToolTip="Click Play to ensure all other data bindings update as well or enable 'Constantly apply data bindings in editor'"
Cursor="Help">
Other data bindings not updating?
</TextBlock>
<Separator Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2" Style="{StaticResource MaterialDesignLightSeparator}" Margin="0" />
@@ -122,7 +122,7 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings.DirectDa
}
// Modifier type
ModifierTypeCategoryViewModel root = new ModifierTypeCategoryViewModel(null, null);
ModifierTypeCategoryViewModel root = new(null, null);
IEnumerable<IGrouping<string, BaseDataBindingModifierType>> modifierTypes = _dataBindingService.GetCompatibleModifierTypes(sourceType, ModifierTypePart.Value).GroupBy(t => t.Category);
foreach (IGrouping<string, BaseDataBindingModifierType> dataBindingModifierTypes in modifierTypes)
{
@@ -75,7 +75,7 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties
public List<ITimelineKeyframeViewModel> GetAllKeyframeViewModels(bool expandedOnly)
{
List<ITimelineKeyframeViewModel> result = new List<ITimelineKeyframeViewModel>();
List<ITimelineKeyframeViewModel> result = new();
if (expandedOnly && !IsExpanded)
return result;
@@ -71,7 +71,7 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.Timeline.Controls
base.OnRender(drawingContext);
UpdateTimeScale();
Pen linePen = new Pen(Fill, 1);
Pen linePen = new(Fill, 1);
double width = HorizontalOffset + VisibleWidth;
int frameStart = 0;
@@ -126,8 +126,8 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.Timeline.Controls
private void RenderLabel(DrawingContext drawingContext, string text, double x)
{
Typeface typeFace = new Typeface(FontFamily, new FontStyle(), new FontWeight(), new FontStretch());
FormattedText formattedText = new FormattedText(text, CultureInfo.CurrentUICulture, FlowDirection.LeftToRight, typeFace, 9, Fill, null, VisualTreeHelper.GetDpi(this).PixelsPerDip);
Typeface typeFace = new(FontFamily, new FontStyle(), new FontWeight(), new FontStretch());
FormattedText formattedText = new(text, CultureInfo.CurrentUICulture, FlowDirection.LeftToRight, typeFace, 9, Fill, null, VisualTreeHelper.GetDpi(this).PixelsPerDip);
if (x == 0 && OffsetFirstValue)
drawingContext.DrawText(formattedText, new Point(2, 5));
else
@@ -42,7 +42,7 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.Timeline.Dialogs
public class TimelineSegmentDialogViewModelValidator : AbstractValidator<TimelineSegmentDialogViewModel>
{
private readonly Regex _inputRegex = new Regex("^[.][-|0-9]+$|^-?[0-9]*[.]{0,1}[0-9]*$");
private readonly Regex _inputRegex = new("^[.][-|0-9]+$|^-?[0-9]*[.]{0,1}[0-9]*$");
public TimelineSegmentDialogViewModelValidator()
{
@@ -31,7 +31,7 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.Timeline.Models
if (HasBeenPasted)
throw new ArtemisUIException("Clipboard model can only be pasted once");
List<ILayerPropertyKeyframe> results = new List<ILayerPropertyKeyframe>();
List<ILayerPropertyKeyframe> results = new();
if (!ClipboardModels.Any())
return results;
@@ -249,7 +249,7 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.Timeline
private void CopyKeyframes(List<ILayerPropertyKeyframe> keyframes)
{
KeyframesClipboardModel clipboardModel = new KeyframesClipboardModel(keyframes);
KeyframesClipboardModel clipboardModel = new(keyframes);
JsonClipboard.SetObject(clipboardModel);
}
@@ -261,7 +261,7 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.Timeline
private List<ILayerPropertyKeyframe> PasteClipboardData(KeyframesClipboardModel clipboardModel, TimeSpan pastePosition)
{
List<ILayerPropertyKeyframe> pasted = new List<ILayerPropertyKeyframe>();
List<ILayerPropertyKeyframe> pasted = new();
if (clipboardModel == null)
return pasted;
RenderProfileElement target = _profileEditorService.SelectedProfileElement;
@@ -368,7 +368,7 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.Timeline
return;
Point position = e.GetPosition((IInputElement) sender);
Rect selectedRect = new Rect(_mouseDragStartPoint, position);
Rect selectedRect = new(_mouseDragStartPoint, position);
SelectionRectangle.Rect = selectedRect;
List<ITimelineKeyframeViewModel> keyframeViewModels = GetAllKeyframeViewModels();
@@ -386,7 +386,7 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.Timeline
if (_mouseDragging && e.LeftButton == MouseButtonState.Pressed)
{
Point position = e.GetPosition((IInputElement) sender);
Rect selectedRect = new Rect(_mouseDragStartPoint, position);
Rect selectedRect = new(_mouseDragStartPoint, position);
SelectionRectangle.Rect = selectedRect;
e.Handled = true;
}
@@ -432,7 +432,7 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.Timeline
private List<ITimelineKeyframeViewModel> GetAllKeyframeViewModels()
{
List<ITimelineKeyframeViewModel> viewModels = new List<ITimelineKeyframeViewModel>();
List<ITimelineKeyframeViewModel> viewModels = new();
foreach (LayerPropertyGroupViewModel layerPropertyGroupViewModel in LayerPropertyGroups)
viewModels.AddRange(layerPropertyGroupViewModel.GetAllKeyframeViewModels(false));
@@ -79,7 +79,7 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.Tree
// Find the BaseLayerBrush parameter, it is required by the base constructor so its there for sure
ParameterInfo brushParameter = constructors.First().GetParameters().First(p => typeof(BaseLayerBrush).IsAssignableFrom(p.ParameterType));
ConstructorArgument argument = new ConstructorArgument(brushParameter.Name, layerBrush);
ConstructorArgument argument = new(brushParameter.Name, layerBrush);
BrushConfigurationViewModel viewModel = (BrushConfigurationViewModel) layerBrush.Descriptor.Provider.Plugin.Kernel.Get(configurationViewModel.Type, argument);
_windowManager.ShowDialog(new LayerBrushSettingsWindowViewModel(viewModel));
@@ -105,7 +105,7 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.Tree
throw new ArtemisUIException("Effect configuration dialogs must have exactly one constructor");
ParameterInfo effectParameter = constructors.First().GetParameters().First(p => typeof(BaseLayerEffect).IsAssignableFrom(p.ParameterType));
ConstructorArgument argument = new ConstructorArgument(effectParameter.Name, layerEffect);
ConstructorArgument argument = new(effectParameter.Name, layerEffect);
EffectConfigurationViewModel viewModel = (EffectConfigurationViewModel) layerEffect.Descriptor.Provider.Plugin.Kernel.Get(configurationViewModel.Type, argument);
_windowManager.ShowDialog(new LayerEffectSettingsWindowViewModel(viewModel));
}
@@ -24,7 +24,7 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.Tree
return;
e.Handled = true;
MouseWheelEventArgs eventArg = new MouseWheelEventArgs(e.MouseDevice, e.Timestamp, e.Delta)
MouseWheelEventArgs eventArg = new(e.MouseDevice, e.Timestamp, e.Delta)
{
RoutedEvent = UIElement.MouseWheelEvent,
Source = sender
@@ -54,7 +54,7 @@ namespace Artemis.UI.Screens.ProfileEditor.ProfileTree.TreeItem
public List<TreeItemViewModel> GetAllChildren()
{
List<TreeItemViewModel> children = new List<TreeItemViewModel>();
List<TreeItemViewModel> children = new();
foreach (TreeItemViewModel childFolder in Items)
{
// Add all children in this element
@@ -128,7 +128,7 @@ namespace Artemis.UI.Screens.ProfileEditor.ProfileTree.TreeItem
if (!SupportsChildren)
throw new ArtemisUIException("Cannot add a folder to a profile element of type " + ProfileElement.GetType().Name);
Folder _ = new Folder(ProfileElement, "New folder");
Folder _ = new(ProfileElement, "New folder");
_profileEditorService.UpdateSelectedProfile();
}
@@ -137,7 +137,7 @@ namespace Artemis.UI.Screens.ProfileEditor.ProfileTree.TreeItem
if (!SupportsChildren)
throw new ArtemisUIException("Cannot add a layer to a profile element of type " + ProfileElement.GetType().Name);
Layer layer = new Layer(ProfileElement, "New layer");
Layer layer = new(ProfileElement, "New layer");
// Could be null if the default brush got disabled
LayerBrushDescriptor brush = _layerBrushService.GetDefaultLayerBrush();
@@ -217,7 +217,7 @@ namespace Artemis.UI.Screens.ProfileEditor.ProfileTree.TreeItem
Items.Remove(treeItemViewModel);
// Add missing children
List<TreeItemViewModel> newChildren = new List<TreeItemViewModel>();
List<TreeItemViewModel> newChildren = new();
foreach (ProfileElement profileElement in ProfileElement.Children.OrderBy(c => c.Order))
if (profileElement is Folder folder)
{
@@ -74,7 +74,7 @@ namespace Artemis.UI.Screens.ProfileEditor.Visualization
}
}
public Thickness LayerPosition => new Thickness(ViewportRectangle.Left, ViewportRectangle.Top, 0, 0);
public Thickness LayerPosition => new(ViewportRectangle.Left, ViewportRectangle.Top, 0, 0);
public bool IsSelected
{
@@ -188,7 +188,7 @@ namespace Artemis.UI.Screens.ProfileEditor.Visualization
base.OnInitialActivate();
}
protected override void OnClose()
{
_coreService.FrameRendered -= OnFrameRendered;
@@ -367,13 +367,13 @@ namespace Artemis.UI.Screens.ProfileEditor.Visualization
{
TimeSpan delta = DateTime.Now - _lastUpdate;
_lastUpdate = DateTime.Now;
if (!AlwaysApplyDataBindings.Value || _profileEditorService.SelectedProfile == null)
if (!AlwaysApplyDataBindings.Value || _profileEditorService.SelectedProfile == null || ((ProfileEditorViewModel) Parent).LayerPropertiesViewModel.Playing)
return;
foreach (IDataBindingRegistration dataBindingRegistration in _profileEditorService.SelectedProfile.GetAllFolders()
.SelectMany(f => f.GetAllLayerProperties(), (f, p) => p)
.SelectMany(p => p.GetAllDataBindingRegistrations()))
.SelectMany(p => p.GetAllDataBindingRegistrations()))
dataBindingRegistration.GetDataBinding()?.UpdateWithDelta(delta);
foreach (IDataBindingRegistration dataBindingRegistration in _profileEditorService.SelectedProfile.GetAllLayers()
.SelectMany(f => f.GetAllLayerProperties(), (f, p) => p)
@@ -420,13 +420,13 @@ namespace Artemis.UI.Screens.ProfileEditor.Visualization
{
UpdateCanSelectEditTool();
}
private void TransformValueChanged(object sender, LayerPropertyEventArgs e)
{
if (ActiveToolIndex != 1)
ActivateToolByIndex(1);
}
private void OnSelectedProfileElementUpdated(object sender, EventArgs e)
{
ApplyActiveProfile();
@@ -62,7 +62,7 @@ namespace Artemis.UI.Screens.ProfileEditor.Visualization.Tools
ShapeAnchor = _layerEditorService.GetLayerAnchorPosition(layer).ToSKPoint();
Execute.PostToUIThread(() =>
{
RectangleGeometry shapeGeometry = new RectangleGeometry(_layerEditorService.GetLayerBounds(layer))
RectangleGeometry shapeGeometry = new(_layerEditorService.GetLayerBounds(layer))
{
Transform = _layerEditorService.GetLayerTransformGroup(layer)
};
@@ -392,12 +392,12 @@ namespace Artemis.UI.Screens.ProfileEditor.Visualization.Tools
private static SKPoint RoundPoint(SKPoint point, int decimals)
{
return new SKPoint((float) Math.Round(point.X, decimals, MidpointRounding.AwayFromZero), (float) Math.Round(point.Y, decimals, MidpointRounding.AwayFromZero));
return new((float) Math.Round(point.X, decimals, MidpointRounding.AwayFromZero), (float) Math.Round(point.Y, decimals, MidpointRounding.AwayFromZero));
}
private static SKPoint[] UnTransformPoints(SKPoint[] skPoints, Layer layer, SKPoint pivot, bool includeScale)
{
using SKPath counterRotatePath = new SKPath();
using SKPath counterRotatePath = new();
counterRotatePath.AddPoly(skPoints, false);
counterRotatePath.Transform(SKMatrix.CreateRotationDegrees(layer.Transform.Rotation.CurrentValue * -1, pivot.X, pivot.Y));
if (includeScale)
@@ -15,7 +15,7 @@ namespace Artemis.UI.Screens.ProfileEditor.Visualization.Tools
public SelectionRemoveToolViewModel(ProfileViewModel profileViewModel, IProfileEditorService profileEditorService) : base(profileViewModel, profileEditorService)
{
using (MemoryStream stream = new MemoryStream(Resources.aero_pen_min))
using (MemoryStream stream = new(Resources.aero_pen_min))
{
Cursor = new Cursor(stream);
}
@@ -32,7 +32,7 @@ namespace Artemis.UI.Screens.ProfileEditor.Visualization.Tools
base.MouseUp(sender, e);
Point position = ProfileViewModel.PanZoomViewModel.GetRelativeMousePosition(sender, e);
Rect selectedRect = new Rect(MouseDownStartPosition, position);
Rect selectedRect = new(MouseDownStartPosition, position);
// Get selected LEDs
List<ArtemisLed> selectedLeds = ProfileViewModel.GetLedsInRectangle(selectedRect);
@@ -60,7 +60,7 @@ namespace Artemis.UI.Screens.ProfileEditor.Visualization.Tools
}
Point position = ProfileViewModel.PanZoomViewModel.GetRelativeMousePosition(sender, e);
Rect selectedRect = new Rect(MouseDownStartPosition, position);
Rect selectedRect = new(MouseDownStartPosition, position);
List<ArtemisLed> selectedLeds = ProfileViewModel.GetLedsInRectangle(selectedRect);
// Unless shift is held down, clear the current selection
@@ -21,7 +21,7 @@ namespace Artemis.UI.Screens.ProfileEditor.Visualization.Tools
ILayerBrushService layerBrushService) : base(profileViewModel, profileEditorService)
{
_layerBrushService = layerBrushService;
using (MemoryStream stream = new MemoryStream(Resources.aero_crosshair))
using (MemoryStream stream = new(Resources.aero_crosshair))
{
Cursor = new Cursor(stream);
}
@@ -38,7 +38,7 @@ namespace Artemis.UI.Screens.ProfileEditor.Visualization.Tools
base.MouseUp(sender, e);
Point position = ProfileViewModel.PanZoomViewModel.GetRelativeMousePosition(sender, e);
Rect selectedRect = new Rect(MouseDownStartPosition, position);
Rect selectedRect = new(MouseDownStartPosition, position);
// Get selected LEDs
List<ArtemisLed> selectedLeds = ProfileViewModel.GetLedsInRectangle(selectedRect);
@@ -78,7 +78,7 @@ namespace Artemis.UI.Screens.ProfileEditor.Visualization.Tools
}
Point position = ProfileViewModel.PanZoomViewModel.GetRelativeMousePosition(sender, e);
Rect selectedRect = new Rect(MouseDownStartPosition, position);
Rect selectedRect = new(MouseDownStartPosition, position);
List<ArtemisLed> selectedLeds = ProfileViewModel.GetLedsInRectangle(selectedRect);
// Unless shift is held down, clear the current selection
@@ -91,7 +91,7 @@ namespace Artemis.UI.Screens.ProfileEditor.Visualization.Tools
private void CreateLayer(Folder folder, List<ArtemisLed> selectedLeds)
{
Layer newLayer = new Layer(folder, "New layer");
Layer newLayer = new(folder, "New layer");
LayerBrushDescriptor brush = _layerBrushService.GetDefaultLayerBrush();
if (brush != null)
@@ -161,7 +161,7 @@ namespace Artemis.UI.Screens.ProfileEditor.Visualization.UserControls
private void UpdateControlPosition(UIElement control, SKPoint point1, SKPoint point2)
{
SKPoint point = new SKPoint((point1.X + point2.X) / 2, (point1.Y + point2.Y) / 2);
SKPoint point = new((point1.X + point2.X) / 2, (point1.Y + point2.Y) / 2);
UpdateControlPosition(control, point);
}