From 90b24e547d81e28cc8ee54dba1c904215ff6dcd8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Holger=20B=C3=B6rchers?= Date: Fri, 1 Jan 2021 22:38:09 +0100 Subject: [PATCH] fixed csproj dependencies --- App/ContentDialogExample.xaml.cs | 4 ++-- App/MainWindowViewModel.cs | 4 ++-- App/ModernWpfPlayground.csproj | 2 -- App/MvvmStuff/BaseViewModel.cs | 6 +++--- Controls/Controls.csproj | 5 +---- Controls/PropertyPresenter/EnumToKeyValueListConverter.cs | 8 +++++--- Controls/PropertyPresenter/MagicSymbolConverter.cs | 6 +++--- Controls/PropertyPresenter/ValueConverter.cs | 2 +- 8 files changed, 17 insertions(+), 20 deletions(-) diff --git a/App/ContentDialogExample.xaml.cs b/App/ContentDialogExample.xaml.cs index d591439..57994ad 100644 --- a/App/ContentDialogExample.xaml.cs +++ b/App/ContentDialogExample.xaml.cs @@ -7,9 +7,9 @@ namespace ModernWpfPlayground public static readonly DependencyProperty MessageProperty = DependencyProperty.Register( "Message", typeof(string), typeof(ContentDialogExample), new PropertyMetadata(default(string))); - public string Message + public string? Message { - get => (string) GetValue(MessageProperty); + get => (string?) GetValue(MessageProperty); set => SetValue(MessageProperty, value); } diff --git a/App/MainWindowViewModel.cs b/App/MainWindowViewModel.cs index 6131b3f..5629ef0 100644 --- a/App/MainWindowViewModel.cs +++ b/App/MainWindowViewModel.cs @@ -75,7 +75,7 @@ namespace ModernWpfPlayground public ICommand ShowDialogCommand { get; } - public string WelcomeMessage + public string? WelcomeMessage { get => GetProperty("Shadow of the empire"); set => SetProperty(value); @@ -137,7 +137,7 @@ namespace ModernWpfPlayground private void SaveViewModel() { var contents = _serializer.Serialize(Values); - if (Path == null) + if (Path is null) { var saveFileDialog = new SaveFileDialog {AddExtension = true, DefaultExt = "*.yaml"}; var result = saveFileDialog.ShowDialog(Application.Current.MainWindow?.Owner); diff --git a/App/ModernWpfPlayground.csproj b/App/ModernWpfPlayground.csproj index 7d45f0a..6e0ab45 100644 --- a/App/ModernWpfPlayground.csproj +++ b/App/ModernWpfPlayground.csproj @@ -15,8 +15,6 @@ - - diff --git a/App/MvvmStuff/BaseViewModel.cs b/App/MvvmStuff/BaseViewModel.cs index db3993a..7f248d9 100644 --- a/App/MvvmStuff/BaseViewModel.cs +++ b/App/MvvmStuff/BaseViewModel.cs @@ -14,9 +14,9 @@ namespace ModernWpfPlayground.MvvmStuff ObjectAccessor = ObjectAccessor.Create(this); } - private readonly Dictionary _values = new Dictionary(); + private readonly Dictionary _values = new(); protected readonly ObjectAccessor ObjectAccessor; - private readonly Dictionary _defaultValues = new Dictionary(); + private readonly Dictionary _defaultValues = new(); protected IReadOnlyDictionary Values => _values; @@ -32,7 +32,7 @@ namespace ModernWpfPlayground.MvvmStuff return true; } - protected T GetProperty(T defaultValue = default, [CallerMemberName] string? propertyName = null) + protected T? GetProperty(T? defaultValue = default, [CallerMemberName] string? propertyName = null) { if (propertyName == null) throw new ArgumentNullException(nameof(propertyName)); if (Values.TryGetValue(propertyName, out var obj)) diff --git a/Controls/Controls.csproj b/Controls/Controls.csproj index e6553ca..f6df3a4 100644 --- a/Controls/Controls.csproj +++ b/Controls/Controls.csproj @@ -1,16 +1,13 @@  - net5.0-windows10.0.18362.0 + net5.0-windows true enable - - - diff --git a/Controls/PropertyPresenter/EnumToKeyValueListConverter.cs b/Controls/PropertyPresenter/EnumToKeyValueListConverter.cs index cdd0a8f..bb7fa9e 100644 --- a/Controls/PropertyPresenter/EnumToKeyValueListConverter.cs +++ b/Controls/PropertyPresenter/EnumToKeyValueListConverter.cs @@ -26,10 +26,12 @@ namespace Controls /// private static string GetDescription(object value) { - if (!(value is Enum enumValue)) return string.Empty; + if (value is not Enum enumValue) return string.Empty; var descriptionAttribute = enumValue.GetType() - .GetField(enumValue.ToString())?.GetCustomAttributes(false) - .OfType().FirstOrDefault(); + .GetField(enumValue.ToString())? + .GetCustomAttributes(false) + .OfType() + .FirstOrDefault(); return descriptionAttribute?.Description ?? value.ToString() ?? string.Empty; } diff --git a/Controls/PropertyPresenter/MagicSymbolConverter.cs b/Controls/PropertyPresenter/MagicSymbolConverter.cs index f65c217..acffbc1 100644 --- a/Controls/PropertyPresenter/MagicSymbolConverter.cs +++ b/Controls/PropertyPresenter/MagicSymbolConverter.cs @@ -36,11 +36,11 @@ namespace Controls var data = value as string; if (string.IsNullOrWhiteSpace(data)) return value; //maybe not a string. eventually something else. - if (data.StartsWith(NoParseKeyword, StringComparison.Ordinal)) return data.Substring(NoParseKeyword.Length); + if (data.StartsWith(NoParseKeyword, StringComparison.Ordinal)) return data[NoParseKeyword.Length..]; if (data.StartsWith(PathKeyword, StringComparison.Ordinal)) { - var path = data.Substring(PathKeyword.Length); + var path = data[PathKeyword.Length..]; var icon = ObjectImageConverter.GetIcon(Geometry.Parse(path), Brushes.Black); return new Image { @@ -53,7 +53,7 @@ namespace Controls if (data.StartsWith(DynResKeyword, StringComparison.Ordinal)) { - var resourceKey = data.Substring(DynResKeyword.Length); + var resourceKey = data[DynResKeyword.Length..]; //get icon from resource dictionary return new Image { diff --git a/Controls/PropertyPresenter/ValueConverter.cs b/Controls/PropertyPresenter/ValueConverter.cs index 7701a90..7da8804 100644 --- a/Controls/PropertyPresenter/ValueConverter.cs +++ b/Controls/PropertyPresenter/ValueConverter.cs @@ -26,7 +26,7 @@ namespace Controls return System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(bitmap.GetHbitmap(), IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromWidthAndHeight(16, 16)); } - if (!(value is string strValue)) return Binding.DoNothing; + if (value is not string strValue) return Binding.DoNothing; if (strValue.StartsWith(dynResPrefix, StringComparison.Ordinal)) { var resource = Application.Current.TryFindResource(strValue.Replace(dynResPrefix, string.Empty , StringComparison.InvariantCulture));