-
-
Notifications
You must be signed in to change notification settings - Fork 540
/
Property.cs
47 lines (38 loc) · 1.58 KB
/
Property.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
using System;
using System.Reflection;
using FluentAssertions.Common;
namespace FluentAssertions.Equivalency
{
/// <summary>
/// A specialized type of <see cref="INode "/> that represents a property of an object in a structural equivalency assertion.
/// </summary>
#pragma warning disable CA1716
public class Property : Node, IMember
{
private readonly PropertyInfo propertyInfo;
public Property(PropertyInfo propertyInfo, INode parent)
: this(propertyInfo.ReflectedType, propertyInfo, parent)
{
}
public Property(Type reflectedType, PropertyInfo propertyInfo, INode parent)
{
ReflectedType = reflectedType;
this.propertyInfo = propertyInfo;
DeclaringType = propertyInfo.DeclaringType;
Name = propertyInfo.Name;
Type = propertyInfo.PropertyType;
Path = parent.PathAndName;
GetSubjectId = parent.GetSubjectId;
RootIsCollection = parent.RootIsCollection;
}
public object GetValue(object obj)
{
return propertyInfo.GetValue(obj);
}
public Type DeclaringType { get; private set; }
public Type ReflectedType { get; }
public override string Description => $"property {GetSubjectId().Combine(PathAndName)}";
public CSharpAccessModifier GetterAccessibility => propertyInfo.GetGetMethod(nonPublic: true).GetCSharpAccessModifier();
public CSharpAccessModifier SetterAccessibility => propertyInfo.GetSetMethod(nonPublic: true).GetCSharpAccessModifier();
}
}