-
Notifications
You must be signed in to change notification settings - Fork 25
/
TypesFunctions.cs
29 lines (27 loc) · 1018 Bytes
/
TypesFunctions.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
using System.Collections.Generic;
using System.Linq;
namespace NTypewriter.CodeModel.Functions
{
/// <summary>
/// Set of filters that operates on IEnumerable<IType>
/// </summary>
public static class TypesFunctions
{
/// <summary>
/// Filters types based on if a type implements given interface (directly or indirectly)
/// </summary>
public static IEnumerable<IType> ThatImplement(this IEnumerable<IType> types, string interfaceName)
{
var result = types.Where(x => x.AllInterfaces.Any(y => y.Name == interfaceName));
return result;
}
/// <summary>
/// Filters types based on if a type inherits directly from given type
/// </summary>
public static IEnumerable<IType> ThatInheritFrom(this IEnumerable<IType> types, string baseTypeName)
{
var result = types.Where(x => x.BaseType?.Name.Equals(baseTypeName) == true);
return result;
}
}
}