4 using System.Collections;
5 using System.Collections.Generic;
6 using SiliconStudio.Core.Reflection;
8 namespace SiliconStudio.Assets.Visitors
15 private readonly
object rootInstance;
17 private readonly Stack<DataVisitNode> stackItems =
new Stack<DataVisitNode>();
26 : base(typeDescriptorFactory)
28 if (rootInstance == null)
throw new ArgumentNullException(
"rootInstance");
29 this.rootInstance = rootInstance;
30 var objectDescriptor = typeDescriptorFactory.Find(rootInstance.GetType()) as
ObjectDescriptor;
31 if (objectDescriptor == null)
32 throw new ArgumentException(
"Expecting an object",
"rootInstance");
44 if (rootInstance == null)
return null;
45 return new DataVisitNodeBuilder(typeDescriptorFactory, rootInstance).Run();
60 if (!AcceptMember(member))
65 var node = stackItems.Peek();
67 AddMember(node, newNode);
69 stackItems.Push(newNode);
70 base.VisitObjectMember(container, containerDescriptor, member, value);
76 var node = stackItems.Peek();
79 AddItem(node, newNode);
81 stackItems.Push(newNode);
82 base.VisitCollectionItem(collection, descriptor, index, item, itemDescriptor);
88 var node = stackItems.Peek();
91 AddItem(node, newNode);
93 stackItems.Push(newNode);
94 base.VisitDictionaryKeyValue(dictionary, descriptor, key, keyDescriptor, value, valueDescriptor);
100 var node = stackItems.Peek();
102 AddItem(node, newNode);
104 stackItems.Push(newNode);
105 base.VisitArrayItem(array, descriptor, index, item, itemDescriptor);
117 if (member == null)
throw new ArgumentNullException(
"member");
118 if (thisObject.
Members == null)
119 thisObject.Members =
new List<DataVisitNode>();
121 member.Parent = thisObject;
122 thisObject.Members.Add(member);
133 if (item == null)
throw new ArgumentNullException(
"item");
134 if (thisObject.Items == null)
135 thisObject.Items =
new List<DataVisitNode>();
137 item.Parent = thisObject;
138 thisObject.Items.Add(item);
144 if ((typeof(AssetImport).IsAssignableFrom(member.
DeclaringType) && (member.
Name ==
"ImporterId" || member.
Name ==
"SourceHash"))
145 || typeof(Asset).IsAssignableFrom(member.
DeclaringType) && (member.
Name ==
"~Base" || member.
Name ==
"Id"))
Provides a descriptor for a System.Collections.ICollection.
override void VisitObjectMember(object container, ObjectDescriptor containerDescriptor, IMemberDescriptor member, object value)
Visits an object member.
string Name
Gets the name.
A diff element for a member (field or property) of a class.
Default implementation of a ITypeDescriptor.
A visitor for producing a DataVisitNode for an object hierarchy.
Type DeclaringType
Gets the type that is declaring this member.
override void VisitDictionaryKeyValue(object dictionary, DictionaryDescriptor descriptor, object key, ITypeDescriptor keyDescriptor, object value, ITypeDescriptor valueDescriptor)
Visits a dictionary key-value.
Describe a member of an object.
Defines an item in a list.
static DataVisitObject Run(ITypeDescriptorFactory typeDescriptorFactory, object rootInstance)
Creates DataVisitNode from the specified instance.
DataVisitObject Run()
Runs this instance.
The root node used for storing a hierarchy of DataVisitNode
Provides a descriptor for a System.Collections.IDictionary.
List< DataVisitNode > Members
override void VisitCollectionItem(IEnumerable collection, CollectionDescriptor descriptor, int index, object item, ITypeDescriptor itemDescriptor)
Visits a collection item.
Base class for all items in a collection (array, list or dictionary)
Provides access members of a type.
Defines a dictionary item (key-value).
override void VisitArrayItem(Array array, ArrayDescriptor descriptor, int index, object item, ITypeDescriptor itemDescriptor)
Visits an array item.
A descriptor for an array.
A factory to create an instance of a ITypeDescriptor
Defines an item in an array.