-
Notifications
You must be signed in to change notification settings - Fork 380
/
Binder.cs
30 lines (25 loc) · 1.03 KB
/
Binder.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
// Copyright (c) .NET Foundation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System.Linq;
namespace System.CommandLine.Binding
{
internal static class Binder
{
internal static bool IsMatch(this string parameterName, string alias) =>
String.Equals(alias?.RemovePrefix()
.Replace("-", ""),
parameterName,
StringComparison.OrdinalIgnoreCase);
internal static bool IsMatch(this string parameterName, ISymbol symbol) =>
symbol.Aliases.Any(parameterName.IsMatch);
internal static bool IsNullable(this Type t)
{
return t.IsGenericType &&
t.GetGenericTypeDefinition() == typeof(Nullable<>);
}
public static object GetDefaultValueForType(this Type type)
{
return type.IsValueType ? Activator.CreateInstance(type) : null;
}
}
}