protected override void ReadAddCollectionItem(ref ObjectContext objectContext, Type elementType, CollectionDescriptor collectionDescriptor, object thisObject, int index)
        {
            var scriptCollection = (ScriptCollection)objectContext.Instance;

            object value = null;
            bool needAdd = true; // If we could get existing value, no need add to collection
            if (scriptCollection.Count > index)
            {
                value = scriptCollection[index];
                needAdd = false;
            }

            value = ReadCollectionItem(ref objectContext, value, elementType);
            if (needAdd)
                collectionDescriptor.CollectionAdd(thisObject, value);
        }
        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);
            }
        }
示例#3
0
        /// <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)
        {
            ObjectDescriptor descriptor;

            // The order of the descriptors here is important

            if (PrimitiveDescriptor.IsPrimitive(type))
            {
                descriptor = new PrimitiveDescriptor(attributeRegistry, type, namingConvention);
            }
            else if (DictionaryDescriptor.IsDictionary(type)) // resolve dictionary before collections, as they are also collections
            {
                // IDictionary
                descriptor = new DictionaryDescriptor(attributeRegistry, type, emitDefaultValues, respectPrivateSetters, namingConvention);
            }
            else if (CollectionDescriptor.IsCollection(type))
            {
                // ICollection
                descriptor = new CollectionDescriptor(attributeRegistry, type, emitDefaultValues, respectPrivateSetters, namingConvention);
            }
            else if (type.IsArray)
            {
                // array[]
                descriptor = new ArrayDescriptor(attributeRegistry, type, namingConvention);
            }
            else if (NullableDescriptor.IsNullable(type))
            {
                descriptor = new NullableDescriptor(attributeRegistry, type, namingConvention);
            }
            else
            {
                // standard object (class or value type)
                descriptor = new ObjectDescriptor(attributeRegistry, type, emitDefaultValues, respectPrivateSetters, namingConvention);
            }

            // Initialize the descriptor
            descriptor.Initialize();
            return(descriptor);
        }
        /// <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(attributeRegistry, type);
            }
            else if (DictionaryDescriptor.IsDictionary(type)) // resolve dictionary before collections, as they are also collections
            {
                // IDictionary
                descriptor = new DictionaryDescriptor(attributeRegistry, type, emitDefaultValues);
            }
            else if (CollectionDescriptor.IsCollection(type))
            {
                // ICollection
                descriptor = new CollectionDescriptor(attributeRegistry, type, emitDefaultValues);
            }
            else if (type.IsArray)
            {
                // array[]
                descriptor = new ArrayDescriptor(attributeRegistry, type);
            }
            else if (NullableDescriptor.IsNullable(type))
            {
                descriptor = new NullableDescriptor(attributeRegistry, type);
            }
            else
            {
                // standard object (class or value type)
                descriptor = new ObjectDescriptor(attributeRegistry, type, emitDefaultValues);
            }
            return 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);
     collectionDescriptor.CollectionAdd(thisObject, value);
 }