Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into dev/7.0.0
Browse files Browse the repository at this point in the history
# Conflicts:
#	version.json
  • Loading branch information
michael-hawker committed Mar 18, 2020
2 parents 2b5eb6c + 8d4fb2d commit df1ef7a
Show file tree
Hide file tree
Showing 43 changed files with 9,335 additions and 29 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -225,3 +225,6 @@ msbuild.binlog
*.project.lock.json
/build/tools/**
!/build/tools/packages.config

# Generated file from .ttinclude
**/Generated/TypeInfo.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
MinAngle="@[MinAngle:Slider:210:0-360]"
MaxAngle="@[MaxAngle:Slider:150:0-360]"
Unit="units"
ValueStringFormat="@[ValueStringFormat:String:N0]"
NeedleWidth="@[NeedleWidth:Slider:4:1-10]"
NeedleLength="@[NeedleLength:Slider:100:20-100]"
TickLength="@[TickLength:Slider:10:0-30]"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public class RadialGauge : RangeBase
/// Identifies the ValueStringFormat dependency property.
/// </summary>
public static readonly DependencyProperty ValueStringFormatProperty =
DependencyProperty.Register(nameof(ValueStringFormat), typeof(string), typeof(RadialGauge), new PropertyMetadata("N0"));
DependencyProperty.Register(nameof(ValueStringFormat), typeof(string), typeof(RadialGauge), new PropertyMetadata("N0", (s, e) => OnValueChanged(s)));

/// <summary>
/// Identifies the TickSpacing dependency property.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@
FontSize="20"
FontWeight="SemiBold"
Foreground="{TemplateBinding Foreground}"
Text="{TemplateBinding Value}"
TextAlignment="Center" />
<TextBlock Margin="0"
FontSize="16"
Expand Down
8 changes: 2 additions & 6 deletions Microsoft.Toolkit.Uwp/Deferred/EventHandlerExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
// See the LICENSE file in the project root for more information.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

Expand All @@ -16,8 +14,6 @@ namespace Microsoft.Toolkit.Uwp.Deferred
/// </summary>
public static class EventHandlerExtensions
{
private static readonly Task CompletedTask = Task.FromResult(0);

/// <summary>
/// Use to invoke an async <see cref="EventHandler{TEventArgs}"/> using <see cref="DeferredEventArgs"/>.
/// </summary>
Expand Down Expand Up @@ -46,7 +42,7 @@ public static Task InvokeAsync<T>(this EventHandler<T> eventHandler, object send
{
if (eventHandler == null)
{
return CompletedTask;
return Task.CompletedTask;
}

var tasks = eventHandler.GetInvocationList()
Expand All @@ -59,7 +55,7 @@ public static Task InvokeAsync<T>(this EventHandler<T> eventHandler, object send

var deferral = eventArgs.GetCurrentDeferralAndReset();

return deferral?.WaitForCompletion(cancellationToken) ?? CompletedTask;
return deferral?.WaitForCompletion(cancellationToken) ?? Task.CompletedTask;
})
.ToArray();

Expand Down
6 changes: 2 additions & 4 deletions Microsoft.Toolkit.Uwp/Deferred/TypedEventHandlerExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ namespace Microsoft.Toolkit.Uwp.Deferred
/// </summary>
public static class TypedEventHandlerExtensions
{
private static readonly Task CompletedTask = Task.FromResult(0);

/// <summary>
/// Use to invoke an async <see cref="TypedEventHandler{TSender, TResult}"/> using <see cref="DeferredEventArgs"/>.
/// </summary>
Expand Down Expand Up @@ -47,7 +45,7 @@ public static Task InvokeAsync<S, R>(this TypedEventHandler<S, R> eventHandler,
{
if (eventHandler == null)
{
return CompletedTask;
return Task.CompletedTask;
}

var tasks = eventHandler.GetInvocationList()
Expand All @@ -60,7 +58,7 @@ public static Task InvokeAsync<S, R>(this TypedEventHandler<S, R> eventHandler,

var deferral = eventArgs.GetCurrentDeferralAndReset();

return deferral?.WaitForCompletion(cancellationToken) ?? CompletedTask;
return deferral?.WaitForCompletion(cancellationToken) ?? Task.CompletedTask;
})
.ToArray();

Expand Down
4 changes: 0 additions & 4 deletions Microsoft.Toolkit/Converters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System;
using System.Collections.Generic;
using System.Text;

namespace Microsoft.Toolkit
{
/// <summary>
Expand Down
1,638 changes: 1,638 additions & 0 deletions Microsoft.Toolkit/Diagnostics/Generated/Guard.Collection.g.cs

Large diffs are not rendered by default.

283 changes: 283 additions & 0 deletions Microsoft.Toolkit/Diagnostics/Generated/Guard.Collection.tt
Original file line number Diff line number Diff line change
@@ -0,0 +1,283 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
<#@include file="TypeInfo.ttinclude" #>
/* ========================
* Auto generated file
* ===================== */

using System;
using System.Collections.Generic;
using System.Runtime.CompilerServices;

#nullable enable

namespace Microsoft.Toolkit.Diagnostics
{
/// <summary>
/// Helper methods to verify conditions when running code.
/// </summary>
public static partial class Guard
{
<#
GenerateTextForItems(EnumerableTypes, item =>
{
#>
/// <summary>
/// Asserts that the input <#=item.XmlType#> instance must be empty.
/// </summary>
/// <typeparam name="T">The item of items in the input <#=item.XmlType#> instance.</typeparam>
/// <param name="<#=item.Name#>">The input <#=item.XmlType#> instance to check the size for.</param>
/// <param name="name">The name of the input parameter being tested.</param>
/// <exception cref="ArgumentException">Thrown if the size of <paramref name="<#=item.Name#>"/> is != 0.</exception>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void IsEmpty<T>(<#=item.Type#> <#=item.Name#>, string name)
{
if (<#=item.Name#>.<#=item.Size#> != 0)
{
ThrowHelper.ThrowArgumentExceptionForIsEmpty(<#=item.Cast#><#=item.Name#>, name);
}
}

/// <summary>
/// Asserts that the input <#=item.XmlType#> instance must not be empty.
/// </summary>
/// <typeparam name="T">The item of items in the input <#=item.XmlType#> instance.</typeparam>
/// <param name="<#=item.Name#>">The input <#=item.XmlType#> instance to check the size for.</param>
/// <param name="name">The name of the input parameter being tested.</param>
/// <exception cref="ArgumentException">Thrown if the size of <paramref name="<#=item.Name#>"/> is == 0.</exception>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void IsNotEmpty<T>(<#=item.Type#> <#=item.Name#>, string name)
{
if (<#=item.Name#>.<#=item.Size#> == 0)
{
<#
if (item.Type == "Span<T>")
{
#>
ThrowHelper.ThrowArgumentExceptionForIsNotEmptyWithSpan<T>(name);
<#
}
else if (item.Type == "ReadOnlySpan<T>")
{
#>
ThrowHelper.ThrowArgumentExceptionForIsNotEmptyWithReadOnlySpan<T>(name);
<#
}
else
{
#>
ThrowHelper.ThrowArgumentExceptionForIsNotEmpty<<#=item.Type#>>(name);
<#
}
#>
}
}

/// <summary>
/// Asserts that the input <#=item.XmlType#> instance must have a size of a specified value.
/// </summary>
/// <typeparam name="T">The item of items in the input <#=item.XmlType#> instance.</typeparam>
/// <param name="<#=item.Name#>">The input <#=item.XmlType#> instance to check the size for.</param>
/// <param name="size">The target size to test.</param>
/// <param name="name">The name of the input parameter being tested.</param>
/// <exception cref="ArgumentException">Thrown if the size of <paramref name="<#=item.Name#>"/> is != <paramref name="size"/>.</exception>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void HasSizeEqualTo<T>(<#=item.Type#> <#=item.Name#>, int size, string name)
{
if (<#=item.Name#>.<#=item.Size#> != size)
{
ThrowHelper.ThrowArgumentExceptionForHasSizeEqualTo(<#=item.Cast#><#=item.Name#>, size, name);
}
}

/// <summary>
/// Asserts that the input <#=item.XmlType#> instance must have a size not equal to a specified value.
/// </summary>
/// <typeparam name="T">The item of items in the input <#=item.XmlType#> instance.</typeparam>
/// <param name="<#=item.Name#>">The input <#=item.XmlType#> instance to check the size for.</param>
/// <param name="size">The target size to test.</param>
/// <param name="name">The name of the input parameter being tested.</param>
/// <exception cref="ArgumentException">Thrown if the size of <paramref name="<#=item.Name#>"/> is == <paramref name="size"/>.</exception>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void HasSizeNotEqualTo<T>(<#=item.Type#> <#=item.Name#>, int size, string name)
{
if (<#=item.Name#>.<#=item.Size#> == size)
{
ThrowHelper.ThrowArgumentExceptionForHasSizeNotEqualTo(<#=item.Cast#><#=item.Name#>, size, name);
}
}

/// <summary>
/// Asserts that the input <#=item.XmlType#> instance must have a size over a specified value.
/// </summary>
/// <typeparam name="T">The item of items in the input <#=item.XmlType#> instance.</typeparam>
/// <param name="<#=item.Name#>">The input <#=item.XmlType#> instance to check the size for.</param>
/// <param name="size">The target size to test.</param>
/// <param name="name">The name of the input parameter being tested.</param>
/// <exception cref="ArgumentException">Thrown if the size of <paramref name="<#=item.Name#>"/> is &lt;= <paramref name="size"/>.</exception>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void HasSizeOver<T>(<#=item.Type#> <#=item.Name#>, int size, string name)
{
if (<#=item.Name#>.<#=item.Size#> <= size)
{
ThrowHelper.ThrowArgumentExceptionForHasSizeOver(<#=item.Cast#><#=item.Name#>, size, name);
}
}

/// <summary>
/// Asserts that the input <#=item.XmlType#> instance must have a size of at least or equal to a specified value.
/// </summary>
/// <typeparam name="T">The item of items in the input <#=item.XmlType#> instance.</typeparam>
/// <param name="<#=item.Name#>">The input <#=item.XmlType#> instance to check the size for.</param>
/// <param name="size">The target size to test.</param>
/// <param name="name">The name of the input parameter being tested.</param>
/// <exception cref="ArgumentException">Thrown if the size of <paramref name="<#=item.Name#>"/> is &lt; <paramref name="size"/>.</exception>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void HasSizeAtLeast<T>(<#=item.Type#> <#=item.Name#>, int size, string name)
{
if (<#=item.Name#>.<#=item.Size#> < size)
{
ThrowHelper.ThrowArgumentExceptionForHasSizeAtLeast(<#=item.Cast#><#=item.Name#>, size, name);
}
}

/// <summary>
/// Asserts that the input <#=item.XmlType#> instance must have a size of less than a specified value.
/// </summary>
/// <typeparam name="T">The item of items in the input <#=item.XmlType#> instance.</typeparam>
/// <param name="<#=item.Name#>">The input <#=item.XmlType#> instance to check the size for.</param>
/// <param name="size">The target size to test.</param>
/// <param name="name">The name of the input parameter being tested.</param>
/// <exception cref="ArgumentException">Thrown if the size of <paramref name="<#=item.Name#>"/> is >= <paramref name="size"/>.</exception>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void HasSizeLessThan<T>(<#=item.Type#> <#=item.Name#>, int size, string name)
{
if (<#=item.Name#>.<#=item.Size#> >= size)
{
ThrowHelper.ThrowArgumentExceptionForHasSizeLessThan(<#=item.Cast#><#=item.Name#>, size, name);
}
}

/// <summary>
/// Asserts that the input <#=item.XmlType#> instance must have a size of less than or equal to a specified value.
/// </summary>
/// <typeparam name="T">The item of items in the input <#=item.XmlType#> instance.</typeparam>
/// <param name="<#=item.Name#>">The input <#=item.XmlType#> instance to check the size for.</param>
/// <param name="size">The target size to test.</param>
/// <param name="name">The name of the input parameter being tested.</param>
/// <exception cref="ArgumentException">Thrown if the size of <paramref name="<#=item.Name#>"/> is > <paramref name="size"/>.</exception>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void HasSizeLessThanOrEqualTo<T>(<#=item.Type#> <#=item.Name#>, int size, string name)
{
if (<#=item.Name#>.<#=item.Size#> > size)
{
ThrowHelper.ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(<#=item.Cast#><#=item.Name#>, size, name);
}
}

/// <summary>
/// Asserts that the source <#=item.XmlType#> instance must have the same size of a destination <#=item.XmlType#> instance.
/// </summary>
/// <typeparam name="T">The item of items in the input <#=item.XmlType#> instance.</typeparam>
/// <param name="source">The source <#=item.XmlType#> instance to check the size for.</param>
/// <param name="destination">The destination <#=item.XmlType#> instance to check the size for.</param>
/// <param name="name">The name of the input parameter being tested.</param>
/// <exception cref="ArgumentException">Thrown if the size of <paramref name="source"/> is != the one of <paramref name="destination"/>.</exception>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void HasSizeEqualTo<T>(<#=item.Type#> source, <#=item.DestinationType#> destination, string name)
{
if (source.<#=item.Size#> != destination.<#=item.Size#>)
{
<#
if (item.HasCountProperty)
{
#>
ThrowHelper.ThrowArgumentExceptionForHasSizeEqualTo(<#=item.Cast#>source, destination.<#=item.Size#>, name);
<#
}
else
{
#>
ThrowHelper.ThrowArgumentExceptionForHasSizeEqualTo(source, <#=item.Cast#>destination, name);
<#
}
#>
}
}

/// <summary>
/// Asserts that the source <#=item.XmlType#> instance must have a size of less than or equal to that of a destination <#=item.XmlType#> instance.
/// </summary>
/// <typeparam name="T">The item of items in the input <#=item.XmlType#> instance.</typeparam>
/// <param name="source">The source <#=item.XmlType#> instance to check the size for.</param>
/// <param name="destination">The destination <#=item.XmlType#> instance to check the size for.</param>
/// <param name="name">The name of the input parameter being tested.</param>
/// <exception cref="ArgumentException">Thrown if the size of <paramref name="source"/> is > the one of <paramref name="destination"/>.</exception>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void HasSizeLessThanOrEqualTo<T>(<#=item.Type#> source, <#=item.DestinationType#> destination, string name)
{
if (source.<#=item.Size#> > destination.<#=item.Size#>)
{
<#
if (item.HasCountProperty)
{
#>
ThrowHelper.ThrowArgumentExceptionForHasSizeEqualTo(<#=item.Cast#>source, destination.<#=item.Size#>, name);
<#
}
else
{
#>
ThrowHelper.ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(source, <#=item.Cast#>destination, name);
<#
}
#>
}
}

/// <summary>
/// Asserts that the input index is valid for a given <#=item.XmlType#> instance.
/// </summary>
/// <typeparam name="T">The item of items in the input <#=item.XmlType#> instance.</typeparam>
/// <param name="index">The input index to be used to access <paramref name="<#=item.Name#>"/>.</param>
/// <param name="<#=item.Name#>">The input <#=item.XmlType#> instance to use to validate <paramref name="index"/>.</param>
/// <param name="name">The name of the input parameter being tested.</param>
/// <exception cref="ArgumentOutOfRangeException">Thrown if <paramref name="index"/> is not valid to access <paramref name="<#=item.Name#>"/>.</exception>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void IsInRangeFor<T>(int index, <#=item.Type#> <#=item.Name#>, string name)
{
<#
/* Here we're leveraging the fact that signed integers are represented
* in 2-complement to perform the bounds check with a single compare operation.
* This is the same trick used throughout CoreCLR as well.
* For more info and code sample, see the original conversation here:
* https://github.com/windows-toolkit/WindowsCommunityToolkit/pull/3131#discussion_r390682835 */
#>
if ((uint)index >= (uint)<#=item.Name#>.<#=item.Size#>)
{
ThrowHelper.ThrowArgumentOutOfRangeExceptionForIsInRangeFor(index, <#=item.Cast#><#=item.Name#>, name);
}
}

/// <summary>
/// Asserts that the input index is not valid for a given <#=item.XmlType#> instance.
/// </summary>
/// <typeparam name="T">The item of items in the input <#=item.XmlType#> instance.</typeparam>
/// <param name="index">The input index to be used to access <paramref name="<#=item.Name#>"/>.</param>
/// <param name="<#=item.Name#>">The input <#=item.XmlType#> instance to use to validate <paramref name="index"/>.</param>
/// <param name="name">The name of the input parameter being tested.</param>
/// <exception cref="ArgumentOutOfRangeException">Thrown if <paramref name="index"/> is valid to access <paramref name="<#=item.Name#>"/>.</exception>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void IsNotInRangeFor<T>(int index, <#=item.Type#> <#=item.Name#>, string name)
{
if ((uint)index < (uint)<#=item.Name#>.<#=item.Size#>)
{
ThrowHelper.ThrowArgumentOutOfRangeExceptionForIsNotInRangeFor(index, <#=item.Cast#><#=item.Name#>, name);
}
}
<#
});
#>
}
}
Loading

0 comments on commit df1ef7a

Please sign in to comment.