-
-
Notifications
You must be signed in to change notification settings - Fork 540
/
Field.cs
46 lines (37 loc) · 1.42 KB
/
Field.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
using System;
using System.Reflection;
using FluentAssertions.Common;
namespace FluentAssertions.Equivalency
{
/// <summary>
/// A specialized type of <see cref="INode "/> that represents a field of an object in a structural equivalency assertion.
/// </summary>
public class Field : Node, IMember
{
private readonly FieldInfo fieldInfo;
public Field(FieldInfo fieldInfo, INode parent)
: this(fieldInfo.ReflectedType, fieldInfo, parent)
{
}
public Field(Type reflectedType, FieldInfo fieldInfo, INode parent)
{
this.fieldInfo = fieldInfo;
DeclaringType = fieldInfo.DeclaringType;
ReflectedType = reflectedType;
Path = parent.PathAndName;
GetSubjectId = parent.GetSubjectId;
Name = fieldInfo.Name;
Type = fieldInfo.FieldType;
RootIsCollection = parent.RootIsCollection;
}
public Type ReflectedType { get; }
public object GetValue(object obj)
{
return fieldInfo.GetValue(obj);
}
public Type DeclaringType { get; set; }
public override string Description => $"field {GetSubjectId().Combine(PathAndName)}";
public CSharpAccessModifier GetterAccessibility => fieldInfo.GetCSharpAccessModifier();
public CSharpAccessModifier SetterAccessibility => fieldInfo.GetCSharpAccessModifier();
}
}