Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
MemberContent.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 
5 using System.Reflection;
6 
7 using SiliconStudio.Core.Reflection;
8 using SiliconStudio.Quantum.References;
9 
10 namespace SiliconStudio.Quantum.Contents
11 {
12  /// <summary>
13  /// An implementation of <see cref="IContent"/> that gives access to a member of an object.
14  /// </summary>
15  public class MemberContent : ContentBase
16  {
17  protected IContent Container;
18 
19  public MemberContent(IContent container, IMemberDescriptor member, ITypeDescriptor descriptor, bool isPrimitive, IReference reference)
20  : base(member.Type, descriptor, isPrimitive, reference)
21  {
22  if (container == null) throw new ArgumentNullException("container");
23  Member = member;
24  Container = container;
25  }
26 
27  /// <summary>
28  /// The <see cref="IMemberDescriptor"/> used to access the member of the container represented by this content.
29  /// </summary>
30  public IMemberDescriptor Member { get; protected set; }
31 
32  /// <inheritdoc/>
33  public sealed override object Value
34  {
35  get
36  {
37  if (Container.Value == null) throw new InvalidOperationException("Container's value is null");
38  return Member.Get(Container.Value);
39  }
40  set
41  {
42  if (Container.Value == null) throw new InvalidOperationException("Container's value is null");
43  var containerValue = Container.Value;
44  Member.Set(containerValue, value);
45 
46  if (Container.Value.GetType().GetTypeInfo().IsValueType)
47  Container.Value = containerValue;
48  }
49  }
50  }
51 }
A base abstract implementation of the IContent interface.
Definition: ContentBase.cs:13
Content of a IModelNode.
Definition: IContent.cs:13
MemberContent(IContent container, IMemberDescriptor member, ITypeDescriptor descriptor, bool isPrimitive, IReference reference)
An implementation of IContent that gives access to a member of an object.
Provides access members of a type.