示例#1
0
 /// <summary>
 /// Pushes an array access on the path.
 /// </summary>
 /// <param name="descriptor">The descriptor of the array.</param>
 /// <param name="index">The index in the array.</param>
 /// <exception cref="System.ArgumentNullException">descriptor</exception>
 public void Push(ArrayDescriptor descriptor, int index)
 {
     if (descriptor == null)
     {
         throw new ArgumentNullException(nameof(descriptor));
     }
     AddItem(new ArrayPathItem(descriptor, index));
 }
示例#2
0
 public ArrayPathItem(ArrayDescriptor descriptor, int index)
 {
     if (descriptor == null)
     {
         throw new ArgumentNullException(nameof(descriptor));
     }
     Index      = index;
     Descriptor = descriptor;
 }
示例#3
0
 /// <inheritdoc />
 public virtual void VisitArray(Array array, ArrayDescriptor descriptor)
 {
     for (var i = 0; i < array.Length; i++)
     {
         var value = array.GetValue(i);
         CurrentPath.Push(descriptor, i);
         VisitArrayItem(array, descriptor, i, value, TypeDescriptorFactory.Find(value?.GetType() ?? descriptor.ElementType));
         CurrentPath.Pop();
     }
 }
示例#4
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)
        {
            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 (ListDescriptor.IsList(type))
            {
                // IList
                descriptor = new ListDescriptor(this, type, emitDefaultValues, namingConvention);
            }
            else if (SetDescriptor.IsSet(type))
            {
                // ISet
                descriptor = new SetDescriptor(this, type, emitDefaultValues, namingConvention);
            }
            else if (OldCollectionDescriptor.IsCollection(type))
            {
                // ICollection
                descriptor = new OldCollectionDescriptor(this, type, emitDefaultValues, namingConvention);
            }
            else if (type.IsArray)
            {
                if (type.GetArrayRank() == 1 && !type.GetElementType().IsArray)
                {
                    // array[] - only single dimension array is supported
                    descriptor = new ArrayDescriptor(this, type, emitDefaultValues, namingConvention);
                }
                else
                {
                    // multi-dimension array to be treated as a 'standard' object
                    descriptor = new NotSupportedObjectDescriptor(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);
        }
示例#5
0
 /// <inheritdoc />
 public virtual void VisitArrayItem(Array array, ArrayDescriptor descriptor, int index, object item, ITypeDescriptor itemDescriptor)
 {
     Visit(item, itemDescriptor);
 }