4 using System.Collections;
5 using System.Collections.Generic;
7 using SiliconStudio.Core.Reflection;
9 namespace SiliconStudio.Quantum.Contents
14 : base(value, descriptor, isPrimitive, null)
18 public override object Value
20 get {
return base.Value; }
24 if (BoxedStructureOwner != null)
26 if (BoxedStructureOwnerIndices != null)
28 var currentObj = BoxedStructureOwner.Value;
29 for (
int i = 0; i < BoxedStructureOwnerIndices.Length - 1; ++i)
31 currentObj = FetchItem(currentObj, BoxedStructureOwnerIndices[i]);
33 SetItem(currentObj, BoxedStructureOwnerIndices[BoxedStructureOwnerIndices.Length - 1], value);
36 BoxedStructureOwner.Value = value;
41 internal IContent BoxedStructureOwner {
get; set; }
43 internal object[] BoxedStructureOwnerIndices {
get; set; }
45 private static object FetchItem(
object enumerable,
object index)
47 var list = enumerable as IList;
48 if (list != null && index is
int)
49 return list[(int)index];
52 if (dictionary != null)
53 return dictionary[index];
55 var type = enumerable.GetType();
58 var keyType = type.GetInterface(typeof(
IDictionary<,>)).GetGenericArguments()[0];
59 var valueType = type.GetInterface(typeof(
IDictionary<,>)).GetGenericArguments()[0];
60 var indexerMethod = type.GetProperty(
"Item", valueType,
new[] { keyType });
61 return indexerMethod.GetValue(enumerable,
new [] { index });
63 throw new ArgumentException(
@"Enumerable object has no indexing and is not supported.",
"enumerable");
66 private static void SetItem(
object enumerable,
object index,
object value)
68 var list = enumerable as IList;
69 if (list != null && index is
int)
71 list[(int)index] = value;
75 var dictionary = enumerable as IDictionary;
76 if (dictionary != null)
78 dictionary[index] = value;
82 var type = enumerable.GetType();
85 var keyType = type.GetInterface(typeof(
IDictionary<,>)).GetGenericArguments()[0];
86 var valueType = type.GetInterface(typeof(
IDictionary<,>)).GetGenericArguments()[0];
87 var indexerMethod = type.GetProperty(
"Item", valueType,
new[] { keyType });
88 indexerMethod.SetValue(enumerable, value,
new[] { index });
91 throw new ArgumentException(
@"Enumerable object has no indexing and is not supported.",
"enumerable");
An implementation of IContent that gives access to an object or a boxed struct.
Provides access members of a type.
BoxedContent(object value, ITypeDescriptor descriptor, bool isPrimitive)