forked from fareloz/AttachToolbar
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEngineType.cs
46 lines (39 loc) · 1.2 KB
/
EngineType.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
40
41
42
43
44
45
46
using System;
using System.Reflection;
namespace AttachToolbar
{
public enum EngineType
{
[EngineName("Native")]
Native = 1,
[EngineName("Managed")]
Managed = 2,
[EngineName("Managed/Native")]
Both = 3
}
public static class AttachEngineTypeConverter
{
public static string GetEngineName(this EngineType type)
{
Type atTypeDesc = type.GetType();
MemberInfo[] info = atTypeDesc.GetMember(type.ToString());
EngineNameAttribute engineNameAttr = Attribute.GetCustomAttribute(info[0], typeof(EngineNameAttribute))
as EngineNameAttribute;
if (engineNameAttr == null)
throw new ArgumentException();
return engineNameAttr.EngineName;
}
public static EngineType GetAttachType(this string engineName)
{
Array enumValues = Enum.GetValues(typeof(EngineType));
foreach (EngineType type in enumValues)
{
if (type.GetEngineName() == engineName)
{
return type;
}
}
return EngineType.Native;
}
}
}