forked from praeclarum/sqlite-net
-
Notifications
You must be signed in to change notification settings - Fork 160
/
Copy pathReflectionServiceWinRT.cs
48 lines (44 loc) · 1.76 KB
/
ReflectionServiceWinRT.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
47
48
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using SQLite.Net.Interop;
namespace SQLite.Net.Platform.WinRT
{
public class ReflectionServiceWinRT : IReflectionService
{
public IEnumerable<PropertyInfo> GetPublicInstanceProperties(Type mappedType)
{
if (mappedType == null) throw new ArgumentNullException(nameof(mappedType));
return from p in mappedType.GetRuntimeProperties()
where
((p.GetMethod != null && p.GetMethod.IsPublic) || (p.SetMethod != null && p.SetMethod.IsPublic) ||
(p.GetMethod != null && p.GetMethod.IsStatic) || (p.SetMethod != null && p.SetMethod.IsStatic))
select p;
}
public IEnumerable<PropertyInfo> GetDecoratedPrivateInstanceProperties(Type mappedType, Type attributeType)
{
return from p in mappedType.GetRuntimeProperties()
where (
(p.GetMethod != null && p.GetMethod.IsPrivate) || (p.SetMethod != null && p.SetMethod.IsPrivate) ||
p.GetCustomAttribute(attributeType) != null
)
select p;
}
public object GetMemberValue(object obj, Expression expr, MemberInfo member)
{
if (member is PropertyInfo)
{
var m = (PropertyInfo) member;
return m.GetValue(obj, null);
}
if (member is FieldInfo)
{
var m = (FieldInfo) member;
return m.GetValue(obj);
}
throw new NotSupportedException("MemberExpr: " + member.DeclaringType);
}
}
}