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
|
internal class AttributeLogic
{
internal static readonly AttributeLogic Instance = new AttributeLogic();
internal string GetAttributeValue(Type targetType, Type attributeType, string attributePropertyName)
{
if (Attribute.IsDefined(targetType, attributeType))
{
Object att = Attribute.GetCustomAttribute(targetType, attributeType);
PropertyInfo pi = att.GetType().GetProperty(attributePropertyName);
if (pi == null)
{
throw new Exception(String.Format("The {0} attribute on the {1} type dosen't define the {2} property",
new object[] { attributeType, targetType, attributePropertyName }));
}
else
{
return pi.GetValue(att, null).ToString();
}
}
else
{
throw new Exception(String.Format("The {0} attribute isn't set to the type {1}", new object[] { attributeType, targetType }));
}
}
internal bool isAttributeTrue(Type targetType, Type attributeType, string attributePropertyName)
{
if (Attribute.IsDefined(targetType, attributeType))
{
Object att = Attribute.GetCustomAttribute(targetType, attributeType);
PropertyInfo pi = att.GetType().GetProperty(attributePropertyName);
if (pi == null)
{
return false;
}
else
{
return Convert.ToBoolean(pi.GetValue(att, null));
}
}
else
{
return false;
}
}
}
|