forked from Azure/azure-functions-host
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTypeSymbolExtensions.cs
39 lines (33 loc) · 1.17 KB
/
TypeSymbolExtensions.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
31
32
33
34
35
36
37
38
39
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
using Microsoft.CodeAnalysis;
using System.Linq;
namespace Microsoft.Azure.Functions.Analyzers
{
internal static class TypeSymbolExtensions
{
internal static bool IsAssignableFrom(this ITypeSymbol targetType, ITypeSymbol sourceType, bool exactMatch = false)
{
if (targetType != null)
{
while (sourceType != null)
{
if (sourceType.Equals(targetType, SymbolEqualityComparer.Default))
{
return true;
}
if (exactMatch)
{
return false;
}
if (targetType.TypeKind == TypeKind.Interface)
{
return sourceType.AllInterfaces.Any(i => i.Equals(targetType, SymbolEqualityComparer.Default));
}
sourceType = sourceType.BaseType;
}
}
return false;
}
}
}