This repository has been archived by the owner on Feb 2, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathPartialClassesTests.cs
99 lines (85 loc) · 2.41 KB
/
PartialClassesTests.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
// 참고:
// Partial Class Definitions (C# Programming Guide) - msdn
// http://msdn.microsoft.com/en-US/library/wa80x488
using Xunit;
namespace CSharpFeaturesTest.V20.PartialClasses
{
public class PartialClassesTests
{
partial class Numbers
{
public int ReturnOne()
{
return 1;
}
public partial class Nested
{
public static int ReturnThree()
{
return 3;
}
}
}
// 클래스 정의를 나눠서 할 수 있다.
// C#에서 generation하는 코드와 사용자 코드를 분리할 수 있어서 유용.
// (아마 이것때매 피처를 추가하지 않았을까 추측. 예. XAML code-behind)
partial class Numbers
{
public int ReturnTwo()
{
return 2;
}
public partial class Nested
{
public static int ReturnFour()
{
return 4;
}
}
}
[Fact]
public void PartialClassesTest()
{
Numbers n = new Numbers();
Assert.Equal(1, n.ReturnOne());
Assert.Equal(2, n.ReturnTwo());
Assert.Equal(3, Numbers.Nested.ReturnThree());
Assert.Equal(4, Numbers.Nested.ReturnFour());
}
interface INumbers1
{
int ReturnOne();
}
interface INumbers2
{
int ReturnTwo();
}
partial class NumbersImpl : INumbers1
{
int INumbers1.ReturnOne()
{
return 1;
}
}
partial class NumbersImpl : INumbers2
{
int INumbers2.ReturnTwo()
{
return 2;
}
}
[Fact]
public void PartialImplementationInterfaceTest()
{
NumbersImpl impl = new NumbersImpl();
// partial class NumbersImpl : INumbers1
// partial class NumbersImpl : INumbers2
// ==>
// class NumbersImpl : INumbers1, INumbers2
INumbers1 n1 = (INumbers1)impl;
Assert.Equal(1, n1.ReturnOne());
INumbers2 n2 = (INumbers2)impl;
Assert.Equal(2, n2.ReturnTwo());
}
}
}