Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
DataVisitDictionaryItem.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.Collections;
5 using SiliconStudio.Core.Reflection;
6 
7 namespace SiliconStudio.Assets.Visitors
8 {
9  /// <summary>
10  /// Defines a dictionary item (key-value).
11  /// </summary>
12  public sealed class DataVisitDictionaryItem : DataVisitNode
13  {
14  private readonly object key;
15 
16  private readonly ITypeDescriptor keyDescriptor;
17 
18  /// <summary>
19  /// Initializes a new instance of the <see cref="DataVisitDictionaryItem"/> class.
20  /// </summary>
21  /// <param name="key">The key.</param>
22  /// <param name="keyDescriptor">The key descriptor.</param>
23  /// <param name="value">The value.</param>
24  /// <param name="valueDescriptor">The value descriptor.</param>
25  public DataVisitDictionaryItem(object key, ITypeDescriptor keyDescriptor, object value, ITypeDescriptor valueDescriptor) : base(value, valueDescriptor)
26  {
27  if (keyDescriptor == null) throw new ArgumentNullException("keyDescriptor");
28  this.key = key;
29  this.keyDescriptor = keyDescriptor;
30  }
31 
32  /// <summary>
33  /// Gets the dictionary.
34  /// </summary>
35  /// <value>The dictionary.</value>
36  public IDictionary Dictionary
37  {
38  get
39  {
40  return (IDictionary)(Parent != null ? Parent.Instance : null);
41  }
42  }
43 
44  /// <summary>
45  /// Gets the descriptor.
46  /// </summary>
47  /// <value>The descriptor.</value>
48  public DictionaryDescriptor Descriptor
49  {
50  get
51  {
52  return (DictionaryDescriptor)(Parent != null ? Parent.InstanceDescriptor : null);
53  }
54  }
55 
56  /// <summary>
57  /// Gets the key.
58  /// </summary>
59  /// <value>The key.</value>
60  public object Key
61  {
62  get
63  {
64  return key;
65  }
66  }
67 
68  /// <summary>
69  /// Gets the key descriptor.
70  /// </summary>
71  /// <value>The key descriptor.</value>
72  public ITypeDescriptor KeyDescriptor
73  {
74  get
75  {
76  return keyDescriptor;
77  }
78  }
79 
80  /// <summary>
81  /// Gets the value descriptor.
82  /// </summary>
83  /// <value>The value descriptor.</value>
84  public ITypeDescriptor ValueDescriptor
85  {
86  get
87  {
88  return InstanceDescriptor;
89  }
90  }
91 
92  public override string ToString()
93  {
94  return string.Format("{0} => {1}", key, Instance ?? "null");
95  }
96  }
97 }
Provides a descriptor for a System.Collections.IDictionary.
DataVisitDictionaryItem(object key, ITypeDescriptor keyDescriptor, object value, ITypeDescriptor valueDescriptor)
Initializes a new instance of the DataVisitDictionaryItem class.
Base class for all items in a collection (array, list or dictionary)
Provides access members of a type.