From 2c5f43b9f4162c04ae1096491194d28668b11f8d Mon Sep 17 00:00:00 2001 From: Rustam Sayfutdinov Date: Thu, 4 Nov 2021 11:49:19 +0300 Subject: [PATCH] Refactoring --- .../AvaloniaProjectInfoResolver.App.csproj | 2 +- .../AvaloniaProjectInfoTypes.cs | 7 ++++--- .../ContextAwareTask.cs | 6 +++--- .../PreviewInfoResolverTask.cs | 13 +++++++++---- 4 files changed, 17 insertions(+), 11 deletions(-) diff --git a/src/AvaloniaProjectInfoResolver.App/AvaloniaProjectInfoResolver.App.csproj b/src/AvaloniaProjectInfoResolver.App/AvaloniaProjectInfoResolver.App.csproj index 8407f77..5337f4e 100644 --- a/src/AvaloniaProjectInfoResolver.App/AvaloniaProjectInfoResolver.App.csproj +++ b/src/AvaloniaProjectInfoResolver.App/AvaloniaProjectInfoResolver.App.csproj @@ -2,7 +2,7 @@ WinExe netcoreapp3.1 - 0.10.2 + 0.10.10 diff --git a/src/AvaloniaProjectInfoResolver.PreviewTask/AvaloniaProjectInfoTypes.cs b/src/AvaloniaProjectInfoResolver.PreviewTask/AvaloniaProjectInfoTypes.cs index 3c6e9a1..f3f017e 100644 --- a/src/AvaloniaProjectInfoResolver.PreviewTask/AvaloniaProjectInfoTypes.cs +++ b/src/AvaloniaProjectInfoResolver.PreviewTask/AvaloniaProjectInfoTypes.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using System.Xml; using System.Xml.Schema; using System.Xml.Serialization; @@ -17,7 +18,7 @@ private static readonly XmlSerializer SerializerForXamlFileInfo public string AvaloniaPreviewerNetFullToolPath { get; internal set; } = string.Empty; - public IReadOnlyList AppExecInfoCollection { get; internal set; } = new AppExecInfo[0]; + public IReadOnlyList AppExecInfoCollection { get; internal set; } = Array.Empty(); public XamlFileInfo XamlFileInfo { get; internal set; } = new(); @@ -73,7 +74,7 @@ public class XamlFileInfo : IXmlSerializable public string AvaloniaXaml { get; internal set; } = string.Empty; - public IReadOnlyList ReferenceXamlFileInfoCollection { get; internal set; } = new XamlFileInfo[0]; + public IReadOnlyList ReferenceXamlFileInfoCollection { get; internal set; } = Array.Empty(); public XmlSchema? GetSchema() => null; diff --git a/src/AvaloniaProjectInfoResolver.PreviewTask/ContextAwareTask.cs b/src/AvaloniaProjectInfoResolver.PreviewTask/ContextAwareTask.cs index 1fc0654..0bfc47b 100644 --- a/src/AvaloniaProjectInfoResolver.PreviewTask/ContextAwareTask.cs +++ b/src/AvaloniaProjectInfoResolver.PreviewTask/ContextAwareTask.cs @@ -14,7 +14,7 @@ namespace AvaloniaProjectInfoResolver.PreviewTask public abstract class ContextAwareTask : Task { protected virtual string ManagedDllDirectory => - Path.GetDirectoryName(new Uri(GetType().GetTypeInfo().Assembly.CodeBase).LocalPath); + Path.GetDirectoryName(new Uri(GetType().GetTypeInfo().Assembly.CodeBase).LocalPath)!; protected virtual string? UnmanagedDllDirectory => null; @@ -46,8 +46,8 @@ from outerProperty in outerProperties.Values } var executeInnerMethod = - innerTaskType.GetMethod(nameof(ExecuteInner), BindingFlags.Instance | BindingFlags.NonPublic); - var result = (bool)executeInnerMethod.Invoke(innerTask, new object[0]); + innerTaskType.GetMethod(nameof(ExecuteInner), BindingFlags.Instance | BindingFlags.NonPublic)!; + var result = (bool)executeInnerMethod.Invoke(innerTask, Array.Empty()); foreach (var propertyPair in outputPropertiesMap) { diff --git a/src/AvaloniaProjectInfoResolver.PreviewTask/PreviewInfoResolverTask.cs b/src/AvaloniaProjectInfoResolver.PreviewTask/PreviewInfoResolverTask.cs index ac463c3..2169d97 100644 --- a/src/AvaloniaProjectInfoResolver.PreviewTask/PreviewInfoResolverTask.cs +++ b/src/AvaloniaProjectInfoResolver.PreviewTask/PreviewInfoResolverTask.cs @@ -105,7 +105,7 @@ protected override bool ExecuteInner() if (!TryResolvePreviewInfoTfms(ProjectFile, out var targetFrameworks)) return false; - if (!TryResolvePreviewInfoCommon(out var previewInfo, targetFrameworks)) + if (!TryResolvePreviewInfoCommon(targetFrameworks, out var previewInfo)) return false; var appExecInfoCollection = new List(targetFrameworks.Length); @@ -149,7 +149,8 @@ private bool TryResolvePreviewInfoTfms(string projectFile, out string[] targetFr return false; } - private bool TryResolvePreviewInfoCommon(out PreviewInfo previewInfo, string[] targetFrameworks) + // ReSharper disable once SuggestBaseTypeForParameter + private bool TryResolvePreviewInfoCommon(string[] targetFrameworks, out PreviewInfo previewInfo) { var targetOutputs = new Dictionary(); var props = GetGlobalProperties(targetFrameworks[0]); @@ -161,7 +162,7 @@ private bool TryResolvePreviewInfoCommon(out PreviewInfo previewInfo, string[] t } previewInfo = SelectPreviewInfoCommon(targetOutputs); - if (IsReferencesAvalonia(previewInfo)) + if (ShouldReferencesAvalonia(previewInfo)) { var xamlFileInfoCollection = ResolveReferenceXamlFileInfoCollection( previewInfo.XamlFileInfo.ProjectPath, props, new List()); @@ -177,10 +178,13 @@ private bool TryResolvePreviewInfoCommon(out PreviewInfo previewInfo, string[] t } private List ResolveReferenceXamlFileInfoCollection( + // ReSharper disable once SuggestBaseTypeForParameter + // ReSharper disable once ParameterTypeCanBeEnumerable.Local string parentProjectPath, Dictionary props, IReadOnlyList projectReadies) { var targetOutputs = new Dictionary(); var xamlFileInfoCollection = new List(); + // ReSharper disable once InvertIf if (BuildEngine.BuildProjectFile(parentProjectPath, TargetGetProjectReference, props, targetOutputs)) { var currentProjectDirectory = Directory.GetParent(parentProjectPath)!.FullName; @@ -193,6 +197,7 @@ private List ResolveReferenceXamlFileInfoCollection( foreach (var project in projectReferenceCollection) { var path = Path.Combine(currentProjectDirectory, project); + // ReSharper disable once InvertIf if (TryResolvePreviewInfoCommonProjectReference(path, projectReadiesInner, out var xamlFileInfo)) { xamlFileInfoCollection.Add(new XamlFileInfo @@ -265,7 +270,7 @@ private bool TryResolveAppExecInfo(out AppExecInfo appExecInfo, string targetFra return false; } - private static bool IsReferencesAvalonia(PreviewInfo previewInfo) => + private static bool ShouldReferencesAvalonia(PreviewInfo previewInfo) => !string.IsNullOrEmpty(previewInfo.AvaloniaPreviewerNetCoreToolPath) || !string.IsNullOrEmpty(previewInfo.AvaloniaPreviewerNetFullToolPath);