-
Notifications
You must be signed in to change notification settings - Fork 774
Expand file tree
/
Copy pathReflectionPolyfills.cs
More file actions
37 lines (32 loc) · 1.16 KB
/
ReflectionPolyfills.cs
File metadata and controls
37 lines (32 loc) · 1.16 KB
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
using System;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
namespace Python.Runtime
{
internal static class ReflectionPolyfills
{
public static AssemblyBuilder DefineDynamicAssembly(this AppDomain _, AssemblyName assemblyName, AssemblyBuilderAccess assemblyBuilderAccess)
{
return AssemblyBuilder.DefineDynamicAssembly(assemblyName, assemblyBuilderAccess);
}
public static Type CreateType(this TypeBuilder typeBuilder)
{
return typeBuilder.CreateTypeInfo();
}
public static T GetCustomAttribute<T>(this Type type) where T: Attribute
{
return type.GetCustomAttributes(typeof(T), inherit: false)
.Cast<T>()
.SingleOrDefault();
}
public static T GetCustomAttribute<T>(this Assembly assembly) where T: Attribute
{
return assembly.GetCustomAttributes(typeof(T), inherit: false)
.Cast<T>()
.SingleOrDefault();
}
public static bool IsFlagsEnum(this Type type)
=> type.GetCustomAttribute<FlagsAttribute>() is not null;
}
}