Skip to content

Commit

Permalink
Tools: Annotate NRTs (#24226)
Browse files Browse the repository at this point in the history
Part of #19007
  • Loading branch information
bricelam authored Feb 23, 2021
1 parent 39d0036 commit 3278828
Show file tree
Hide file tree
Showing 46 changed files with 356 additions and 324 deletions.
4 changes: 3 additions & 1 deletion src/EFCore.Design/Design/IOperationResultHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

using JetBrains.Annotations;

#nullable enable

namespace Microsoft.EntityFrameworkCore.Design
{
/// <summary>
Expand All @@ -20,7 +22,7 @@ public interface IOperationResultHandler
/// Invoked when a result is available.
/// </summary>
/// <param name="value"> The result. </param>
void OnResult([CanBeNull] object value);
void OnResult([CanBeNull] object? value);

/// <summary>
/// Invoked when an error occurs.
Expand Down
18 changes: 10 additions & 8 deletions src/EFCore.Design/Design/OperationReportHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,19 @@
using System;
using JetBrains.Annotations;

#nullable enable

namespace Microsoft.EntityFrameworkCore.Design
{
/// <summary>
/// Used to handle reported design-time activity.
/// </summary>
public class OperationReportHandler : MarshalByRefObject, IOperationReportHandler
{
private readonly Action<string> _errorHandler;
private readonly Action<string> _warningHandler;
private readonly Action<string> _informationHandler;
private readonly Action<string> _verboseHandler;
private readonly Action<string>? _errorHandler;
private readonly Action<string>? _warningHandler;
private readonly Action<string>? _informationHandler;
private readonly Action<string>? _verboseHandler;

/// <summary>
/// Gets the contract version of this handler.
Expand All @@ -31,10 +33,10 @@ public virtual int Version
/// <param name="informationHandler"> A callback for <see cref="OnInformation(string)" />. </param>
/// <param name="verboseHandler"> A callback for <see cref="OnVerbose(string)" />. </param>
public OperationReportHandler(
[CanBeNull] Action<string> errorHandler = null,
[CanBeNull] Action<string> warningHandler = null,
[CanBeNull] Action<string> informationHandler = null,
[CanBeNull] Action<string> verboseHandler = null)
[CanBeNull] Action<string>? errorHandler = null,
[CanBeNull] Action<string>? warningHandler = null,
[CanBeNull] Action<string>? informationHandler = null,
[CanBeNull] Action<string>? verboseHandler = null)
{
_errorHandler = errorHandler;
_warningHandler = warningHandler;
Expand Down
20 changes: 11 additions & 9 deletions src/EFCore.Design/Design/OperationResultHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

using System;

#nullable enable

namespace Microsoft.EntityFrameworkCore.Design
{
/// <summary>
Expand All @@ -11,10 +13,10 @@ namespace Microsoft.EntityFrameworkCore.Design
public class OperationResultHandler : MarshalByRefObject, IOperationResultHandler
{
private bool _hasResult;
private object _result;
private string _errorType;
private string _errorMessage;
private string _errorStackTrace;
private object? _result;
private string? _errorType;
private string? _errorMessage;
private string? _errorStackTrace;

/// <summary>
/// Gets the contract version of this handler.
Expand All @@ -34,21 +36,21 @@ public virtual bool HasResult
/// Gets the result.
/// </summary>
/// <value>The result.</value>
public virtual object Result
public virtual object? Result
=> _result;

/// <summary>
/// Gets the type of the exception if any.
/// </summary>
/// <value>The exception type.</value>
public virtual string ErrorType
public virtual string? ErrorType
=> _errorType;

/// <summary>
/// Gets the error message if any.
/// </summary>
/// <value>The error message.</value>
public virtual string ErrorMessage
public virtual string? ErrorMessage
=> _errorMessage;

/// <summary>
Expand All @@ -58,14 +60,14 @@ public virtual string ErrorMessage
/// <remarks>
/// When an <see cref="OperationException" /> is received, the stack trace should not be shown by default.
/// </remarks>
public virtual string ErrorStackTrace
public virtual string? ErrorStackTrace
=> _errorStackTrace;

/// <summary>
/// Invoked when a result is available.
/// </summary>
/// <param name="value"> The result. </param>
public virtual void OnResult(object value)
public virtual void OnResult(object? value)
{
_hasResult = true;
_result = value;
Expand Down
6 changes: 3 additions & 3 deletions src/dotnet-ef/Exe.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ internal static class Exe
public static int Run(
string executable,
IReadOnlyList<string> args,
string workingDirectory = null,
string? workingDirectory = null,
bool interceptOutput = false)
{
var arguments = ToArguments(args);
Expand All @@ -28,11 +28,11 @@ public static int Run(
startInfo.WorkingDirectory = workingDirectory;
}

var process = Process.Start(startInfo);
var process = Process.Start(startInfo)!;

if (interceptOutput)
{
string line;
string? line;
while ((line = process.StandardOutput.ReadLine()) != null)
{
Reporter.WriteVerbose(line);
Expand Down
40 changes: 20 additions & 20 deletions src/dotnet-ef/Project.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ namespace Microsoft.EntityFrameworkCore.Tools
internal class Project
{
private readonly string _file;
private readonly string _framework;
private readonly string _configuration;
private readonly string _runtime;
private readonly string? _framework;
private readonly string? _configuration;
private readonly string? _runtime;

public Project(string file, string framework, string configuration, string runtime)
public Project(string file, string? framework, string? configuration, string? runtime)
{
Debug.Assert(!string.IsNullOrEmpty(file), "file is null or empty.");

Expand All @@ -29,29 +29,29 @@ public Project(string file, string framework, string configuration, string runti

public string ProjectName { get; }

public string AssemblyName { get; set; }
public string Language { get; set; }
public string OutputPath { get; set; }
public string PlatformTarget { get; set; }
public string ProjectAssetsFile { get; set; }
public string ProjectDir { get; set; }
public string RootNamespace { get; set; }
public string RuntimeFrameworkVersion { get; set; }
public string TargetFileName { get; set; }
public string TargetFrameworkMoniker { get; set; }
public string? AssemblyName { get; set; }
public string? Language { get; set; }
public string? OutputPath { get; set; }
public string? PlatformTarget { get; set; }
public string? ProjectAssetsFile { get; set; }
public string? ProjectDir { get; set; }
public string? RootNamespace { get; set; }
public string? RuntimeFrameworkVersion { get; set; }
public string? TargetFileName { get; set; }
public string? TargetFrameworkMoniker { get; set; }

public static Project FromFile(
string file,
string buildExtensionsDir,
string framework = null,
string configuration = null,
string runtime = null)
string? buildExtensionsDir,
string? framework = null,
string? configuration = null,
string? runtime = null)
{
Debug.Assert(!string.IsNullOrEmpty(file), "file is null or empty.");

if (buildExtensionsDir == null)
{
buildExtensionsDir = Path.Combine(Path.GetDirectoryName(file), "obj");
buildExtensionsDir = Path.Combine(Path.GetDirectoryName(file)!, "obj");
}

Directory.CreateDirectory(buildExtensionsDir);
Expand All @@ -60,7 +60,7 @@ public static Project FromFile(
buildExtensionsDir,
Path.GetFileName(file) + ".EntityFrameworkCore.targets");
using (var input = typeof(Resources).Assembly.GetManifestResourceStream(
"Microsoft.EntityFrameworkCore.Tools.Resources.EntityFrameworkCore.targets"))
"Microsoft.EntityFrameworkCore.Tools.Resources.EntityFrameworkCore.targets")!)
using (var output = File.OpenWrite(efTargetsPath))
{
// NB: Copy always in case it changes
Expand Down
14 changes: 7 additions & 7 deletions src/dotnet-ef/ProjectOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ namespace Microsoft.EntityFrameworkCore.Tools
{
internal class ProjectOptions
{
public CommandOption Project { get; private set; }
public CommandOption StartupProject { get; private set; }
public CommandOption Framework { get; private set; }
public CommandOption Configuration { get; private set; }
public CommandOption Runtime { get; private set; }
public CommandOption MSBuildProjectExtensionsPath { get; private set; }
public CommandOption NoBuild { get; private set; }
public CommandOption? Project { get; private set; }
public CommandOption? StartupProject { get; private set; }
public CommandOption? Framework { get; private set; }
public CommandOption? Configuration { get; private set; }
public CommandOption? Runtime { get; private set; }
public CommandOption? MSBuildProjectExtensionsPath { get; private set; }
public CommandOption? NoBuild { get; private set; }

public void Configure(CommandLineApplication command)
{
Expand Down
Loading

0 comments on commit 3278828

Please sign in to comment.