回答編集履歴
1
Wrapperという表現をやめた
answer
CHANGED
@@ -1,14 +1,14 @@
|
|
1
|
-
どうしても`hoge.A_Method();`のような方法で呼び出したいのであれば、
|
1
|
+
どうしても`hoge.A_Method();`のような方法で呼び出したいのであれば、既存のオブジェクトから必要な情報を取り出して新しいオブジェクトを取り扱うのが良いと思います。下記コードの場合は新しいデータ保持用のオブジェクトを使って `AModel` と `A` を has a 関係にしています。
|
2
2
|
|
3
3
|
```
|
4
|
-
public interface
|
4
|
+
public interface IModel{
|
5
5
|
int Property { get; set; }
|
6
6
|
string Method();
|
7
7
|
}
|
8
8
|
|
9
|
-
public class
|
9
|
+
public class AModel: IModel{
|
10
10
|
private A a;
|
11
|
-
public
|
11
|
+
public AModel(A a){
|
12
12
|
this.a = a;
|
13
13
|
}
|
14
14
|
public string Method(){ return a.A_Method(); }
|
@@ -18,9 +18,9 @@
|
|
18
18
|
}
|
19
19
|
}
|
20
20
|
|
21
|
-
public class
|
21
|
+
public class BModel : IModel{
|
22
22
|
private B b;
|
23
|
-
public
|
23
|
+
public BModel(B b){
|
24
24
|
this.b = b;
|
25
25
|
}
|
26
26
|
public string Method(){ return b.B_Method(); }
|
@@ -35,9 +35,9 @@
|
|
35
35
|
}
|
36
36
|
|
37
37
|
public class Hoge {
|
38
|
-
public void DoSomething(
|
38
|
+
public void DoSomething(IModel model){
|
39
39
|
// 共通処理...
|
40
|
-
Console.WriteLine($"Property is {
|
40
|
+
Console.WriteLine($"Property is {model.Property}, Method is {model.Method()}");
|
41
41
|
}
|
42
42
|
}
|
43
43
|
```
|