blob: 952fa6924364305829ec35a87bd39c62bec9215f (
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
|
using Xunit;
using System;
using System.Linq;
using System.Reflection;
using System.Collections.Generic;
#pragma warning disable 0414
namespace System.Reflection.Tests
{
public class MemberInfoTests
{
[Fact]
public void MetadataToken()
{
Assert.True(Enumerable.SequenceEqual(GetMembers(typeof(SampleClass)), GetMembers(typeof(SampleClass))));
Assert.True(Enumerable.SequenceEqual(GetMembers(new MemberInfoTests().GetType()), GetMembers(new MemberInfoTests().GetType())));
Assert.True(Enumerable.SequenceEqual(GetMembers(new Dictionary<int, string>().GetType()), GetMembers(new Dictionary<int, int>().GetType())));
Assert.True(Enumerable.SequenceEqual(GetMembers(typeof(int)), GetMembers(typeof(int))));
Assert.True(Enumerable.SequenceEqual(GetMembers(typeof(Dictionary<,>)), GetMembers(typeof(Dictionary<,>))));
Assert.False(Enumerable.SequenceEqual(GetMembers(new Dictionary<int, string>().GetType()), GetMembers(new HashSet<int>().GetType())));
}
private IEnumerable<int> GetMembers(Type type)
{
return type.GetTypeInfo().GetMembers(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance).Select(m => m.MetadataToken);
}
#pragma warning disable 0067, 0169
public class SampleClass
{
public int PublicField;
private int PrivateField;
public SampleClass() { }
private SampleClass(int x) { }
public void PublicMethod() { }
private void PrivateMethod() { }
public int PublicProp { get; set; }
private int PrivateProp { get; set; }
public event EventHandler PublicEvent;
private event EventHandler PrivateEvent;
}
#pragma warning restore 0067, 0169
}
}
|