diff --git a/src/MixAssembler/Parser.cs b/src/MixAssembler/Parser.cs index 88a8e9d..8effabb 100644 --- a/src/MixAssembler/Parser.cs +++ b/src/MixAssembler/Parser.cs @@ -254,18 +254,18 @@ private static string[] SplitLine(string sourceLine) var opFieldStart = FindFirstNonWhiteSpace(sourceLine, searchBeyondIndex); if (opFieldStart == -1) - return new string[] { sourceLine.Substring(0, searchBeyondIndex), string.Empty, string.Empty, string.Empty }; + return new string[] { sourceLine[..searchBeyondIndex], string.Empty, string.Empty, string.Empty }; var opFieldEnd = FindFirstWhiteSpace(sourceLine, opFieldStart); if (opFieldEnd == -1) - return new string[] { sourceLine.Substring(0, searchBeyondIndex), sourceLine[opFieldStart..], string.Empty, string.Empty }; + return new string[] { sourceLine[..searchBeyondIndex], sourceLine[opFieldStart..], string.Empty, string.Empty }; int opFieldLength = opFieldEnd - opFieldStart; var addressFieldStart = FindFirstNonWhiteSpace(sourceLine, opFieldEnd); if (addressFieldStart == -1) - return new string[] { sourceLine.Substring(0, searchBeyondIndex), sourceLine.Substring(opFieldStart, opFieldLength), string.Empty, string.Empty }; + return new string[] { sourceLine[..searchBeyondIndex], sourceLine.Substring(opFieldStart, opFieldLength), string.Empty, string.Empty }; if (sourceLine[addressFieldStart] == '"') { @@ -280,15 +280,15 @@ private static string[] SplitLine(string sourceLine) addressFieldEnd = FindFirstWhiteSpace(sourceLine, addressFieldStart); if (addressFieldEnd == -1) - return new string[] { sourceLine.Substring(0, searchBeyondIndex), sourceLine.Substring(opFieldStart, opFieldLength), sourceLine[addressFieldStart..], string.Empty }; + return new string[] { sourceLine[..searchBeyondIndex], sourceLine.Substring(opFieldStart, opFieldLength), sourceLine[addressFieldStart..], string.Empty }; int addressFieldLength = addressFieldEnd - addressFieldStart; var commentFieldStart = FindFirstNonWhiteSpace(sourceLine, addressFieldEnd); if (commentFieldStart == -1) - return new string[] { sourceLine.Substring(0, searchBeyondIndex), sourceLine.Substring(opFieldStart, opFieldLength), sourceLine.Substring(addressFieldStart, addressFieldLength), string.Empty }; + return new string[] { sourceLine[..searchBeyondIndex], sourceLine.Substring(opFieldStart, opFieldLength), sourceLine.Substring(addressFieldStart, addressFieldLength), "" }; - return new string[] { sourceLine.Substring(0, searchBeyondIndex), sourceLine.Substring(opFieldStart, opFieldLength), sourceLine.Substring(addressFieldStart, addressFieldLength), sourceLine[commentFieldStart..] }; + return new string[] { sourceLine[..searchBeyondIndex], sourceLine.Substring(opFieldStart, opFieldLength), sourceLine.Substring(addressFieldStart, addressFieldLength), sourceLine[commentFieldStart..] }; } } } diff --git a/src/MixEmul/Components/AssemblyFindingListView.cs b/src/MixEmul/Components/AssemblyFindingListView.cs index e3e48a2..255cdfc 100644 --- a/src/MixEmul/Components/AssemblyFindingListView.cs +++ b/src/MixEmul/Components/AssemblyFindingListView.cs @@ -117,12 +117,9 @@ public int Compare(AssemblyFinding x, AssemblyFinding y) } } - public class SelectionChangedEventArgs : EventArgs + public class SelectionChangedEventArgs(AssemblyFinding finding) : EventArgs { - private readonly AssemblyFinding mSelectedFinding; - - public SelectionChangedEventArgs(AssemblyFinding finding) - => mSelectedFinding = finding; + private readonly AssemblyFinding mSelectedFinding = finding; public AssemblyFinding SelectedFinding => mSelectedFinding; } diff --git a/src/MixEmul/Components/InstructionInstanceTextBox.cs b/src/MixEmul/Components/InstructionInstanceTextBox.cs index 33c999b..938b48d 100644 --- a/src/MixEmul/Components/InstructionInstanceTextBox.cs +++ b/src/MixEmul/Components/InstructionInstanceTextBox.cs @@ -205,7 +205,7 @@ private bool AssembleInstruction(bool markErrors) var instance = Assembler.Assemble(Text, MemoryAddress, out ParsedSourceLine line, Symbols, out AssemblyFindingCollection findings); - if (instance != null && !(instance is MixInstruction.Instance)) + if (instance != null && instance is not MixInstruction.Instance) { findings.Add(new AssemblyError(0, LineSection.OpField, 0, line.OpField.Length, new ValidationError("only MIX instruction mnemonics supported"))); instance = null; @@ -553,7 +553,7 @@ public IWord WordValue get => this.instructionWord; set { - if (!(value is IFullWord)) + if (value is not IFullWord) { throw new ArgumentException("value must be an IFullWord"); } diff --git a/src/MixEmul/Components/LongValueTextBox.cs b/src/MixEmul/Components/LongValueTextBox.cs index 0ff126d..11989c8 100644 --- a/src/MixEmul/Components/LongValueTextBox.cs +++ b/src/MixEmul/Components/LongValueTextBox.cs @@ -433,22 +433,14 @@ public override string Text set => CheckAndUpdateValue(value); } - public class ValueChangedEventArgs : EventArgs + public class ValueChangedEventArgs(Word.Signs oldSign, long oldMagnitude, Word.Signs newSign, long newMagnitude) : EventArgs { - public long OldMagnitude { get; private set; } - public Word.Signs OldSign { get; private set; } - public long NewMagnitude { get; private set; } - public Word.Signs NewSign { get; private set; } + public long OldMagnitude { get; private set; } = oldMagnitude; + public Word.Signs OldSign { get; private set; } = oldSign; + public long NewMagnitude { get; private set; } = newMagnitude; + public Word.Signs NewSign { get; private set; } = newSign; - public ValueChangedEventArgs(Word.Signs oldSign, long oldMagnitude, Word.Signs newSign, long newMagnitude) - { - OldMagnitude = oldMagnitude; - NewMagnitude = newMagnitude; - OldSign = oldSign; - NewSign = newSign; - } - - public long NewValue + public long NewValue => NewSign.ApplyTo(NewMagnitude); public long OldValue diff --git a/src/MixEmul/Components/MixByteCollectionCharTextBox.cs b/src/MixEmul/Components/MixByteCollectionCharTextBox.cs index 93879e8..5eb24ab 100644 --- a/src/MixEmul/Components/MixByteCollectionCharTextBox.cs +++ b/src/MixEmul/Components/MixByteCollectionCharTextBox.cs @@ -146,7 +146,7 @@ private void This_TextChanged(object sender, EventArgs e) validText += c; if (validText.Length > this.byteCollection.MaxByteCount) - validText = validText.Substring(0, this.byteCollection.MaxByteCount); + validText = validText[..this.byteCollection.MaxByteCount]; if (validText.Length > 0 || TextLength == 0) { @@ -281,7 +281,7 @@ public IMixByteCollection MixByteCollectionValue this.byteCollection = value; if (TextLength > this.byteCollection.MaxByteCount) - Text = Text.Substring(0, this.byteCollection.MaxByteCount); + Text = Text[..this.byteCollection.MaxByteCount]; Select(TextLength, 0); diff --git a/src/MixEmul/Components/MixByteTextBox.cs b/src/MixEmul/Components/MixByteTextBox.cs index 080642f..3b7c32d 100644 --- a/src/MixEmul/Components/MixByteTextBox.cs +++ b/src/MixEmul/Components/MixByteTextBox.cs @@ -197,17 +197,11 @@ public sealed override string Text set => CheckAndUpdateValue(value); } - public class ValueChangedEventArgs : EventArgs + public class ValueChangedEventArgs(MixByte oldValue, MixByte newValue) : EventArgs { - public MixByte NewValue { get; private set; } - public MixByte OldValue { get; private set; } - - public ValueChangedEventArgs(MixByte oldValue, MixByte newValue) - { - OldValue = oldValue; - NewValue = newValue; - } - } + public MixByte NewValue { get; private set; } = newValue; + public MixByte OldValue { get; private set; } = oldValue; + } public delegate void ValueChangedEventHandler(MixByteTextBox sender, MixByteTextBox.ValueChangedEventArgs e); } diff --git a/src/MixEmul/Components/PreferencesForm.cs b/src/MixEmul/Components/PreferencesForm.cs index 5a76c30..cfa9596 100644 --- a/src/MixEmul/Components/PreferencesForm.cs +++ b/src/MixEmul/Components/PreferencesForm.cs @@ -105,7 +105,7 @@ private void LoaderCardsDefaultButton_Click(object sender, EventArgs e) private void InitializeLoaderCardTextBoxes() { - this.loaderCardTextBoxes = new MixByteCollectionCharTextBox[] { this.loaderCard1TextBox, this.loaderCard2TextBox, this.loaderCard3TextBox }; + this.loaderCardTextBoxes = [this.loaderCard1TextBox, this.loaderCard2TextBox, this.loaderCard3TextBox]; for (int index = 0; index < this.loaderCardTextBoxes.Length; index++) { @@ -182,8 +182,8 @@ private void FillColorSelectionBox() { var comboBoxItem = new ColorComboBoxItem(colorName); - if (this.configuration.Colors.ContainsKey(colorName)) - comboBoxItem.Color = this.configuration.Colors[colorName]; + if (this.configuration.Colors.TryGetValue(colorName, out var color)) + comboBoxItem.Color = color; list.Add(comboBoxItem); } @@ -202,13 +202,13 @@ private void FillDeviceFileSelectionBox() var list = new List(); foreach (MixDevice device in this.devices) { - if (!(device is FileBasedDevice)) + if (device is not FileBasedDevice) continue; var item = new DeviceFileComboBoxItem((FileBasedDevice)device); - if (this.configuration.DeviceFilePaths.ContainsKey(device.Id)) - item.FilePath = this.configuration.DeviceFilePaths[device.Id]; + if (this.configuration.DeviceFilePaths.TryGetValue(device.Id, out var path)) + item.FilePath = path; list.Add(item); } @@ -232,8 +232,8 @@ private void FillTickCountSelectionBox() { var item = new TickCountComboBoxItem(tickCountName); - if (this.configuration.TickCounts.ContainsKey(tickCountName)) - item.TickCount = this.configuration.TickCounts[tickCountName]; + if (this.configuration.TickCounts.TryGetValue(tickCountName, out var tickCount)) + item.TickCount = tickCount; list.Add(item); } @@ -758,12 +758,7 @@ private void InitializeComponent() this.loaderCard3TextBox.Location = new Point(0, 28); this.loaderCard3TextBox.Margin = new Padding(0); fullWord1.LongValue = 0; - fullWord1.Magnitude = new MixByte[] { - mixByte1, - mixByte2, - mixByte3, - mixByte4, - mixByte5}; + fullWord1.Magnitude = [mixByte1, mixByte2, mixByte3, mixByte4, mixByte5]; fullWord1.MagnitudeLongValue = 0; fullWord1.Sign = Word.Signs.Positive; this.loaderCard3TextBox.MixByteCollectionValue = fullWord1; @@ -785,12 +780,7 @@ private void InitializeComponent() this.loaderCard2TextBox.Location = new Point(0, 14); this.loaderCard2TextBox.Margin = new Padding(0); fullWord2.LongValue = 0; - fullWord2.Magnitude = new MixByte[] { - mixByte6, - mixByte7, - mixByte8, - mixByte9, - mixByte10}; + fullWord2.Magnitude = [mixByte6, mixByte7, mixByte8, mixByte9, mixByte10]; fullWord2.MagnitudeLongValue = 0; fullWord2.Sign = Word.Signs.Positive; this.loaderCard2TextBox.MixByteCollectionValue = fullWord2; @@ -812,12 +802,7 @@ private void InitializeComponent() this.loaderCard1TextBox.Location = new Point(0, 0); this.loaderCard1TextBox.Margin = new Padding(0); fullWord3.LongValue = 0; - fullWord3.Magnitude = new MixByte[] { - mixByte11, - mixByte12, - mixByte13, - mixByte14, - mixByte15}; + fullWord3.Magnitude = [mixByte11, mixByte12, mixByte13, mixByte14, mixByte15]; fullWord3.MagnitudeLongValue = 0; fullWord3.Sign = Word.Signs.Positive; this.loaderCard1TextBox.MixByteCollectionValue = fullWord3; @@ -914,18 +899,15 @@ private void ColorDefaultButton_Click(object sender, EventArgs e) private void ColorSetButton_Click(object sender, EventArgs e) { - if (this.colorDialog == null) + this.colorDialog ??= new ColorDialog { - this.colorDialog = new ColorDialog - { - AnyColor = true, - SolidColorOnly = true, - AllowFullOpen = true - }; - } + AnyColor = true, + SolidColorOnly = true, + AllowFullOpen = true + }; var selectedItem = (ColorComboBoxItem)this.colorSelectionBox.SelectedItem; - this.colorDialog.CustomColors = new int[] { selectedItem.Color.B << 16 | selectedItem.Color.G << 8 | selectedItem.Color.R }; + this.colorDialog.CustomColors = [selectedItem.Color.B << 16 | selectedItem.Color.G << 8 | selectedItem.Color.R]; this.colorDialog.Color = selectedItem.Color; if (this.colorDialog.ShowDialog(this) == DialogResult.OK) @@ -978,13 +960,10 @@ private void DeviceDirectoryDefaultButton_Click(object sender, EventArgs e) private void DeviceDirectorySetButton_Click(object sender, EventArgs e) { - if (this.deviceFilesFolderBrowserDialog == null) + this.deviceFilesFolderBrowserDialog ??= new FolderBrowserDialog { - this.deviceFilesFolderBrowserDialog = new FolderBrowserDialog - { - Description = "Please select the default directory for device files." - }; - } + Description = "Please select the default directory for device files." + }; this.deviceFilesFolderBrowserDialog.SelectedPath = GetCurrentDeviceFilesDirectory(); @@ -1006,16 +985,13 @@ private void DeviceFileDefaultButton_Click(object sender, EventArgs e) private void DeviceFileSetButton_Click(object sender, EventArgs e) { - if (this.selectDeviceFileDialog == null) + this.selectDeviceFileDialog ??= new SaveFileDialog { - this.selectDeviceFileDialog = new SaveFileDialog - { - CreatePrompt = true, - DefaultExt = "mixdev", - Filter = "MIX device files|*.mixdev|All files|*.*", - OverwritePrompt = false - }; - } + CreatePrompt = true, + DefaultExt = "mixdev", + Filter = "MIX device files|*.mixdev|All files|*.*", + OverwritePrompt = false + }; var selectedItem = (DeviceFileComboBoxItem)this.deviceFileSelectionBox.SelectedItem; this.selectDeviceFileDialog.FileName = Path.Combine(GetCurrentDeviceFilesDirectory(), selectedItem.FilePath); @@ -1091,7 +1067,7 @@ private void SetTickCountValue() private void This_KeyPress(object sender, KeyPressEventArgs e) { - if (e.KeyChar == (char)Keys.Escape && !(GetFocusedControl() is IEscapeConsumer)) + if (e.KeyChar == (char)Keys.Escape && GetFocusedControl() is not IEscapeConsumer) { DialogResult = DialogResult.Cancel; Hide(); @@ -1271,22 +1247,15 @@ private void FloatingPointMemoryWordCountBox_ValueChanged(LongValueTextBox sourc /// /// Instances of this class are used to store the color settings /// - private class ColorComboBoxItem - { - private readonly string mDisplayName; - public bool IsDefault { get; private set; } - public string Name { get; private set; } - - private Color mSetColor; + private class ColorComboBoxItem(string name) + { + private readonly string mDisplayName = GetDisplayName(name); + public bool IsDefault { get; private set; } = true; + public string Name { get; private set; } = name; - public ColorComboBoxItem(string name) - { - Name = name; - mDisplayName = GetDisplayName(name); - IsDefault = true; - } + private Color mSetColor; - public bool IsBackground => !Name.EndsWith("Text", StringComparison.Ordinal); + public bool IsBackground => !Name.EndsWith("Text", StringComparison.Ordinal); public override string ToString() => mDisplayName; @@ -1324,14 +1293,12 @@ public Color Color /// /// Instances of this class are used to store the device file settings /// - private class DeviceFileComboBoxItem - { - private readonly FileBasedDevice mDevice; - private string mFilePath; - - public DeviceFileComboBoxItem(FileBasedDevice device) => mDevice = device; + private class DeviceFileComboBoxItem(FileBasedDevice device) + { + private readonly FileBasedDevice mDevice = device; + private string mFilePath; - public int Id => mDevice.Id; + public int Id => mDevice.Id; public bool IsDefault => mFilePath == null; @@ -1349,21 +1316,14 @@ public string FilePath /// /// Instances of this class are used to store the tick count settings /// - private class TickCountComboBoxItem - { - private readonly string mDisplayName; - private bool mIsDefault; - private readonly string mName; - private int mSetTickCount; - - public TickCountComboBoxItem(string name) - { - mName = name; - mDisplayName = GetDisplayName(name); - mIsDefault = true; - } + private class TickCountComboBoxItem(string name) + { + private readonly string mDisplayName = GetDisplayName(name); + private bool mIsDefault = true; + private readonly string mName = name; + private int mSetTickCount; - public bool IsDefault => mIsDefault; + public bool IsDefault => mIsDefault; public string Name => mName; @@ -1400,13 +1360,11 @@ public int TickCount } } - private class DeviceReloadIntervalComboBoxItem - { - public int MilliSeconds { get; set; } - - public DeviceReloadIntervalComboBoxItem(int milliSeconds) => MilliSeconds = milliSeconds; + private class DeviceReloadIntervalComboBoxItem(int milliSeconds) + { + public int MilliSeconds { get; set; } = milliSeconds; - public override string ToString() + public override string ToString() { if (MilliSeconds < 1000) return MilliSeconds.ToString("##0 ms"); diff --git a/src/MixEmul/Components/RegistersEditor.cs b/src/MixEmul/Components/RegistersEditor.cs index 2f677a0..b24f25b 100644 --- a/src/MixEmul/Components/RegistersEditor.cs +++ b/src/MixEmul/Components/RegistersEditor.cs @@ -51,8 +51,8 @@ public RegistersEditor(MixLib.Registers registers = null) this.compareLabel = new Label(); this.overflowLabel = new Label(); - this.editors = new List - { + this.editors = + [ (this.rAEditor = new WordValueEditor(this.registers.RA)), (this.rXEditor = new WordValueEditor(this.registers.RX)), (this.rI1Editor = new WordValueEditor(this.registers.RI1)), @@ -62,7 +62,7 @@ public RegistersEditor(MixLib.Registers registers = null) (this.r5Editor = new WordValueEditor(this.registers.RI5)), (this.rI6Editor = new WordValueEditor(this.registers.RI6)), (this.rJEditor = new WordValueEditor(this.registers.RJ, false)) - }; + ]; this.compareButton = new Button(); this.overflowBox = new CheckBox(); diff --git a/src/MixEmul/Components/SearchDialog.cs b/src/MixEmul/Components/SearchDialog.cs index 4159d1e..dde2c22 100644 --- a/src/MixEmul/Components/SearchDialog.cs +++ b/src/MixEmul/Components/SearchDialog.cs @@ -41,9 +41,7 @@ private void SetFindButtonEnabledState() private void FindButton_Click(object sender, EventArgs e) { - if (this.searchParameters == null) - this.searchParameters = new SearchParameters(); - + this.searchParameters ??= new SearchParameters(); this.searchParameters.SearchText = this.searchTextBox.MixByteCollectionValue.ToString(true).Trim(); this.searchParameters.SearchFields = FieldTypes.None; diff --git a/src/MixEmul/Components/SourceCodeControl.cs b/src/MixEmul/Components/SourceCodeControl.cs index b648cf0..0aa1069 100644 --- a/src/MixEmul/Components/SourceCodeControl.cs +++ b/src/MixEmul/Components/SourceCodeControl.cs @@ -14,12 +14,12 @@ public class SourceCodeControl : UserControl { private const string LineNumberSeparator = " │ "; private static readonly Color[] findingColors = - { + [ GuiSettings.GetColor(GuiSettings.DebugText), GuiSettings.GetColor(GuiSettings.InfoText), GuiSettings.GetColor(GuiSettings.WarningText), GuiSettings.GetColor(GuiSettings.ErrorText) - }; + ]; private Color addressColor; private Color commentColor; @@ -53,7 +53,7 @@ public SourceCodeControl() UpdateLayout(); - this.instructions = new List(); + this.instructions = []; this.lineNumberLength = 0; this.findingsColored = false; } @@ -337,18 +337,12 @@ private enum MarkOperation Mark } - private class ProcessedSourceLine - { - public ParsedSourceLine SourceLine { get; private set; } - public int LineTextIndex { get; private set; } - - public ProcessedSourceLine(ParsedSourceLine sourceLine, int lineTextIndex) - { - SourceLine = sourceLine; - LineTextIndex = lineTextIndex; - } + private class ProcessedSourceLine(ParsedSourceLine sourceLine, int lineTextIndex) + { + public ParsedSourceLine SourceLine { get; private set; } = sourceLine; + public int LineTextIndex { get; private set; } = lineTextIndex; - public int CommentTextIndex => + public int CommentTextIndex => !SourceLine.IsCommentLine ? AddressTextIndex + AddressTextLength + Parser.FieldSpacing : LineTextIndex; public int LineTextLength => diff --git a/src/MixEmul/Components/SymbolListView.cs b/src/MixEmul/Components/SymbolListView.cs index 5b386ef..d975441 100644 --- a/src/MixEmul/Components/SymbolListView.cs +++ b/src/MixEmul/Components/SymbolListView.cs @@ -102,9 +102,7 @@ public SymbolCollection Symbols public void AddSymbol(SymbolBase symbol) { - if (this.symbols == null) - this.symbols = new SymbolCollection(); - + this.symbols ??= []; this.symbols.Add(symbol); ShowSymbol(symbol); @@ -176,8 +174,7 @@ private void ListView_KeyPress(object sender, KeyPressEventArgs e) private void SetButton_Click(object sender, EventArgs e) { - if (this.symbols == null) - this.symbols = new SymbolCollection(); + this.symbols ??= []; string symbolName = this.symbolNameTextBox.Text; long symbolMagnitude = this.symbolValueTextBox.Magnitude; diff --git a/src/MixEmul/Components/ToolStripCycleButton.cs b/src/MixEmul/Components/ToolStripCycleButton.cs index 1b6acc6..344daf0 100644 --- a/src/MixEmul/Components/ToolStripCycleButton.cs +++ b/src/MixEmul/Components/ToolStripCycleButton.cs @@ -25,7 +25,7 @@ public ToolStripCycleButton() : base(new Button { Text = string.Empty, FlatStyle = FlatStyle.Flat, Height = 21, Padding = new Padding(0), TextAlign = ContentAlignment.TopCenter }) { InitializeComponent(); - this.steps = new List(); + this.steps = []; AutoSize = false; Size = Control.Size; Control.SizeChanged += Control_SizeChanged; @@ -112,11 +112,9 @@ public object Value if (value == null) return; - var step = this.steps.FirstOrDefault(s => s.Value is IComparable comparable ? comparable.CompareTo(value) == 0 : s.Value.Equals(value)); - - if (step == null) - throw new ArgumentException($"no step with Value {value} exists"); - + var step = this.steps.FirstOrDefault(s => s.Value is IComparable comparable ? comparable.CompareTo(value) == 0 : s.Value.Equals(value)) + ?? throw new ArgumentException($"no step with Value {value} exists"); + SetCurrentStep(step); } } @@ -131,24 +129,17 @@ private void SetCurrentStep(Step step) OnValueChanged(new EventArgs()); } - public class Step - { - public object Value { get; private set; } - public string Text { get; private set; } - public Step NextStep { get; set; } - - public Step(object value, string text) : this(value, text, null) { } + public class Step(object value, string text, Step nextStep) + { + public object Value { get; private set; } = value; + public string Text { get; private set; } = text; + public Step NextStep { get; set; } = nextStep; - public Step(object value) : this(value, value.ToString(), null) { } + public Step(object value, string text) : this(value, text, null) { } - public Step(object value, Step nextStep) : this(value, value.ToString(), nextStep) { } + public Step(object value) : this(value, value.ToString(), null) { } - public Step(object value, string text, Step nextStep) - { - Value = value; - Text = text; - NextStep = nextStep; - } - } + public Step(object value, Step nextStep) : this(value, value.ToString(), nextStep) { } } + } } diff --git a/src/MixEmul/MixForm.cs b/src/MixEmul/MixForm.cs index 211d700..fa20427 100644 --- a/src/MixEmul/MixForm.cs +++ b/src/MixEmul/MixForm.cs @@ -28,7 +28,7 @@ public partial class MixForm : Form private const int MainMemoryEditorIndex = 0; private const int FloatingPointMemoryEditorIndex = 1; - private IContainer components; + private Container components; private AboutForm aboutForm; private readonly Configuration configuration; private readonly string defaultDirectory = Environment.CurrentDirectory; @@ -1282,13 +1282,10 @@ private void LoadProgram(string filePath) var instances = Assembler.Assemble(File.ReadAllLines(filePath), out PreInstruction[] instructions, out SymbolCollection symbols, out AssemblyFindingCollection findings); if (instructions != null && findings != null) { - if (this.sourceAndFindingsForm == null) + this.sourceAndFindingsForm ??= new SourceAndFindingsForm { - this.sourceAndFindingsForm = new SourceAndFindingsForm - { - SeverityImageList = this.severityImageList - }; - } + SeverityImageList = this.severityImageList + }; this.sourceAndFindingsForm.SetInstructionsAndFindings(instructions, instances, findings); @@ -1424,9 +1421,7 @@ private void UpdateDeviceConfig() foreach (var device in this.mix.Devices.OfType()) { - device.FilePath = this.configuration.DeviceFilePaths.ContainsKey(device.Id) - ? this.configuration.DeviceFilePaths[device.Id] - : null; + device.FilePath = this.configuration.DeviceFilePaths.TryGetValue(device.Id, out var path) ? path : null; } }