Skip to content

Commit

Permalink
Bring back extension methods, fix formatting of xml doc comments (#144)
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffkl authored Nov 10, 2021
1 parent 6acd112 commit ca7e4b8
Show file tree
Hide file tree
Showing 36 changed files with 306 additions and 285 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace Microsoft.Build.Utilities.ProjectCreation.UnitTests
public class ExtensibilityTests : MSBuildTestBase
{
/// <summary>
/// Proves that <see cref="ProjectCreator"/> can be extended by and end user through extension methods.
/// Proves that <see cref="ProjectCreator" /> can be extended by and end user through extension methods.
/// </summary>
[Fact]
public void CustomExtensionMethod()
Expand Down
24 changes: 12 additions & 12 deletions src/Microsoft.Build.Utilities.ProjectCreation/BuildEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,51 +9,51 @@
namespace Microsoft.Build.Utilities.ProjectCreation
{
/// <summary>
/// Represents an implementation of <see cref="IBuildEngine"/> that allows for capturing logged events in tasks.
/// Represents an implementation of <see cref="IBuildEngine" /> that allows for capturing logged events in tasks.
/// </summary>
public sealed class BuildEngine : BuildEventArgsCollection, IBuildEngine
{
private BuildEngine()
{
}

/// <inheritdoc cref="IBuildEngine.ColumnNumberOfTaskNode"/>
/// <inheritdoc cref="IBuildEngine.ColumnNumberOfTaskNode" />
public int ColumnNumberOfTaskNode => 0;

/// <inheritdoc cref="IBuildEngine.ContinueOnError"/>
/// <inheritdoc cref="IBuildEngine.ContinueOnError" />
public bool ContinueOnError => false;

/// <inheritdoc cref="IBuildEngine.LineNumberOfTaskNode"/>
/// <inheritdoc cref="IBuildEngine.LineNumberOfTaskNode" />
public int LineNumberOfTaskNode => 0;

/// <inheritdoc cref="IBuildEngine.ProjectFileOfTaskNode"/>
/// <inheritdoc cref="IBuildEngine.ProjectFileOfTaskNode" />
public string? ProjectFileOfTaskNode => null;

/// <summary>
/// Creates an instance of the <see cref="BuildEngine"/> class.
/// Creates an instance of the <see cref="BuildEngine" /> class.
/// </summary>
/// <returns>A <see cref="BuildEngine"/> instance.</returns>
/// <returns>A <see cref="BuildEngine" /> instance.</returns>
public static BuildEngine Create()
{
return new BuildEngine();
}

/// <inheritdoc cref="IBuildEngine.BuildProjectFile"/>
/// <inheritdoc cref="IBuildEngine.BuildProjectFile" />
public bool BuildProjectFile(string projectFileName, string[] targetNames, IDictionary globalProperties, IDictionary targetOutputs)
{
throw new NotSupportedException();
}

/// <inheritdoc cref="IBuildEngine.LogCustomEvent"/>
/// <inheritdoc cref="IBuildEngine.LogCustomEvent" />
public void LogCustomEvent(CustomBuildEventArgs e) => Add(e);

/// <inheritdoc cref="IBuildEngine.LogErrorEvent"/>
/// <inheritdoc cref="IBuildEngine.LogErrorEvent" />
public void LogErrorEvent(BuildErrorEventArgs e) => Add(e);

/// <inheritdoc cref="IBuildEngine.LogMessageEvent"/>
/// <inheritdoc cref="IBuildEngine.LogMessageEvent" />
public void LogMessageEvent(BuildMessageEventArgs e) => Add(e);

/// <inheritdoc cref="IBuildEngine.LogWarningEvent"/>
/// <inheritdoc cref="IBuildEngine.LogWarningEvent" />
public void LogWarningEvent(BuildWarningEventArgs e) => Add(e);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
namespace Microsoft.Build.Utilities.ProjectCreation
{
/// <summary>
/// Represents a collection of <see cref="BuildEventArgs"/> objects.
/// Represents a collection of <see cref="BuildEventArgs" /> objects.
/// </summary>
public abstract class BuildEventArgsCollection : IDisposable
{
Expand All @@ -38,7 +38,7 @@ public abstract class BuildEventArgsCollection : IDisposable
private readonly ConcurrentQueue<BuildEventArgs> _allEvents = new ConcurrentQueue<BuildEventArgs>();

/// <summary>
/// Initializes a new instance of the <see cref="BuildEventArgsCollection"/> class.
/// Initializes a new instance of the <see cref="BuildEventArgsCollection" /> class.
/// </summary>
protected BuildEventArgsCollection()
{
Expand Down Expand Up @@ -67,7 +67,7 @@ protected BuildEventArgsCollection()
public BuildMessageEventArgsCollection MessageEvents { get; }

/// <summary>
/// Gets a <see cref="BuildMessageCollection"/> object that gets the messages from the build.
/// Gets a <see cref="BuildMessageCollection" /> object that gets the messages from the build.
/// </summary>
public BuildMessageCollection Messages { get; }

Expand All @@ -81,7 +81,7 @@ protected BuildEventArgsCollection()
/// </summary>
public IReadOnlyCollection<string> Warnings => _warningEvents.Select(i => i.Message).ToList();

/// <inheritdoc cref="IDisposable.Dispose"/>
/// <inheritdoc cref="IDisposable.Dispose" />
public virtual void Dispose()
{
_errorEvents.Clear();
Expand Down Expand Up @@ -160,7 +160,7 @@ public string GetConsoleLog(LoggerVerbosity verbosity = LoggerVerbosity.Normal)
/// <summary>
/// Adds a build event.
/// </summary>
/// <param name="buildEventArgs">A <see cref="BuildEventArgs"/> object to add.</param>
/// <param name="buildEventArgs">A <see cref="BuildEventArgs" /> object to add.</param>
protected void Add(BuildEventArgs buildEventArgs)
{
_allEvents.Enqueue(buildEventArgs);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,39 +18,39 @@ public sealed class BuildMessageCollection : IReadOnlyCollection<string>
private readonly BuildEventArgsCollection _buildOutput;

/// <summary>
/// Initializes a new instance of the <see cref="BuildMessageCollection"/> class.
/// Initializes a new instance of the <see cref="BuildMessageCollection" /> class.
/// </summary>
/// <param name="buildOutput">The <see cref="BuildEventArgsCollection"/> object that has message events.</param>
/// <param name="buildOutput">The <see cref="BuildEventArgsCollection" /> object that has message events.</param>
internal BuildMessageCollection(BuildEventArgsCollection buildOutput)
{
_buildOutput = buildOutput ?? throw new ArgumentNullException(nameof(buildOutput));
}

/// <inheritdoc cref="IReadOnlyCollection{T}.Count"/>
/// <inheritdoc cref="IReadOnlyCollection{T}.Count" />
public int Count => _buildOutput.MessageEvents.Count;

/// <summary>
/// Gets the messages that were logged with <see cref="MessageImportance.High"/>.
/// Gets the messages that were logged with <see cref="MessageImportance.High" />.
/// </summary>
public IReadOnlyCollection<string> High => _buildOutput.MessageEvents.High.Select(i => i.Message).ToList();

/// <summary>
/// Gets the messages that were logged with <see cref="MessageImportance.Low"/>.
/// Gets the messages that were logged with <see cref="MessageImportance.Low" />.
/// </summary>
public IReadOnlyCollection<string> Low => _buildOutput.MessageEvents.Low.Select(i => i.Message).ToList();

/// <summary>
/// Gets the messages that were logged with <see cref="MessageImportance.Normal"/>.
/// Gets the messages that were logged with <see cref="MessageImportance.Normal" />.
/// </summary>
public IReadOnlyCollection<string> Normal => _buildOutput.MessageEvents.Normal.Select(i => i.Message).ToList();

/// <inheritdoc cref="IEnumerable{T}.GetEnumerator"/>
/// <inheritdoc cref="IEnumerable{T}.GetEnumerator" />
public IEnumerator<string> GetEnumerator()
{
return _buildOutput.MessageEvents.Select(i => i.Message).ToList().GetEnumerator();
}

/// <inheritdoc cref="IEnumerable.GetEnumerator"/>
/// <inheritdoc cref="IEnumerable.GetEnumerator" />
IEnumerator IEnumerable.GetEnumerator()
{
return GetEnumerator();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,46 +11,46 @@
namespace Microsoft.Build.Utilities.ProjectCreation
{
/// <summary>
/// Represents the <see cref="BuildMessageEventArgs"/> that were logged.
/// Represents the <see cref="BuildMessageEventArgs" /> that were logged.
/// </summary>
public sealed class BuildMessageEventArgsCollection : IReadOnlyCollection<BuildMessageEventArgs>
{
private readonly IReadOnlyCollection<BuildMessageEventArgs> _messageEvents;

/// <summary>
/// Initializes a new instance of the <see cref="BuildMessageEventArgsCollection"/> class.
/// Initializes a new instance of the <see cref="BuildMessageEventArgsCollection" /> class.
/// </summary>
/// <param name="messageEvents">A <see cref="IReadOnlyCollection{BuildMessageEventArgs}"/> containing the logged message events.</param>
/// <param name="messageEvents">A <see cref="IReadOnlyCollection{BuildMessageEventArgs}" /> containing the logged message events.</param>
internal BuildMessageEventArgsCollection(IReadOnlyCollection<BuildMessageEventArgs> messageEvents)
{
_messageEvents = messageEvents ?? throw new ArgumentNullException(nameof(messageEvents));
}

/// <inheritdoc cref="IReadOnlyCollection{T}.Count"/>
/// <inheritdoc cref="IReadOnlyCollection{T}.Count" />
public int Count => _messageEvents.Count;

/// <summary>
/// Gets the <see cref="BuildMessageEventArgs"/> that were logged with <see cref="MessageImportance.High"/>.
/// Gets the <see cref="BuildMessageEventArgs" /> that were logged with <see cref="MessageImportance.High" />.
/// </summary>
public IReadOnlyCollection<BuildMessageEventArgs> High => _messageEvents.Where(i => i.Importance == MessageImportance.High).ToList();

/// <summary>
/// Gets the <see cref="BuildMessageEventArgs"/> that were logged with <see cref="MessageImportance.Low"/>.
/// Gets the <see cref="BuildMessageEventArgs" /> that were logged with <see cref="MessageImportance.Low" />.
/// </summary>
public IReadOnlyCollection<BuildMessageEventArgs> Low => _messageEvents.Where(i => i.Importance == MessageImportance.Low).ToList();

/// <summary>
/// Gets the <see cref="BuildMessageEventArgs"/> that were logged with <see cref="MessageImportance.Normal"/>.
/// Gets the <see cref="BuildMessageEventArgs" /> that were logged with <see cref="MessageImportance.Normal" />.
/// </summary>
public IReadOnlyCollection<BuildMessageEventArgs> Normal => _messageEvents.Where(i => i.Importance == MessageImportance.Normal).ToList();

/// <inheritdoc cref="IEnumerable{T}.GetEnumerator"/>
/// <inheritdoc cref="IEnumerable{T}.GetEnumerator" />
public IEnumerator<BuildMessageEventArgs> GetEnumerator()
{
return _messageEvents.GetEnumerator();
}

/// <inheritdoc cref="IEnumerable.GetEnumerator"/>
/// <inheritdoc cref="IEnumerable.GetEnumerator" />
IEnumerator IEnumerable.GetEnumerator()
{
return GetEnumerator();
Expand Down
16 changes: 8 additions & 8 deletions src/Microsoft.Build.Utilities.ProjectCreation/BuildOutput.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public sealed class BuildOutput : BuildEventArgsCollection, ILogger
private readonly ConcurrentDictionary<string, bool> _resultsByProject = new ConcurrentDictionary<string, bool>(StringComparer.OrdinalIgnoreCase);

/// <summary>
/// Stores the <see cref="BuildFinishedEventArgs"/> that were logged when the build finished.
/// Stores the <see cref="BuildFinishedEventArgs" /> that were logged when the build finished.
/// </summary>
private BuildFinishedEventArgs? _buildFinished;

Expand All @@ -29,7 +29,7 @@ private BuildOutput()
Parameters = string.Empty;
}

/// <inheritdoc cref="ILogger.Parameters"/>
/// <inheritdoc cref="ILogger.Parameters" />
public string Parameters { get; set; }

/// <summary>
Expand All @@ -42,35 +42,35 @@ private BuildOutput()
/// </summary>
public bool? Succeeded => _buildFinished?.Succeeded;

/// <inheritdoc cref="ILogger.Verbosity"/>
/// <inheritdoc cref="ILogger.Verbosity" />
public LoggerVerbosity Verbosity { get; set; }

/// <summary>
/// Creates an instance of the <see cref="BuildOutput"/> class.
/// Creates an instance of the <see cref="BuildOutput" /> class.
/// </summary>
/// <returns>A <see cref="BuildOutput"/> instance.</returns>
/// <returns>A <see cref="BuildOutput" /> instance.</returns>
public static BuildOutput Create()
{
return new BuildOutput();
}

/// <inheritdoc cref="IDisposable.Dispose"/>
/// <inheritdoc cref="IDisposable.Dispose" />
public override void Dispose()
{
_buildFinished = null;

base.Dispose();
}

/// <inheritdoc cref="ILogger.Initialize"/>
/// <inheritdoc cref="ILogger.Initialize" />
public void Initialize(IEventSource eventSource)
{
eventSource.BuildFinished += OnBuildFinished;
eventSource.ProjectFinished += OnProjectFinished;
eventSource.AnyEventRaised += OnAnyEventRaised;
}

/// <inheritdoc cref="ILogger.Shutdown"/>
/// <inheritdoc cref="ILogger.Shutdown" />
public void Shutdown()
{
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ namespace Microsoft.Build.Utilities.ProjectCreation
/// <summary>
/// Provides extension methods.
/// </summary>
internal static class ExtensionMethods
public static class ExtensionMethods
{
/// <summary>
/// Gets the current object as an <see cref="IEnumerable{T}"/>.
/// Gets the current object as an <see cref="IEnumerable{T}" />.
/// </summary>
/// <typeparam name="T">The type of the object.</typeparam>
/// <param name="item">The item to make into an <see cref="IEnumerable{T}"/>.</param>
/// <returns>The current object as an <see cref="IEnumerable{T}"/>.</returns>
/// <param name="item">The item to make into an <see cref="IEnumerable{T}" />.</param>
/// <returns>The current object as an <see cref="IEnumerable{T}" />.</returns>
[DebuggerStepThrough]
public static IEnumerable<T> AsEnumerable<T>(this T? item)
where T : class
Expand All @@ -42,7 +42,7 @@ public static IEnumerable<T> AsEnumerable<T>(this T? item)
/// </summary>
/// <param name="first">The first dictionary and all of its values to start with.</param>
/// <param name="second">The second dictionary to merge with the first and override its values.</param>
/// <returns>A merged <see cref="IDictionary{String,String}"/> with the values of the first dictionary overridden by the second.</returns>
/// <returns>A merged <see cref="IDictionary{String,String}" /> with the values of the first dictionary overridden by the second.</returns>
[DebuggerStepThrough]
public static IDictionary<string, string?> Merge(this IDictionary<string, string?>? first, IDictionary<string, string?> second)
{
Expand All @@ -54,8 +54,8 @@ public static IEnumerable<T> AsEnumerable<T>(this T? item)
/// </summary>
/// <param name="first">The first dictionary and all of its values to start with.</param>
/// <param name="second">The second dictionary to merge with the first and override its values.</param>
/// <param name="comparer">The <see cref="IEqualityComparer{String}"/> implementation to use when comparing keys, or null to use the default <see cref="IEqualityComparer{String}"/> for the type of the key. </param>
/// <returns>A merged <see cref="IDictionary{String,String}"/> with the values of the first dictionary overridden by the second.</returns>
/// <param name="comparer">The <see cref="IEqualityComparer{String}" /> implementation to use when comparing keys, or null to use the default <see cref="IEqualityComparer{String}" /> for the type of the key. </param>
/// <returns>A merged <see cref="IDictionary{String,String}" /> with the values of the first dictionary overridden by the second.</returns>
[DebuggerStepThrough]
public static IDictionary<string, string?> Merge(this IDictionary<string, string?>? first, IDictionary<string, string?> second, IEqualityComparer<string> comparer)
{
Expand Down Expand Up @@ -93,7 +93,8 @@ public static T[] ToArrayWithSingleElement<T>(this T item)
/// <param name="packageTypes">An <see cref="IEnumerable{String}" /> containing package types.</param>
/// <returns>An <see cref="IEnumerable{PackageType}" /> containing the package types.</returns>
/// <exception cref="ArgumentOutOfRangeException">Any package types are invalid.</exception>
public static IEnumerable<PackageType> ToPackageTypes(this IEnumerable<string>? packageTypes)
[DebuggerStepThrough]
internal static IEnumerable<PackageType> ToPackageTypes(this IEnumerable<string>? packageTypes)
{
if (packageTypes == null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace Microsoft.Build.Utilities.ProjectCreation
public static partial class MSBuildAssemblyResolver
{
/// <summary>
/// A <see cref="ResolveEventHandler"/> for MSBuild related assemblies.
/// A <see cref="ResolveEventHandler" /> for MSBuild related assemblies.
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="args">The event data.</param>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public static partial class MSBuildAssemblyResolver
private static readonly char[] PathSplitChars = { Path.PathSeparator };

/// <summary>
/// A <see cref="ResolveEventHandler"/> for MSBuild related assemblies.
/// A <see cref="ResolveEventHandler" /> for MSBuild related assemblies.
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="args">The event data.</param>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ public partial class ProjectCreator
/// <param name="includeAssets">An optional value specifying which assets belonging to the package should be consumed.</param>
/// <param name="excludeAssets">An optional value specifying which assets belonging to the package should be not consumed.</param>
/// <param name="privateAssets">An optional value specifying which assets belonging to the package should not flow to dependent projects.</param>
/// <param name="metadata">An optional <see cref="IDictionary{String,String}"/> containing metadata for the item.</param>
/// <param name="metadata">An optional <see cref="IDictionary{String,String}" /> containing metadata for the item.</param>
/// <param name="condition">An optional condition to add to the item.</param>
/// <param name="label">An optional label to add to the item.</param>
/// <returns>The current <see cref="ProjectCreator"/>.</returns>
/// <returns>The current <see cref="ProjectCreator" />.</returns>
public ProjectCreator ItemPackageReference(Package package, string? includeAssets = null, string? excludeAssets = null, string? privateAssets = null, IDictionary<string, string?>? metadata = null, string? condition = null, string? label = null)
{
return ItemPackageReference(package.Id, package.Version, includeAssets, excludeAssets, privateAssets, metadata, condition, label);
Expand Down
Loading

0 comments on commit ca7e4b8

Please sign in to comment.