Skip to content

Commit

Permalink
Updated to C# 6.
Browse files Browse the repository at this point in the history
  • Loading branch information
RoqueDeicide committed Mar 20, 2016
1 parent e2b0f4c commit ce9be5e
Show file tree
Hide file tree
Showing 26 changed files with 207 additions and 265 deletions.
6 changes: 3 additions & 3 deletions Launcher/App.config
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1"/>
</startup>
</configuration>
</configuration>
66 changes: 26 additions & 40 deletions Launcher/Databases/Database.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,20 +98,17 @@ public DatabaseEntry this[string name]
/// <summary>
/// Gets the extension that marks files that store database entries in binary format.
/// </summary>
public string BinaryFileExtension { get; private set; }
public string BinaryFileExtension { get; }

/// <summary>
/// Gets the extension that marks files that store database entries in Xml format.
/// </summary>
public string XmlFileExtension { get; private set; }
public string XmlFileExtension { get; }

/// <summary>
/// Gets amount of entries in this database.
/// </summary>
public int Count
{
get { return this.TopLevelEntries.Count; }
}
public int Count => this.TopLevelEntries.Count;
#endregion
#region Events
#endregion
Expand Down Expand Up @@ -214,7 +211,7 @@ public void Save(string file)
}

string rawExtension = System.IO.Path.GetExtension(file);
string extension = rawExtension != null ? rawExtension.Substring(1) : null;
string extension = rawExtension?.Substring(1);

if (extension == this.BinaryFileExtension)
{
Expand All @@ -227,9 +224,7 @@ public void Save(string file)
else
{
throw new ArgumentException(
string.Format(
"Database.Save: Unable to recognize file extension. Use [{0}] for Xml files and [{1}] for binaries. File that has been attempted to be saved: [{2}]. Extension is [{3}]",
this.XmlFileExtension, this.BinaryFileExtension, file, extension));
$"Database.Save: Unable to recognize file extension. Use [{this.XmlFileExtension}] for Xml files and [{this.BinaryFileExtension}] for binaries. File that has been attempted to be saved: [{file}]. Extension is [{extension}]");
}
}
/// <summary>
Expand All @@ -246,7 +241,7 @@ public void Load(string file)
}

string rawExtension = System.IO.Path.GetExtension(file);
string extension = rawExtension != null ? rawExtension.Substring(1) : null;
string extension = rawExtension?.Substring(1);

if (extension == this.BinaryFileExtension)
{
Expand All @@ -259,9 +254,7 @@ public void Load(string file)
else
{
throw new ArgumentException(
string.Format(
"Database.Load: Unable to recognize file extension. Use [{0}] for Xml files and [{1}] for binaries. File that has been attempted to be loaded: [{2}]. Recognized extension is [{3}]",
this.XmlFileExtension, this.BinaryFileExtension, file, extension));
$"Database.Load: Unable to recognize file extension. Use [{this.XmlFileExtension}] for Xml files and [{this.BinaryFileExtension}] for binaries. File that has been attempted to be loaded: [{file}]. Recognized extension is [{extension}]");
}
}
#endregion
Expand Down Expand Up @@ -310,8 +303,7 @@ private void LoadBinary(string file)
{
if (br.ReadInt32() != DatabaseGlobals.BinaryDatabaseFileIdentifier)
{
throw new ArgumentException(string.Format(
"Database.LoadBinary: Unable to recognize format of the file. File: {0}", file));
throw new ArgumentException($"Database.LoadBinary: Unable to recognize format of the file. File: {file}");
}
while (br.ReadInt32() != DatabaseGlobals.BinaryDatabaseFileEndMarker)
{
Expand Down Expand Up @@ -381,7 +373,7 @@ public class DatabaseEntry
/// <summary>
/// Gets sorted list of subentries.
/// </summary>
public SortedList<string, DatabaseEntry> SubEntries { get; private set; }
public SortedList<string, DatabaseEntry> SubEntries { get; }

/// <summary>
/// Provides read/write access to the subentry with specified name.
Expand Down Expand Up @@ -521,15 +513,13 @@ public void FromBinary(BinaryReader br)
{
EntryContentAttribute contentType =
DatabaseGlobals.RegisteredContentTypes.Find(x => x.TypeHash == br.ReadInt32());
if (contentType != null)

ConstructorInfo constructor =
contentType?.AttributedClass.GetConstructor(Type.EmptyTypes);
if (constructor != null)
{
ConstructorInfo constructor =
contentType.AttributedClass.GetConstructor(Type.EmptyTypes);
if (constructor != null)
{
this.Content = (DatabaseEntryContent)constructor.Invoke(null);
this.Content.FromBinary(br);
}
this.Content = (DatabaseEntryContent)constructor.Invoke(null);
this.Content.FromBinary(br);
}
}
// Read subentries.
Expand Down Expand Up @@ -617,16 +607,14 @@ public void FromXml(XmlElement element)
XmlElement contentElement = children[0];
EntryContentAttribute contentType =
DatabaseGlobals.RegisteredContentTypes.Find(x => x.TypeName == contentElement.Name);
if (contentType != null)

ConstructorInfo constructor =
contentType?.AttributedClass.GetConstructor(Type.EmptyTypes);
if (constructor != null)
{
ConstructorInfo constructor =
contentType.AttributedClass.GetConstructor(Type.EmptyTypes);
if (constructor != null)
{
this.Content = (DatabaseEntryContent)constructor.Invoke(null);
this.Content.FromXml(contentElement);
minimalAmountOfChildNodes++;
}
this.Content = (DatabaseEntryContent)constructor.Invoke(null);
this.Content.FromXml(contentElement);
minimalAmountOfChildNodes++;
}
}
if (element.ChildNodes.Count > minimalAmountOfChildNodes)
Expand Down Expand Up @@ -687,17 +675,17 @@ public sealed class EntryContentAttribute : Attribute
/// <summary>
/// Gets identifier of the class.
/// </summary>
public int TypeHash { get; private set; }
public int TypeHash { get; }

/// <summary>
/// Gets the name of the type of content.
/// </summary>
public string TypeName { get; private set; }
public string TypeName { get; }

/// <summary>
/// Gets class to which this attribute is applied.
/// </summary>
public Type AttributedClass { get; private set; }
public Type AttributedClass { get; }

/// <summary>
/// Creates new instance of <see cref="EntryContentAttribute"/> class.
Expand All @@ -717,9 +705,7 @@ public EntryContentAttribute(string name, Type type)
if (other != null)
{
throw new Exception(
string.Format(
"Unable to register database entry content type with name that has the same hash value as one of the existing ones. New name = {0}, old name = {1}",
this.TypeName, other.TypeName));
$"Unable to register database entry content type with name that has the same hash value as one of the existing ones. New name = {this.TypeName}, old name = {other.TypeName}");
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion Launcher/Extensions/PathUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ private static string EndWithBackSlashInternal(string folderPath)
{
return folderPath.EndsWith("\\")
? folderPath
: string.Format("{0}\\", folderPath);
: $"{folderPath}\\";
}
}
}
12 changes: 2 additions & 10 deletions Launcher/ExtraControls/ExtraFilesSelectionBox.Buttons.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,8 @@ private void ToggleFileSelection(object sender, RoutedEventArgs routedEventArgs)
private void MoveSelectedFileUp(object sender, RoutedEventArgs routedEventArgs)
{
SpinnerButtons buttons = sender as SpinnerButtons;
if (buttons == null)
{
return;
}

FileDesc fileDesc = buttons.DataContext as FileDesc;
FileDesc fileDesc = buttons?.DataContext as FileDesc;
if (fileDesc == null)
{
return;
Expand All @@ -70,12 +66,8 @@ private void MoveSelectedFileUp(object sender, RoutedEventArgs routedEventArgs)
private void MoveSelectedFileDown(object sender, RoutedEventArgs routedEventArgs)
{
SpinnerButtons buttons = sender as SpinnerButtons;
if (buttons == null)
{
return;
}

FileDesc fileDesc = buttons.DataContext as FileDesc;
FileDesc fileDesc = buttons?.DataContext as FileDesc;
if (fileDesc == null)
{
return;
Expand Down
18 changes: 7 additions & 11 deletions Launcher/ExtraControls/ExtraFilesSelectionBox.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ namespace Launcher
/// </summary>
public partial class ExtraFilesSelectionBox
{
private readonly ObservableCollection<object> fileSelection;
private List<string> selectedFiles;
/// <summary>
/// Gets the list of files that are currently selected.
Expand Down Expand Up @@ -52,16 +51,13 @@ public List<string> SelectedFiles
/// <summary>
/// Gets the observable collection that contains information about selected files.
/// </summary>
public ObservableCollection<object> FileSelection
{
get { return this.fileSelection; }
}
public ObservableCollection<object> FileSelection { get; }
/// <summary>
/// Creates a user control.
/// </summary>
public ExtraFilesSelectionBox()
{
this.fileSelection = new ObservableCollection<object>();
this.FileSelection = new ObservableCollection<object>();

this.InitializeComponent();

Expand All @@ -83,11 +79,11 @@ private void UpdatedSelectedFiles(object sender, NotifyCollectionChangedEventArg

private void ClearSelection()
{
foreach (FileDesc file in this.fileSelection.OfType<FileDesc>())
foreach (FileDesc file in this.FileSelection.OfType<FileDesc>())
{
file.Selected = false;
}
this.fileSelection.Clear();
this.FileSelection.Clear();
}
private void RemoveUnavailableSelection(object sender, NotifyCollectionChangedEventArgs args)
{
Expand All @@ -97,16 +93,16 @@ private void RemoveUnavailableSelection(object sender, NotifyCollectionChangedEv
case NotifyCollectionChangedAction.Replace:
case NotifyCollectionChangedAction.Reset:

for (int i = 0; i < this.fileSelection.Count; i++)
for (int i = 0; i < this.FileSelection.Count; i++)
{
FileDesc file = this.fileSelection[i] as FileDesc;
FileDesc file = this.FileSelection[i] as FileDesc;

Debug.Assert(file != null, "file != null");

if (!ExtraFilesLookUp.LoadableFiles.Contains(file))
{
file.Selected = false;
this.fileSelection.RemoveAt(i--);
this.FileSelection.RemoveAt(i--);
}
}

Expand Down
2 changes: 1 addition & 1 deletion Launcher/ExtraControls/IwadComboBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class IwadComboBox : ComboBox
/// <summary>
/// Gets the collection of available IWAD files.
/// </summary>
public ObservableCollection<IwadFile> Files { get; private set; }
public ObservableCollection<IwadFile> Files { get; }
/// <summary>
/// Creates a new instance of this type.
/// </summary>
Expand Down
4 changes: 2 additions & 2 deletions Launcher/ExtraControls/NumericUpDown.cs
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ public override void OnApplyTemplate()
this.Loaded += (sender, args) =>
{
this.valueIsCommited = true;
this.valueBox.Text = this.Value == null ? "" : this.Value.ToString();
this.valueBox.Text = this.Value?.ToString() ?? "";
this.UpdateButtons();
};
Expand Down Expand Up @@ -402,7 +402,7 @@ private void CommitText(string value)
protected virtual void OnValueChanged(int? oldvalue, int? newvalue)
{
var handler = this.ValueChanged;
if (handler != null) handler(this, oldvalue, newvalue);
handler?.Invoke(this, oldvalue, newvalue);
}
private void UpdateButtons()
{
Expand Down
3 changes: 2 additions & 1 deletion Launcher/ExtraControls/SpinnerButton.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ public PointCollection Geometry
}
static SpinnerButton()
{
DefaultStyleKeyProperty.OverrideMetadata(typeof(SpinnerButton), new FrameworkPropertyMetadata(typeof(SpinnerButton)));
DefaultStyleKeyProperty.OverrideMetadata(typeof(SpinnerButton),
new FrameworkPropertyMetadata(typeof(SpinnerButton)));
}
}
}
4 changes: 2 additions & 2 deletions Launcher/ExtraControls/SpinnerButtons.cs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ public override void OnApplyTemplate()
protected virtual void OnClickUp(RoutedEventArgs e)
{
var handler = this.ClickUp;
if (handler != null) handler(this, e);
handler?.Invoke(this, e);
}
/// <summary>
/// Raises <see cref="ClickDown"/> event.
Expand All @@ -149,7 +149,7 @@ protected virtual void OnClickUp(RoutedEventArgs e)
protected virtual void OnClickDown(RoutedEventArgs e)
{
var handler = this.ClickDown;
if (handler != null) handler(this, e);
handler?.Invoke(this, e);
}
#endregion
}
Expand Down
3 changes: 2 additions & 1 deletion Launcher/ExtraControls/TextBoxButton.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ public class TextBoxButton : Button
{
static TextBoxButton()
{
DefaultStyleKeyProperty.OverrideMetadata(typeof(TextBoxButton), new FrameworkPropertyMetadata(typeof(TextBoxButton)));
DefaultStyleKeyProperty.OverrideMetadata(typeof(TextBoxButton),
new FrameworkPropertyMetadata(typeof(TextBoxButton)));
}
}
}
3 changes: 1 addition & 2 deletions Launcher/ExtraWindows/Directories.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@
ItemContainerStyle="{StaticResource DirectoryItem}"
Background="{DynamicResource {x:Static SystemColors.AppWorkspaceBrushKey}}"
BorderThickness="0" HorizontalContentAlignment="Stretch"
ItemTemplate="{StaticResource DirectoryLineTemplate}">
</ListBox>
ItemTemplate="{StaticResource DirectoryLineTemplate}" />
</ScrollViewer>
</Window>
Loading

0 comments on commit ce9be5e

Please sign in to comment.