-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathProtocolTypeExtension.cs
33 lines (28 loc) · 1.09 KB
/
ProtocolTypeExtension.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
using System;
using System.Reflection;
namespace SagePay.IntegrationKit
{
public static class ProtocolTypeExtension
{
public static ApiRegex ApiRegex(this ProtocolType p)
{
return ((ProtocolTypeAttr)Attribute.GetCustomAttribute(ForValue(p), typeof(ProtocolTypeAttr))).ApiRegex;
}
public static int MinLength(this ProtocolType p)
{
return ((ProtocolTypeAttr)Attribute.GetCustomAttribute(ForValue(p), typeof(ProtocolTypeAttr))).MinLength;
}
public static int MaxLength(this ProtocolType p)
{
return ((ProtocolTypeAttr)Attribute.GetCustomAttribute(ForValue(p), typeof(ProtocolTypeAttr))).MaxLength;
}
public static Type Type(this ProtocolType p)
{
return ((ProtocolTypeAttr)Attribute.GetCustomAttribute(ForValue(p), typeof(ProtocolTypeAttr))).Type;
}
private static MemberInfo ForValue(ProtocolType p)
{
return typeof(ProtocolType).GetField(Enum.GetName(typeof(ProtocolType), p));
}
}
}