blob: 3414d1985346958bdb63a46b73ed9facce939e22 (
plain)
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
|
using System;
using System.Reflection;
//
// Test the setting for the default public constructor
//
abstract class Abstract {
}
//
// Test the setting for the default public consturctor
//
class Plain {
}
class Test {
static protected internal void MyProtectedInternal () { }
static internal void MyInternal() { }
static public void MyPublic () { }
static void MyPrivate () {}
static int Main ()
{
Type myself = typeof (Test);
BindingFlags bf = BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Public;
MethodAttributes mpia;
MethodInfo mpi;
//
// protected internal
//
mpi = myself.GetMethod ("MyProtectedInternal", bf);
mpia = mpi.Attributes & MethodAttributes.MemberAccessMask;
if (mpia != MethodAttributes.FamORAssem)
return 1;
//
// internal
//
mpi = myself.GetMethod ("MyInternal", bf);
mpia = mpi.Attributes & MethodAttributes.MemberAccessMask;
if (mpia != MethodAttributes.Assembly)
return 2;
//
// public
//
mpi = myself.GetMethod ("MyPublic", bf);
mpia = mpi.Attributes & MethodAttributes.MemberAccessMask;
if (mpia != MethodAttributes.Public)
return 3;
//
// private
//
mpi = myself.GetMethod ("MyPrivate", bf);
mpia = mpi.Attributes & MethodAttributes.MemberAccessMask;
if (mpia != MethodAttributes.Private)
return 4;
//
// Test 17.10.4 accessibility (default constructor permissions)
//
ConstructorInfo ci = typeof (Abstract).GetConstructor
(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance, null, new Type [0], new
ParameterModifier [0]);
if (!ci.IsFamily)
return 5;
ci = typeof (Plain).GetConstructor
(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance, null, new Type [0], new
ParameterModifier [0]);
if (!ci.IsPublic)
return 6;
Console.WriteLine ("All tests pass");
return 0;
}
}
|