forked from stride3d/stride
-
Notifications
You must be signed in to change notification settings - Fork 0
/
FieldDescriptor.cs
59 lines (49 loc) · 2.1 KB
/
FieldDescriptor.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
// Copyright (c) .NET Foundation and Contributors (https://dotnetfoundation.org/ & https://stride3d.net) and Silicon Studio Corp. (https://www.siliconstudio.co.jp)
// Distributed under the MIT license. See the LICENSE.md file in the project root for more information.
using System;
using System.Collections.Generic;
using System.Reflection;
namespace Stride.Core.Reflection
{
/// <summary>
/// A <see cref="IMemberDescriptor"/> for a <see cref="FieldInfo"/>
/// </summary>
public class FieldDescriptor : MemberDescriptorBase
{
public FieldDescriptor(ITypeDescriptor typeDescriptor, FieldInfo fieldInfo, StringComparer defaultNameComparer)
: base(fieldInfo, defaultNameComparer)
{
if (fieldInfo == null) throw new ArgumentNullException(nameof(fieldInfo));
FieldInfo = fieldInfo;
TypeDescriptor = typeDescriptor;
}
/// <summary>
/// Gets the property information attached to this instance.
/// </summary>
/// <value>The property information.</value>
public FieldInfo FieldInfo { get; }
public override Type Type => FieldInfo.FieldType;
public override bool IsPublic => FieldInfo.IsPublic;
public override bool HasSet => !FieldInfo.IsInitOnly;
public override object Get(object thisObject)
{
return FieldInfo.GetValue(thisObject);
}
public override void Set(object thisObject, object value)
{
FieldInfo.SetValue(thisObject, value);
}
public override IEnumerable<T> GetCustomAttributes<T>(bool inherit)
{
return FieldInfo.GetCustomAttributes<T>(inherit);
}
/// <summary>
/// Returns a <see cref="System.String" /> that represents this instance.
/// </summary>
/// <returns>A <see cref="System.String" /> that represents this instance.</returns>
public override string ToString()
{
return $"Field [{Name}] from Type [{(FieldInfo.DeclaringType != null ? FieldInfo.DeclaringType.FullName : string.Empty)}]";
}
}
}