-
Notifications
You must be signed in to change notification settings - Fork 43
/
SingleMethod.cs
102 lines (80 loc) · 2.75 KB
/
SingleMethod.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Reflection;
namespace FubuCore.Reflection
{
public class SingleMethod : Accessor
{
private readonly MethodValueGetter _getter;
private readonly Type _ownerType;
public SingleMethod(MethodValueGetter getter)
{
_getter = getter;
}
public SingleMethod(MethodValueGetter getter, Type ownerType)
{
_getter = getter;
_ownerType = ownerType;
}
public string FieldName { get { return _getter.Name; } }
public Type PropertyType { get { return _getter.ReturnType; } }
public Type DeclaringType { get { return _getter.DeclaringType; } }
public PropertyInfo InnerProperty { get { return null; } }
public Accessor GetChildAccessor<T>(Expression<Func<T, object>> expression)
{
throw new NotSupportedException("Not supported with Methods");
}
public string[] PropertyNames
{
get { return new[] { Name }; }
}
public Expression<Func<T, object>> ToExpression<T>()
{
throw new NotSupportedException("Not yet supported with Methods");
}
public Accessor Prepend(PropertyInfo property)
{
return
new PropertyChain(new IValueGetter[]
{new PropertyValueGetter(property), _getter});
}
public IEnumerable<IValueGetter> Getters()
{
yield return _getter;
}
public string Name { get { return _getter.Name; } }
public virtual void SetValue(object target, object propertyValue)
{
// no-op
}
public object GetValue(object target)
{
return _getter.GetValue(target);
}
public Type OwnerType
{
get
{
return _ownerType ?? DeclaringType;
}
}
public bool Equals(SingleMethod other)
{
if (ReferenceEquals(null, other)) return false;
if (ReferenceEquals(this, other)) return true;
return Equals(other._getter, _getter);
}
public override bool Equals(object obj)
{
if (ReferenceEquals(null, obj)) return false;
if (ReferenceEquals(this, obj)) return true;
if (obj.GetType() != typeof (SingleMethod)) return false;
return Equals((SingleMethod) obj);
}
public override int GetHashCode()
{
return (_getter != null ? _getter.GetHashCode() : 0);
}
}
}