-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHelpers.cs
45 lines (43 loc) · 1.43 KB
/
Helpers.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
using System;
using System.Collections.Generic;
namespace LStoreJSON
{
internal static class Helpers
{
internal static object GetKeyValeue<T>(this object input)
{
bool keyFound = false;
dynamic output = "";
foreach (System.Reflection.PropertyInfo info in typeof(T).GetProperties())
{
if (Attribute.IsDefined(info, typeof(System.ComponentModel.DataAnnotations.KeyAttribute)))
{
keyFound = true;
output = info.GetValue(input);
break;
}
}
if (!keyFound)
{
throw new KeyNotFoundException("Key attribute not found in " + typeof(T).ToString());
}
return (object)output;
}
internal static List<object> ConvertGenericTypeToObjectList<T>(this List<T> inList)
{
List<object> outputObject = new List<object>();
inList.ForEach(a => outputObject.Add((object)a));
return outputObject;
}
internal static List<T> ConvertObjectToGenericType<T>(this List<object> inList)
{
List<T> outputObject = new List<T>();
inList.ForEach(a => outputObject.Add((T)a));
return outputObject;
}
internal static dynamic ToDynamic<T>(this T input)
{
return (dynamic)input;
}
}
}