Skip to content

Commit

Permalink
Refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
rstm-sf committed Nov 4, 2021
1 parent e10f2d2 commit 2c5f43b
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<AvaloniaVersion>0.10.2</AvaloniaVersion>
<AvaloniaVersion>0.10.10</AvaloniaVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Avalonia" Version="$(AvaloniaVersion)" />
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -17,7 +18,7 @@ private static readonly XmlSerializer SerializerForXamlFileInfo

public string AvaloniaPreviewerNetFullToolPath { get; internal set; } = string.Empty;

public IReadOnlyList<AppExecInfo> AppExecInfoCollection { get; internal set; } = new AppExecInfo[0];
public IReadOnlyList<AppExecInfo> AppExecInfoCollection { get; internal set; } = Array.Empty<AppExecInfo>();

public XamlFileInfo XamlFileInfo { get; internal set; } = new();

Expand Down Expand Up @@ -73,7 +74,7 @@ public class XamlFileInfo : IXmlSerializable

public string AvaloniaXaml { get; internal set; } = string.Empty;

public IReadOnlyList<XamlFileInfo> ReferenceXamlFileInfoCollection { get; internal set; } = new XamlFileInfo[0];
public IReadOnlyList<XamlFileInfo> ReferenceXamlFileInfoCollection { get; internal set; } = Array.Empty<XamlFileInfo>();

public XmlSchema? GetSchema() => null;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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<object>());

foreach (var propertyPair in outputPropertiesMap)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<AppExecInfo>(targetFrameworks.Length);
Expand Down Expand Up @@ -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<string, ITaskItem[]>();
var props = GetGlobalProperties(targetFrameworks[0]);
Expand All @@ -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<string>());
Expand All @@ -177,10 +178,13 @@ private bool TryResolvePreviewInfoCommon(out PreviewInfo previewInfo, string[] t
}

private List<XamlFileInfo> ResolveReferenceXamlFileInfoCollection(
// ReSharper disable once SuggestBaseTypeForParameter
// ReSharper disable once ParameterTypeCanBeEnumerable.Local
string parentProjectPath, Dictionary<string, string> props, IReadOnlyList<string> projectReadies)
{
var targetOutputs = new Dictionary<string, ITaskItem[]>();
var xamlFileInfoCollection = new List<XamlFileInfo>();
// ReSharper disable once InvertIf
if (BuildEngine.BuildProjectFile(parentProjectPath, TargetGetProjectReference, props, targetOutputs))
{
var currentProjectDirectory = Directory.GetParent(parentProjectPath)!.FullName;
Expand All @@ -193,6 +197,7 @@ private List<XamlFileInfo> 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
Expand Down Expand Up @@ -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);

Expand Down

0 comments on commit 2c5f43b

Please sign in to comment.