Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
FieldDescriptor.cs
Go to the documentation of this file.
1 // Copyright (c) 2014 Silicon Studio Corp. (http://siliconstudio.co.jp)
2 // This file is distributed under GPL v3. See LICENSE.md for details.
3 using System;
4 using System.Reflection;
5 
6 namespace SiliconStudio.Core.Reflection
7 {
8  /// <summary>
9  /// A <see cref="IMemberDescriptor"/> for a <see cref="FieldInfo"/>
10  /// </summary>
12  {
13  private readonly FieldInfo fieldInfo;
14 
15  /// <summary>
16  /// Initializes a new instance of the <see cref="FieldDescriptor"/> class.
17  /// </summary>
18  /// <param name="fieldInfo">The property information.</param>
19  public FieldDescriptor(ITypeDescriptorFactory factory, FieldInfo fieldInfo)
20  : base(factory, fieldInfo)
21  {
22  if (fieldInfo == null) throw new ArgumentNullException("fieldInfo");
23 
24  this.fieldInfo = fieldInfo;
25  this.TypeDescriptor = Factory.Find(fieldInfo.FieldType);
26  }
27 
28  /// <summary>
29  /// Gets the property information attached to this instance.
30  /// </summary>
31  /// <value>The property information.</value>
32  public FieldInfo FieldInfo
33  {
34  get
35  {
36  return fieldInfo;
37  }
38  }
39 
40  public override Type Type
41  {
42  get
43  {
44  return fieldInfo.FieldType;
45  }
46  }
47 
48  public override object Get(object thisObject)
49  {
50  return fieldInfo.GetValue(thisObject);
51  }
52 
53  public override void Set(object thisObject, object value)
54  {
55  fieldInfo.SetValue(thisObject, value);
56  }
57 
58  public override bool HasSet
59  {
60  get
61  {
62  return true;
63  }
64  }
65 
66  /// <summary>
67  /// Returns a <see cref="System.String" /> that represents this instance.
68  /// </summary>
69  /// <returns>A <see cref="System.String" /> that represents this instance.</returns>
70  public override string ToString()
71  {
72  return string.Format("Field [{0}] from Type [{1}]", Name, FieldInfo.DeclaringType != null ? FieldInfo.DeclaringType.FullName : string.Empty);
73  }
74  }
75 }
FieldDescriptor(ITypeDescriptorFactory factory, FieldInfo fieldInfo)
Initializes a new instance of the FieldDescriptor class.
A IMemberDescriptor for a FieldInfo
override string ToString()
Returns a System.String that represents this instance.
override object Get(object thisObject)
Gets the value of this member for the specified instance.
Base class for IMemberDescriptor for a MemberInfo
override void Set(object thisObject, object value)
Sets a value of this member for the specified instance.
A factory to create an instance of a ITypeDescriptor