-
Notifications
You must be signed in to change notification settings - Fork 366
Expand file tree
/
Copy pathTypeExtensions.cs
More file actions
25 lines (23 loc) · 1014 Bytes
/
TypeExtensions.cs
File metadata and controls
25 lines (23 loc) · 1014 Bytes
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
namespace ScriptCs.Extensions
{
internal static class TypeExtensions
{
internal static IEnumerable<MethodInfo> GetExtensionMethods(this Type type)
{
return type.Assembly.GetExportedTypes().Where(x => !x.IsGenericType && !x.IsNested && x.IsSealed)
.SelectMany(x => x.GetMethods(BindingFlags.Static | BindingFlags.Public))
.Where(x => x.IsDefined(typeof(ExtensionAttribute), false))
.Where(x => x.GetParameters()[0].ParameterType == type);
}
internal static IEnumerable<MethodInfo> GetAllMethods(this Type type)
{
return type.GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly)
.Where(m => !m.IsSpecialName).Union(type.GetExtensionMethods()).OrderBy(x => x.Name);
}
}
}