-
Notifications
You must be signed in to change notification settings - Fork 29
/
Field_modifiers.cs
129 lines (119 loc) · 3.75 KB
/
Field_modifiers.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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
using PublicApiGeneratorTests.Examples;
using Xunit;
namespace PublicApiGeneratorTests
{
public class Field_modifiers : ApiGeneratorTestsBase
{
[Fact]
public void Include_static_fields()
{
AssertPublicApi<ClassWithStaticFields>(
@"namespace PublicApiGeneratorTests.Examples
{
public class ClassWithStaticFields
{
protected static string StaticProtectedField;
public static int StaticPublicField;
public ClassWithStaticFields() { }
}
}");
}
[Fact]
public void Include_Volatile_field_Without_modreq()
{
AssertPublicApi<ClassWithVolatileField>(
@"namespace PublicApiGeneratorTests.Examples
{
public class ClassWithVolatileField
{
public static int StaticVolatilePublicField;
public ClassWithVolatileField() { }
}
}");
}
[Fact]
public void Include_readonly_fields_without_constant_values()
{
// TODO: Initializing values are set in the constructor. Very tricky to get
AssertPublicApi<ClassWithReadonlyFields>(
@"namespace PublicApiGeneratorTests.Examples
{
public class ClassWithReadonlyFields
{
protected readonly string ReadonlyProtectedField;
public readonly int ReadonlyPublicField;
public ClassWithReadonlyFields() { }
}
}");
}
[Fact]
public void Include_const_fields()
{
// Have to include the ctor - I can't figure out how to hide it
// when values are initialized
AssertPublicApi<ClassWithConstFields>(
@"namespace PublicApiGeneratorTests.Examples
{
public class ClassWithConstFields
{
protected const string ConstProtectedField = ""hello world"";
public const int ConstPublicField = 42;
public ClassWithConstFields() { }
}
}");
}
[Fact]
public void Include_unsafe_fields()
{
// Have to include the ctor - I can't figure out how to hide it
// when values are initialized
AssertPublicApi<ClassWithUnsafeFields>(
@"namespace PublicApiGeneratorTests.Examples
{
public class ClassWithUnsafeFields
{
protected unsafe void* UnsafeProtectedField;
public unsafe byte* UnsafePublicByteField;
public unsafe void* UnsafePublicField;
public unsafe int* UnsafePublicIntField;
public unsafe long* UnsafePublicLongField;
public ClassWithUnsafeFields() { }
}
}");
}
}
// ReSharper disable ClassNeverInstantiated.Global
// ReSharper disable UnusedMember.Global
namespace Examples
{
public class ClassWithStaticFields
{
public static int StaticPublicField;
protected static string StaticProtectedField;
}
public class ClassWithVolatileField
{
public static volatile int StaticVolatilePublicField;
}
public class ClassWithReadonlyFields
{
public readonly int ReadonlyPublicField = 42;
protected readonly string ReadonlyProtectedField = "hello world";
}
public class ClassWithConstFields
{
public const int ConstPublicField = 42;
protected const string ConstProtectedField = "hello world";
}
public class ClassWithUnsafeFields
{
public unsafe void* UnsafePublicField;
public unsafe byte* UnsafePublicByteField;
public unsafe int* UnsafePublicIntField;
public unsafe long* UnsafePublicLongField;
protected unsafe void* UnsafeProtectedField;
}
}
// ReSharper restore UnusedMember.Global
// ReSharper restore ClassNeverInstantiated.Global
}