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.Shared
if (scrollPos == scrollViewer.ScrollableHeight && e.Delta < 0 || scrollPos == 0 && e.Delta > 0)
{
e.Handled = true;
MouseWheelEventArgs e2 = new MouseWheelEventArgs(e.MouseDevice, e.Timestamp, e.Delta);
MouseWheelEventArgs e2 = new(e.MouseDevice, e.Timestamp, e.Delta);
e2.RoutedEvent = UIElement.MouseWheelEvent;
AssociatedObject.RaiseEvent(e2);
}
@@ -106,7 +106,7 @@ namespace Artemis.UI.Shared
// Determine the scale required to fit the desired size of the control
Size measureSize = MeasureDevice();
double scale = Math.Min(DesiredSize.Width / measureSize.Width, DesiredSize.Height / measureSize.Height);
Rect scaledRect = new Rect(0, 0, measureSize.Width * scale, measureSize.Height * scale);
Rect scaledRect = new(0, 0, measureSize.Width * scale, measureSize.Height * scale);
// Center and scale the visualization in the desired bounding box
if (DesiredSize.Width > 0 && DesiredSize.Height > 0)
@@ -116,7 +116,7 @@ namespace Artemis.UI.Shared
}
// Determine the offset required to rotate within bounds
Rect rotationRect = new Rect(0, 0, Device.RgbDevice.ActualSize.Width, Device.RgbDevice.ActualSize.Height);
Rect rotationRect = new(0, 0, Device.RgbDevice.ActualSize.Width, Device.RgbDevice.ActualSize.Height);
rotationRect.Transform(new RotateTransform(Device.Rotation).Value);
// Apply device rotation
@@ -169,7 +169,7 @@ namespace Artemis.UI.Shared
if (Device == null)
return Size.Empty;
Rect rotationRect = new Rect(0, 0, Device.RgbDevice.ActualSize.Width, Device.RgbDevice.ActualSize.Height);
Rect rotationRect = new(0, 0, Device.RgbDevice.ActualSize.Width, Device.RgbDevice.ActualSize.Height);
rotationRect.Transform(new RotateTransform(Device.Rotation).Value);
return rotationRect.Size;
@@ -249,16 +249,16 @@ namespace Artemis.UI.Shared
}
// Create the opacity drawing group
DrawingGroup opacityDrawingGroup = new DrawingGroup();
DrawingGroup opacityDrawingGroup = new();
DrawingContext drawingContext = opacityDrawingGroup.Open();
foreach (DeviceVisualizerLed deviceVisualizerLed in _deviceVisualizerLeds)
deviceVisualizerLed.RenderOpacityMask(drawingContext);
drawingContext.Close();
// Render the store as a bitmap
DrawingImage drawingImage = new DrawingImage(opacityDrawingGroup);
Image image = new Image {Source = drawingImage};
RenderTargetBitmap bitmap = new RenderTargetBitmap(
DrawingImage drawingImage = new(opacityDrawingGroup);
Image image = new() {Source = drawingImage};
RenderTargetBitmap bitmap = new(
Math.Max(1, (int) (opacityDrawingGroup.Bounds.Width * 2.5)),
Math.Max(1, (int) (opacityDrawingGroup.Bounds.Height * 2.5)),
96,
@@ -270,7 +270,7 @@ namespace Artemis.UI.Shared
bitmap.Freeze();
// Set the bitmap as the opacity mask for the colors backing store
ImageBrush bitmapBrush = new ImageBrush(bitmap);
ImageBrush bitmapBrush = new(bitmap);
bitmapBrush.Freeze();
_backingStore.OpacityMask = bitmapBrush;
@@ -61,9 +61,9 @@ namespace Artemis.UI.Shared
if (DisplayGeometry == null)
return;
SolidColorBrush fillBrush = new SolidColorBrush(Color.FromArgb(100, 255, 255, 255));
SolidColorBrush fillBrush = new(Color.FromArgb(100, 255, 255, 255));
fillBrush.Freeze();
SolidColorBrush penBrush = new SolidColorBrush(Color.FromArgb(255, 255, 255, 255));
SolidColorBrush penBrush = new(Color.FromArgb(255, 255, 255, 255));
penBrush.Freeze();
// Create transparent pixels covering the entire LedRect so the image size matched the LedRect size
@@ -44,7 +44,7 @@ namespace Artemis.UI.Shared
typeof(RoutedPropertyChangedEventHandler<float>),
typeof(DraggableFloat));
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]*$");
private bool _calledDragStarted;
@@ -196,10 +196,10 @@ namespace Artemis.UI.Shared
}
// Use decimals for everything to avoid floating point errors
decimal startValue = new decimal(_startValue);
decimal startX = new decimal(_mouseDragStartPoint.X);
decimal x = new decimal(e.GetPosition((IInputElement) sender).X);
decimal stepSize = new decimal(StepSize);
decimal startValue = new(_startValue);
decimal startX = new(_mouseDragStartPoint.X);
decimal x = new(e.GetPosition((IInputElement) sender).X);
decimal stepSize = new(StepSize);
if (stepSize == 0)
stepSize = 0.1m;
@@ -21,7 +21,7 @@ namespace Artemis.UI.Shared
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
List<ColorGradientStop> colorGradients = (List<ColorGradientStop>) value;
GradientStopCollection collection = new GradientStopCollection();
GradientStopCollection collection = new();
if (colorGradients == null)
return collection;
@@ -34,7 +34,7 @@ namespace Artemis.UI.Shared
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
GradientStopCollection collection = (GradientStopCollection) value;
List<ColorGradientStop> colorGradients = new List<ColorGradientStop>();
List<ColorGradientStop> colorGradients = new();
if (collection == null)
return colorGradients;
@@ -27,7 +27,7 @@ namespace Artemis.UI.Shared
}
}
internal override object InternalGuard => new object();
internal override object InternalGuard => new();
/// <inheritdoc />
public override void UpdateValue(object? model)
@@ -45,7 +45,7 @@ namespace Artemis.UI.Shared
/// </summary>
public DataModelPropertyAttribute TargetDescription { get; }
internal override object InternalGuard { get; } = new object();
internal override object InternalGuard { get; } = new();
/// <inheritdoc />
public sealed override void Submit()
@@ -21,7 +21,7 @@ namespace Artemis.UI.Shared.Input
private readonly IDataModelUIService _dataModelUIService;
private readonly Module _module;
private readonly Timer _updateTimer;
private SolidColorBrush _buttonBrush = new SolidColorBrush(Color.FromRgb(171, 71, 188));
private SolidColorBrush _buttonBrush = new(Color.FromRgb(171, 71, 188));
private DataModelPath? _dataModelPath;
private DataModelPropertiesViewModel? _dataModelViewModel;
private bool _displaySwitchButton;
@@ -59,7 +59,7 @@ namespace Artemis.UI.Shared.Input
/// <summary>
/// Gets the brush to use for the switch button
/// </summary>
public SolidColorBrush SwitchButtonBrush => new SolidColorBrush(ButtonBrush.Color.Darken());
public SolidColorBrush SwitchButtonBrush => new(ButtonBrush.Color.Darken());
/// <summary>
/// Gets or sets the placeholder text when no value is entered
@@ -19,7 +19,7 @@ namespace Artemis.UI.Shared.Input
{
private readonly IDataModelUIService _dataModelUIService;
private readonly Window? _rootView;
private SolidColorBrush _buttonBrush = new SolidColorBrush(Color.FromRgb(171, 71, 188));
private SolidColorBrush _buttonBrush = new(Color.FromRgb(171, 71, 188));
private bool _displaySwitchButton;
private DataModelDisplayViewModel? _displayViewModel;
private DataModelInputViewModel? _inputViewModel;
@@ -62,7 +62,7 @@ namespace Artemis.UI.Shared.Input
/// <summary>
/// Gets the brush to use for the switch button
/// </summary>
public SolidColorBrush SwitchButtonBrush => new SolidColorBrush(ButtonBrush.Color.Darken());
public SolidColorBrush SwitchButtonBrush => new(ButtonBrush.Color.Darken());
/// <summary>
/// Gets the view model used to display the value
@@ -263,7 +263,7 @@ namespace Artemis.UI.Shared
if (depth > MaxDepth)
return null;
DataModelPath dataModelPath = new DataModelPath(DataModel, path);
DataModelPath dataModelPath = new(DataModel, path);
if (!dataModelPath.IsValid)
return null;
@@ -18,7 +18,7 @@ namespace Artemis.UI.Shared
/// <returns>The created view model</returns>
public static DataModelPropertiesViewModel CreateViewModel(this EventPredicateWrapperDataModel wrapper, IDataModelUIService dataModelUIService, DataModelUpdateConfiguration configuration)
{
DataModelPropertiesViewModel viewModel = new DataModelPropertiesViewModel(wrapper, null, new DataModelPath(wrapper));
DataModelPropertiesViewModel viewModel = new(wrapper, null, new DataModelPath(wrapper));
viewModel.Update(dataModelUIService, configuration);
viewModel.UpdateRequested += (sender, args) => viewModel.Update(dataModelUIService, configuration);
viewModel.Children.First().IsVisualizationExpanded = true;
@@ -35,7 +35,7 @@ namespace Artemis.UI.Shared
/// <returns>The created view model</returns>
public static DataModelPropertiesViewModel CreateViewModel(this ListPredicateWrapperDataModel wrapper, IDataModelUIService dataModelUIService, DataModelUpdateConfiguration configuration)
{
DataModelPropertiesViewModel viewModel = new DataModelPropertiesViewModel(wrapper, null, new DataModelPath(wrapper));
DataModelPropertiesViewModel viewModel = new(wrapper, null, new DataModelPath(wrapper));
viewModel.Update(dataModelUIService, configuration);
viewModel.UpdateRequested += (sender, args) => viewModel.Update(dataModelUIService, configuration);
viewModel.Children.First().IsVisualizationExpanded = true;
@@ -85,7 +85,7 @@ namespace Artemis.UI.Shared
}
}
internal override object InternalGuard { get; } = new object();
internal override object InternalGuard { get; } = new();
#region IDisposable
@@ -52,12 +52,12 @@ namespace Artemis.UI.Shared.Screens.GradientEditor
{
Canvas? child = VisualTreeUtilities.FindChild<Canvas>((DependencyObject) sender, null);
float position = (float) (e.GetPosition(child).X / PreviewWidth);
ColorGradientStop stop = new ColorGradientStop(ColorGradient.GetColor(position), position);
ColorGradientStop stop = new(ColorGradient.GetColor(position), position);
ColorGradient.Stops.Add(stop);
ColorGradient.OnColorValuesUpdated();
int index = ColorGradient.Stops.OrderBy(s => s.Position).ToList().IndexOf(stop);
ColorStopViewModel viewModel = new ColorStopViewModel(this, stop);
ColorStopViewModel viewModel = new(this, stop);
ColorStopViewModels.Insert(index, viewModel);
SelectColorStop(viewModel);
@@ -72,7 +72,7 @@ namespace Artemis.UI.Shared.Services
if (_overlayOpacity > 1f)
_overlayOpacity = 1f;
using SKPaint overlayPaint = new SKPaint {Color = new SKColor(0, 0, 0, (byte) (255 * _overlayOpacity))};
using SKPaint overlayPaint = new() {Color = new SKColor(0, 0, 0, (byte) (255 * _overlayOpacity))};
overlayPaint.Color = _overlayColor.WithAlpha((byte) (_overlayColor.Alpha * _overlayOpacity));
e.Canvas.DrawRect(0, 0, e.Canvas.LocalClipBounds.Width, e.Canvas.LocalClipBounds.Height, overlayPaint);
}
@@ -34,7 +34,7 @@ namespace Artemis.UI.Shared.Services
public DataModelPropertiesViewModel GetMainDataModelVisualization()
{
DataModelPropertiesViewModel viewModel = new DataModelPropertiesViewModel(null, null, null);
DataModelPropertiesViewModel viewModel = new(null, null, null);
foreach (DataModel dataModelExpansion in _dataModelService.GetDataModels().OrderBy(d => d.DataModelDescription.Name))
viewModel.Children.Add(new DataModelPropertiesViewModel(dataModelExpansion, viewModel, new DataModelPath(dataModelExpansion)));
@@ -86,7 +86,7 @@ namespace Artemis.UI.Shared.Services
if (dataModel == null)
return null;
DataModelPropertiesViewModel viewModel = new DataModelPropertiesViewModel(null, null, null);
DataModelPropertiesViewModel viewModel = new(null, null, null);
viewModel.Children.Add(new DataModelPropertiesViewModel(dataModel, viewModel, new DataModelPath(dataModel)));
// Update to populate children
@@ -114,7 +114,7 @@ namespace Artemis.UI.Shared.Services
_kernel.Bind(viewModelType).ToSelf();
// Create the registration
DataModelVisualizationRegistration registration = new DataModelVisualizationRegistration(this, RegistrationType.Input, plugin, supportedType, viewModelType)
DataModelVisualizationRegistration registration = new(this, RegistrationType.Input, plugin, supportedType, viewModelType)
{
// Apply the compatible conversion types to the registration
CompatibleConversionTypes = compatibleConversionTypes
@@ -141,7 +141,7 @@ namespace Artemis.UI.Shared.Services
}
_kernel.Bind(viewModelType).ToSelf();
DataModelVisualizationRegistration registration = new DataModelVisualizationRegistration(this, RegistrationType.Display, plugin, supportedType, viewModelType);
DataModelVisualizationRegistration registration = new(this, RegistrationType.Display, plugin, supportedType, viewModelType);
_registeredDataModelDisplays.Add(registration);
return registration;
}
@@ -54,7 +54,7 @@ namespace Artemis.UI.Shared.Services.Models
// Let the folder initialize and load as usual
FolderEntity.Name += " - copy";
Folder folder = new Folder(profile, parent, FolderEntity);
Folder folder = new(profile, parent, FolderEntity);
return folder;
}
@@ -23,8 +23,8 @@ namespace Artemis.UI.Shared.Services
private readonly ILogger _logger;
private readonly IProfileService _profileService;
private readonly List<PropertyInputRegistration> _registeredPropertyEditors;
private readonly object _selectedProfileElementLock = new object();
private readonly object _selectedProfileLock = new object();
private readonly object _selectedProfileElementLock = new();
private readonly object _selectedProfileLock = new();
private TimeSpan _currentTime;
private int _pixelsPerSecond;
@@ -113,7 +113,7 @@ namespace Artemis.UI.Shared.Services
_logger.Verbose("ChangeSelectedProfile {profile}", profile);
ChangeSelectedProfileElement(null);
ProfileEventArgs profileElementEvent = new ProfileEventArgs(profile, SelectedProfile);
ProfileEventArgs profileElementEvent = new(profile, SelectedProfile);
// Ensure there is never a deactivated profile as the selected profile
if (SelectedProfile != null)
@@ -149,7 +149,7 @@ namespace Artemis.UI.Shared.Services
return;
_logger.Verbose("ChangeSelectedProfileElement {profile}", profileElement);
RenderProfileElementEventArgs profileElementEvent = new RenderProfileElementEventArgs(profileElement, SelectedProfileElement);
RenderProfileElementEventArgs profileElementEvent = new(profileElement, SelectedProfileElement);
SelectedProfileElement = profileElement;
OnSelectedProfileElementChanged(profileElementEvent);
@@ -249,7 +249,7 @@ namespace Artemis.UI.Shared.Services
}
_kernel.Bind(viewModelType).ToSelf();
PropertyInputRegistration registration = new PropertyInputRegistration(this, plugin, supportedType, viewModelType);
PropertyInputRegistration registration = new(this, plugin, supportedType, viewModelType);
_registeredPropertyEditors.Add(registration);
return registration;
}
@@ -327,7 +327,7 @@ namespace Artemis.UI.Shared.Services
if (viewModelType == null)
return null;
ConstructorArgument parameter = new ConstructorArgument("layerProperty", layerProperty);
ConstructorArgument parameter = new("layerProperty", layerProperty);
// ReSharper disable once InconsistentlySynchronizedField
// When you've just spent the last 2 hours trying to figure out a deadlock and reach this line, I'm so, so sorry. I thought this would be fine.
IKernel kernel = registration?.Plugin.Kernel ?? _kernel;
@@ -368,7 +368,7 @@ namespace Artemis.UI.Shared.Services
{
case Folder folder:
{
FolderClipboardModel clipboardModel = new FolderClipboardModel(folder);
FolderClipboardModel clipboardModel = new(folder);
JsonClipboard.SetObject(clipboardModel);
break;
}
@@ -19,8 +19,8 @@ namespace Artemis.UI.Shared
/// <returns></returns>
public static List<T> GetHitViewModels<T>(Visual container, RectangleGeometry rectangleGeometry)
{
List<T> result = new List<T>();
GeometryHitTestParameters hitTestParams = new GeometryHitTestParameters(rectangleGeometry);
List<T> result = new();
GeometryHitTestParameters hitTestParams = new(rectangleGeometry);
HitTestResultBehavior ResultCallback(HitTestResult r) => HitTestResultBehavior.Continue;
HitTestFilterBehavior FilterCallback(DependencyObject e)
@@ -9,7 +9,7 @@ namespace Artemis.UI.Shared
/// </summary>
public static class JsonClipboard
{
private static readonly JsonSerializerSettings JsonSettings = new JsonSerializerSettings {TypeNameHandling = TypeNameHandling.All};
private static readonly JsonSerializerSettings JsonSettings = new() {TypeNameHandling = TypeNameHandling.All};
/// <summary>
/// Sets the provided object on the clipboard
@@ -174,7 +174,7 @@ namespace Artemis.UI.Shared
{
// insert dummy story-boards which can later be traced using WPF animation tracing
TriggerTraceStoryboard storyboard = new TriggerTraceStoryboard(triggerBase, TriggerTraceStoryboardType.Enter);
TriggerTraceStoryboard storyboard = new(triggerBase, TriggerTraceStoryboardType.Enter);
triggerBase.EnterActions.Insert(0, new BeginStoryboard {Storyboard = storyboard});
storyboard = new TriggerTraceStoryboard(triggerBase, TriggerTraceStoryboardType.Exit);