/// <inheritdoc/> public override void VisitCollectionItem(IEnumerable collection, CollectionDescriptor descriptor, int index, object item, ITypeDescriptor itemDescriptor) { if (CurrentPath.Match(MemberPath)) VisitAssetMember(item, itemDescriptor); else base.VisitCollectionItem(collection, descriptor, index, item, itemDescriptor); }
/// <summary> /// Pushes an collection access on the path. /// </summary> /// <param name="descriptor">The descriptor of the collection.</param> /// <param name="index">The index in the collection.</param> /// <exception cref="System.ArgumentNullException">descriptor</exception> public void Push(CollectionDescriptor descriptor, int index) { if (descriptor == null) { throw new ArgumentNullException("descriptor"); } AddItem(new CollectionPathItem(descriptor, index)); }
public CollectionPathItem(CollectionDescriptor descriptor, int index) { if (descriptor == null) { throw new ArgumentNullException(nameof(descriptor)); } Descriptor = descriptor; Index = index; }
public virtual void VisitCollection(IEnumerable collection, CollectionDescriptor descriptor) { int i = 0; foreach (var item in collection) { CurrentPath.Push(descriptor, i); VisitCollectionItem(collection, descriptor, i, item, item == null ? null : TypeDescriptorFactory.Find(item.GetType())); CurrentPath.Pop(); i++; } }
public override void VisitCollection(IEnumerable collection, CollectionDescriptor descriptor) { CollectionItemIdentifiers itemIds; if (inNonIdentifiableType == 0 && !CollectionItemIdHelper.TryGetCollectionItemIds(collection, out itemIds)) { itemIds = CollectionItemIdHelper.GetCollectionItemIds(collection); var count = descriptor.GetCollectionCount(collection); for (var i = 0; i < count; ++i) { itemIds.Add(i, ItemId.New()); } } base.VisitCollection(collection, descriptor); }
/// <inheritdoc /> public virtual void VisitCollection(IEnumerable collection, CollectionDescriptor descriptor) { var i = 0; // Make a copy in case VisitCollectionItem mutates something var items = collection.Cast <object>().ToList(); foreach (var item in items) { CurrentPath.Push(descriptor, i); VisitCollectionItem(collection, descriptor, i, item, TypeDescriptorFactory.Find(item?.GetType() ?? descriptor.ElementType)); CurrentPath.Pop(); i++; } }
/// <summary> /// Initialize the tests. /// </summary> public virtual void Initialize() { TypeFactory = new TypeDescriptorFactory(); var myClassDesc = TypeFactory.Find(typeof(MyClass)); var myStructDesc = TypeFactory.Find(typeof(MyStruct)); ListClassDesc = (CollectionDescriptor)TypeFactory.Find(typeof(List<MyClass>)); MapClassDesc = (DictionaryDescriptor)TypeFactory.Find(typeof(Dictionary<string, MyClass>)); MemberValue = myClassDesc.Members.FirstOrDefault(member => member.Name == "Value"); MemberSub = myClassDesc.Members.FirstOrDefault(member => member.Name == "Sub"); MemberStruct = myClassDesc.Members.FirstOrDefault(member => member.Name == "Struct"); MemberSubs = myClassDesc.Members.FirstOrDefault(member => member.Name == "Subs"); MemberMaps = myClassDesc.Members.FirstOrDefault(member => member.Name == "Maps"); MemberX = myStructDesc.Members.FirstOrDefault(member => member.Name == "X"); MemberClass = myStructDesc.Members.FirstOrDefault(member => member.Name == "Class"); }
protected override void ReadAddCollectionItem(ref ObjectContext objectContext, Type elementType, CollectionDescriptor collectionDescriptor, object thisObject, int index) { var scriptCollection = (EntityComponentCollection)objectContext.Instance; EntityComponent value = null; bool needAdd = true; // If we could get existing value, no need add to collection if (index < scriptCollection.Count) { value = scriptCollection[index]; needAdd = false; } value = (EntityComponent)ReadCollectionItem(ref objectContext, value, elementType, index); if (needAdd) { scriptCollection.Add(value); } }
public static bool IsIdentifiable(Type type) { bool result; lock (IdentifiableTypes) { if (!IdentifiableTypes.TryGetValue(type, out result)) { var attributes = TypeDescriptorFactory.Default.AttributeRegistry.GetAttributes(type); // Early exit if we don't need to add a unique identifier to a type result = !(type == typeof(string) || type.IsValueType || type.IsArray || CollectionDescriptor.IsCollection(type) || DictionaryDescriptor.IsDictionary(type) || attributes.OfType <NonIdentifiableAttribute>().Any()); IdentifiableTypes.Add(type, result); } } return(result); }
/// <summary> /// Creates a type descriptor for the specified type. /// </summary> /// <param name="type">The type.</param> /// <returns>An instance of type descriptor.</returns> protected virtual ITypeDescriptor Create(Type type) { ITypeDescriptor descriptor; // The order of the descriptors here is important if (PrimitiveDescriptor.IsPrimitive(type)) { descriptor = new PrimitiveDescriptor(this, type, emitDefaultValues, namingConvention); } else if (DictionaryDescriptor.IsDictionary(type)) // resolve dictionary before collections, as they are also collections { // IDictionary descriptor = new DictionaryDescriptor(this, type, emitDefaultValues, namingConvention); } else if (CollectionDescriptor.IsCollection(type)) { // ICollection descriptor = new CollectionDescriptor(this, type, emitDefaultValues, namingConvention); } else if (type.IsArray) { // array[] descriptor = new ArrayDescriptor(this, type, emitDefaultValues, namingConvention); } else if (NullableDescriptor.IsNullable(type)) { descriptor = new NullableDescriptor(this, type, emitDefaultValues, namingConvention); } else { // standard object (class or value type) descriptor = new ObjectDescriptor(this, type, emitDefaultValues, namingConvention); } return(descriptor); }
public override void VisitCollection(IEnumerable collection, CollectionDescriptor descriptor) { Fixup(collection); base.VisitCollection(collection, descriptor); }
public override void VisitCollectionItem(IEnumerable collection, CollectionDescriptor descriptor, int index, object item, ITypeDescriptor itemDescriptor) { var node = stackItems.Peek(); // TODO modify DataVisitorBase to allow only IList? var newNode = new DataVisitListItem(index, item, itemDescriptor); AddItem(node, newNode); stackItems.Push(newNode); base.VisitCollectionItem(collection, descriptor, index, item, itemDescriptor); stackItems.Pop(); }
public override void VisitCollectionItem(IEnumerable collection, CollectionDescriptor descriptor, int index, object item, ITypeDescriptor itemDescriptor) { base.VisitCollectionItem(collection, descriptor, index, item, itemDescriptor); var assetReference = item as AssetReference; var assetBase = item as AssetBase; var attachedReference = item != null ? AttachedReferenceManager.GetAttachedReference(item) : null; // TODO force support for IList in CollectionDescriptor if (assetReference != null) { var list = (IList)collection; AddLink(assetReference, (guid, location) => list[index] = AssetReference.New(descriptor.ElementType, guid.HasValue ? guid.Value : assetReference.Id, location)); } else if (assetBase != null) { var list = (IList)collection; AddLink(assetBase, (guid, location) => list[index] = new AssetBase(location, assetBase.Asset)); } else if (attachedReference != null) { var list = (IList)collection; AddLink(attachedReference, (guid, location) => list[index] = guid.HasValue && guid.Value != Guid.Empty ? AttachedReferenceManager.CreateSerializableVersion(descriptor.ElementType, guid.Value, location) : null); } else if (item is UFile) { var list = (IList)collection; AddLink(item, (guid, location) => list[index] = new UFile(location)); } else if (item is UDirectory) { var list = (IList)collection; AddLink(item, (guid, location) => list[index] = new UDirectory(location)); } }
public virtual void VisitCollectionItem(IEnumerable collection, CollectionDescriptor descriptor, int index, object item, ITypeDescriptor itemDescriptor) { Visit(item, itemDescriptor); }
public virtual void VisitCollection(IEnumerable collection, CollectionDescriptor descriptor) { var i = 0; // Make a copy in case VisitCollectionItem mutates something var items = collection.Cast<object>().ToList(); foreach (var item in items) { CurrentPath.Push(descriptor, i); VisitCollectionItem(collection, descriptor, i, item, TypeDescriptorFactory.Find(item?.GetType() ?? descriptor.ElementType)); CurrentPath.Pop(); i++; } }
public CollectionPathItem(CollectionDescriptor descriptor, int index) { this.Descriptor = descriptor; this.Index = index; }
/// <summary> /// Creates a type descriptor for the specified type. /// </summary> /// <param name="type">The type.</param> /// <returns>An instance of type descriptor.</returns> protected virtual ITypeDescriptor Create(Type type) { ITypeDescriptor descriptor; // The order of the descriptors here is important if (PrimitiveDescriptor.IsPrimitive(type)) { descriptor = new PrimitiveDescriptor(this, type, emitDefaultValues, namingConvention); } else if (DictionaryDescriptor.IsDictionary(type)) // resolve dictionary before collections, as they are also collections { // IDictionary descriptor = new DictionaryDescriptor(this, type, emitDefaultValues, namingConvention); } else if (CollectionDescriptor.IsCollection(type)) { // ICollection descriptor = new CollectionDescriptor(this, type, emitDefaultValues, namingConvention); } else if (type.IsArray) { // array[] descriptor = new ArrayDescriptor(this, type, emitDefaultValues, namingConvention); } else if (NullableDescriptor.IsNullable(type)) { descriptor = new NullableDescriptor(this, type, emitDefaultValues, namingConvention); } else { // standard object (class or value type) descriptor = new ObjectDescriptor(this, type, emitDefaultValues, namingConvention); } return descriptor; }
public CollectionPathItem(CollectionDescriptor descriptor, int index) { Descriptor = descriptor; Index = index; }
public override void VisitCollectionItem(IEnumerable collection, CollectionDescriptor descriptor, int index, object item, ITypeDescriptor itemDescriptor) { if (ProcessObject(item, descriptor.ElementType)) return; base.VisitCollectionItem(collection, descriptor, index, item, itemDescriptor); }
public virtual void VisitCollection(IEnumerable collection, CollectionDescriptor descriptor) { int i = 0; foreach (var item in collection) { CurrentPath.Push(descriptor, i); VisitCollectionItem(collection, descriptor, i, item, TypeDescriptorFactory.Find(item?.GetType() ?? descriptor.ElementType)); CurrentPath.Pop(); i++; } }
/// <inheritdoc/> public override void VisitCollection(IEnumerable collection, CollectionDescriptor descriptor) { if (!descriptor.HasIndexerAccessors) throw new NotSupportedException("Collections that do not have indexer accessors are not supported in Quantum."); // Don't visit items unless they are primitive or enumerable (collections within collections) if (IsPrimitiveType(descriptor.ElementType, false) || IsCollection(descriptor.ElementType)) { base.VisitCollection(collection, descriptor); } }
/// <inheritdoc/> public override void VisitCollection(IEnumerable collection, CollectionDescriptor descriptor) { var containerNode = GetContextNode(); var count = descriptor.GetCollectionCount(collection); var referenceInfo = GetReferenceInfo(descriptor.Type, collection); if (referenceInfo != null && referenceInfo.EnumerableCount != count) throw new QuantumConsistencyException("A node with an EnumerableReference containing [{0}] items", referenceInfo.EnumerableCount.ToStringSafe(), "A node with an EnumerableReference containing [{0}] items", count.ToStringSafe(), containerNode); if (IsPrimitiveType(descriptor.ElementType, false) || IsEnumerable(descriptor.ElementType)) { base.VisitCollection(collection, descriptor); } }
/// <summary> /// Reads and adds item to the collection. /// </summary> /// <param name="objectContext">The object context.</param> /// <param name="elementType">Type of the element.</param> /// <param name="collectionDescriptor">The collection descriptor.</param> /// <param name="thisObject">The this object.</param> /// <param name="index">The index.</param> protected virtual void ReadAddCollectionItem(ref ObjectContext objectContext, Type elementType, CollectionDescriptor collectionDescriptor, object thisObject, int index) { var value = ReadCollectionItem(ref objectContext, null, elementType, index); collectionDescriptor.Add(thisObject, value); }