回答編集履歴
1
インデント修正
test
CHANGED
@@ -6,52 +6,56 @@
|
|
6
6
|
|
7
7
|
public class FreeClass {
|
8
8
|
|
9
|
-
|
9
|
+
public string FreeProperty { get; set; }
|
10
10
|
|
11
|
-
|
11
|
+
}
|
12
12
|
|
13
13
|
|
14
14
|
|
15
|
-
|
15
|
+
public class FreeManagerClass {
|
16
16
|
|
17
17
|
|
18
18
|
|
19
|
-
|
19
|
+
private static Func<FreeClass, object> TargetProperty;
|
20
20
|
|
21
21
|
|
22
22
|
|
23
|
-
|
23
|
+
public static void FromPropertyMethod(
|
24
24
|
|
25
|
-
|
25
|
+
System.Linq.Expressions.Expression<Func<FreeClass, object>> expression) {
|
26
|
-
|
27
|
-
}
|
28
26
|
|
29
27
|
|
30
28
|
|
31
|
-
|
29
|
+
TargetProperty = expression.Compile();
|
32
30
|
|
33
|
-
public object GetValue(FreeClass instance) {
|
34
|
-
|
35
|
-
return TargetProperty.Invoke(instance);
|
36
|
-
|
37
|
-
|
31
|
+
}
|
38
|
-
|
39
|
-
}
|
40
32
|
|
41
33
|
|
42
34
|
|
35
|
+
// 値取得時には対象インスタンスを受け取って実行
|
36
|
+
|
43
|
-
|
37
|
+
public object GetValue(FreeClass instance) {
|
38
|
+
|
39
|
+
return TargetProperty.Invoke(instance);
|
40
|
+
|
41
|
+
}
|
42
|
+
|
43
|
+
}
|
44
44
|
|
45
45
|
|
46
46
|
|
47
|
-
|
47
|
+
public class UserClass {
|
48
|
-
|
49
|
-
FreeManagerClass.FromPropertyMethod(x => x.FreeProperty);
|
50
|
-
|
51
|
-
}
|
52
48
|
|
53
49
|
|
54
50
|
|
51
|
+
public void UseFromPropertyMethod() {
|
52
|
+
|
53
|
+
FreeManagerClass.FromPropertyMethod(x => x.FreeProperty);
|
54
|
+
|
55
|
-
|
55
|
+
}
|
56
|
+
|
57
|
+
|
58
|
+
|
59
|
+
}
|
56
60
|
|
57
61
|
```
|