forked from pythonnet/pythonnet
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReflectionPolifills.cs
More file actions
36 lines (33 loc) · 1.12 KB
/
Copy pathReflectionPolifills.cs
File metadata and controls
36 lines (33 loc) · 1.12 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
using System;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
namespace Python.Runtime
{
[Obsolete("This API is for internal use only")]
public static class ReflectionPolifills
{
#if NETSTANDARD
public static AssemblyBuilder DefineDynamicAssembly(this AppDomain appDomain, AssemblyName assemblyName, AssemblyBuilderAccess assemblyBuilderAccess)
{
return AssemblyBuilder.DefineDynamicAssembly(assemblyName, assemblyBuilderAccess);
}
public static Type CreateType(this TypeBuilder typeBuilder)
{
return typeBuilder.CreateTypeInfo();
}
#endif
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();
}
}
}