-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathHelper.cs
More file actions
47 lines (44 loc) · 1.54 KB
/
Copy pathHelper.cs
File metadata and controls
47 lines (44 loc) · 1.54 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
38
39
40
41
42
43
44
45
46
47
using SharpNTCIP.Attributes;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace SharpNTCIP
{
public class Helper
{
public static string GetOid(Type implementedInterface, string implementedProperty)
{
string oid = string.Empty;
var interfaceMethod = implementedInterface.GetProperty(implementedProperty);
if (interfaceMethod != null)
{
NtcipOidAttribute attributeOid = interfaceMethod.GetCustomAttributes(
typeof(NtcipOidAttribute), true).FirstOrDefault() as NtcipOidAttribute;
if (attributeOid != null)
{
oid = attributeOid.NtcipOid;
}
}
return oid;
}
public static T EnumParse<T>(object value)
{
try
{
return (T)Enum.Parse(typeof(T), Enum.GetName(typeof(T), value));
} catch
{
throw new InvalidCastException("Returned value does not match known NTCIP values. Perhaps this device implements a newer version of the NTCIP standard");
}
}
protected static string formatOid(string oidString, params object[] list)
{
object[] idList = new object[list.Length];
for (int i = 0; i < idList.Length; i++)
idList[i] = Convert.ToInt32(list[i]);
string finalOid = String.Format(oidString, idList);
return finalOid;
}
}
}